FA-90131 / Bytecode virtual machines / Open access
Structured control: branch does not unwind to the label height · case 01
Intermediate operands pushed inside a block survive a branch out of it.
ROOT CAUSE
Only the carried values are removed, not everything above the label height.
VERIFIED REPAIR
Truncate the operand stack to the height recorded when the label was entered.
Unsuccessful approach: Deleting below the height removes the enclosing code's operands instead of the block's.
Case contract
WebAssembly-style structured control over a value stack. block k / loop / end nest; each block or loop pushes a label recording its operand height and arity (block: k result values, loop: 0). br d targets the d-th enclosing label counting outward from 0; the branch keeps the top arity values, discards operands down to the label height, then for a block pops that label and continues after its end, for a loop keeps the loop label and continues at the first instruction inside the loop. br_if pops a condition and branches when it is non-zero. Other ops: const v, add, sub, eqz, get k, set k, drop. Each instruction costs one fuel. Return status (done/fuel/trap), stack and locals.
Why this case matters
Label-depth branching is the core of structured bytecode interpreters.
1 / The failure
Exit 1"""Failure Map reference implementation. Python standard library only."""
import json
N = 1
observations = []
def solve(code, locals_, fuel):
match = {}
opens = []
for i, ins in enumerate(code):
if ins[0] in ('block', 'loop'):
opens.append(i)
elif ins[0] == 'end':
match[opens.pop()] = i
loc = list(locals_)
stack = []
labels = []
pc = 0
steps = 0
try:
while pc < len(code):
if steps == fuel:
return {'status': 'fuel', 'stack': stack, 'locals': loc}
steps += 1
ins = code[pc]
op = ins[0]
if op in ('block', 'loop'):
labels.append({'kind': op, 'pc': pc, 'end': match[pc], 'height': len(stack),
'arity': ins[1] if op == 'block' else 0})
pc += 1
elif op == 'end':
labels.pop()
pc += 1
elif op in ('br', 'br_if'):
if op == 'br_if' and stack.pop() == 0:
pc += 1
continue
target = labels[len(labels) - 1 - ins[1]]
keep = stack[len(stack) - target['arity']:] if target['arity'] else []
del stack[len(stack) - target['arity']:]
stack.extend(keep)
if target['kind'] == 'loop':
del labels[len(labels) - ins[1]:]
pc = target['pc'] + 1
else:
del labels[len(labels) - 1 - ins[1]:]
pc = target['end'] + 1
elif op == 'const':
stack.append(ins[1])
pc += 1
elif op in ('add', 'sub'):
b = stack.pop()
a = stack.pop()
stack.append(a + b if op == 'add' else a - b)
pc += 1
elif op == 'eqz':
stack.append(1 if stack.pop() == 0 else 0)
pc += 1
elif op == 'get':
stack.append(loc[ins[1]])
pc += 1
elif op == 'set':
loc[ins[1]] = stack.pop()
pc += 1
else:
stack.pop()
pc += 1
except IndexError:
return {'status': 'trap', 'stack': stack, 'locals': loc}
return {'status': 'done', 'stack': stack, 'locals': loc}
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression: counted loop exits through outer block',
([['block', 0],
['loop', 0],
['get', 0],
['eqz'],
['br_if', 1],
['get', 1],
['get', 0],
['add'],
['set', 1],
['get', 0],
['const', 1],
['sub'],
['set', 0],
['br', 0],
['end'],
['end']],
[2, 0],
500),
{'locals': [0, 3], 'stack': [], 'status': 'done'}),
('continue from inside a nested block',
([['block', 0],
['loop', 0],
['get', 0],
['eqz'],
['br_if', 1],
['block', 0],
['get', 0],
['const', 1],
['sub'],
['set', 0],
['get', 1],
['const', 2],
['add'],
['set', 1],
['br', 1],
['end'],
['const', 999],
['set', 1],
['end'],
['end']],
[2, 0],
500),
{'locals': [0, 4], 'stack': [], 'status': 'done'}),
('continue loop with more iterations',
([['block', 0],
['loop', 0],
['get', 0],
['eqz'],
['br_if', 1],
['block', 0],
['get', 0],
['const', 1],
['sub'],
['set', 0],
['get', 1],
['const', 2],
['add'],
['set', 1],
['br', 1],
['end'],
['const', 999],
['set', 1],
['end'],
['end']],
[4, 0],
900),
{'locals': [0, 8], 'stack': [], 'status': 'done'}),
('block result keeps one value above outer operand',
([['const', 41], ['block', 1], ['const', 5], ['const', 7], ['br', 0], ['const', 99], ['end']], [], 50),
{'locals': [], 'stack': [41, 7], 'status': 'done'}),
('void block branch discards operands',
([['block', 0], ['const', 1], ['const', 1], ['br', 0], ['end'], ['const', 3]], [], 50),
{'locals': [], 'stack': [3], 'status': 'done'}),
('untaken br_if consumes its condition',
([['const', 10], ['block', 0], ['const', 0], ['br_if', 0], ['const', 3], ['add'], ['end']], [], 50),
{'locals': [], 'stack': [13], 'status': 'done'}),
('taken br_if exits the block',
([['const', 10], ['block', 0], ['const', 1], ['br_if', 0], ['const', 3], ['add'], ['end']], [], 50),
{'locals': [], 'stack': [10], 'status': 'done'}),
('control: fuel exhaustion',
([['block', 0],
['loop', 0],
['get', 0],
['eqz'],
['br_if', 1],
['get', 1],
['get', 0],
['add'],
['set', 1],
['get', 0],
['const', 1],
['sub'],
['set', 0],
['br', 0],
['end'],
['end']],
[50, 0],
21),
{'locals': [49, 99], 'stack': [], 'status': 'fuel'})],
[('regression: counted loop exits through outer block',
([['block', 0],
['loop', 0],
['get', 0],
['eqz'],
['br_if', 1],
['get', 1],
['get', 0],
['add'],
['set', 1],
['get', 0],
['const', 1],
['sub'],
['set', 0],
['br', 0],
['end'],
['end']],
[3, 0],
500),
{'locals': [0, 6], 'stack': [], 'status': 'done'}),
('continue from inside a nested block',
([['block', 0],
['loop', 0],
['get', 0],
['eqz'],
['br_if', 1],
['block', 0],
['get', 0],
['const', 1],
['sub'],
['set', 0],
['get', 1],
['const', 2],
['add'],
['set', 1],
['br', 1],
['end'],
['const', 999],
['set', 1],
['end'],
['end']],
[3, 0],
500),
{'locals': [0, 6], 'stack': [], 'status': 'done'}),
('continue loop with more iterations',
([['block', 0],
['loop', 0],
['get', 0],
['eqz'],
['br_if', 1],
['block', 0],
['get', 0],
['const', 1],
['sub'],
['set', 0],
['get', 1],
['const', 2],
['add'],
['set', 1],
['br', 1],
['end'],
['const', 999],
['set', 1],
['end'],
['end']],
[5, 0],
900),
{'locals': [0, 10], 'stack': [], 'status': 'done'}),
('block result keeps one value above outer operand',
([['const', 42], ['block', 1], ['const', 5], ['const', 7], ['br', 0], ['const', 99], ['end']], [], 50),
{'locals': [], 'stack': [42, 7], 'status': 'done'}),
('void block branch discards operands',
([['block', 0], ['const', 1], ['const', 2], ['br', 0], ['end'], ['const', 3]], [], 50),
{'locals': [], 'stack': [3], 'status': 'done'}),
('untaken br_if consumes its condition',
([['const', 20], ['block', 0], ['const', 0], ['br_if', 0], ['const', 3], ['add'], ['end']], [], 50),
{'locals': [], 'stack': [23], 'status': 'done'}),
('taken br_if exits the block',
([['const', 10], ['block', 0], ['const', 2], ['br_if', 0], ['const', 3], ['add'], ['end']], [], 50),
{'locals': [], 'stack': [10], 'status': 'done'}),
('control: fuel exhaustion',
([['block', 0],
['loop', 0],
['get', 0],
['eqz'],
['br_if', 1],
['get', 1],
['get', 0],
['add'],
['set', 1],
['get', 0],
['const', 1],
['sub'],
['set', 0],
['br', 0],
['end'],
['end']],
[50, 0],
22),
{'locals': [49, 99], 'stack': [49], 'status': 'fuel'})],
[('regression: counted loop exits through outer block',
([['block', 0],
['loop', 0],
['get', 0],
['eqz'],
['br_if', 1],
['get', 1],
['get', 0],
['add'],
['set', 1],
['get', 0],
['const', 1],
['sub'],
['set', 0],
['br', 0],
['end'],
['end']],
[4, 0],
500),
{'locals': [0, 10], 'stack': [], 'status': 'done'}),
('continue from inside a nested block',
([['block', 0],
['loop', 0],
['get', 0],
['eqz'],
['br_if', 1],
['block', 0],
['get', 0],
['const', 1],
['sub'],
['set', 0],
['get', 1],
['const', 2],
['add'],
['set', 1],
['br', 1],
['end'],
['const', 999],
['set', 1],
['end'],
['end']],
[4, 0],
500),
{'locals': [0, 8], 'stack': [], 'status': 'done'}),
('continue loop with more iterations',
([['block', 0],
['loop', 0],
['get', 0],
['eqz'],
['br_if', 1],
['block', 0],
['get', 0],
['const', 1],
['sub'],
['set', 0],
['get', 1],
['const', 2],
['add'],
['set', 1],
['br', 1],
['end'],
['const', 999],
['set', 1],
['end'],
['end']],
[6, 0],
900),
{'locals': [0, 12], 'stack': [], 'status': 'done'}),
('block result keeps one value above outer operand',
([['const', 43], ['block', 1], ['const', 5], ['const', 7], ['br', 0], ['const', 99], ['end']], [], 50),
{'locals': [], 'stack': [43, 7], 'status': 'done'}),
('void block branch discards operands',
([['block', 0], ['const', 1], ['const', 3], ['br', 0], ['end'], ['const', 3]], [], 50),
{'locals': [], 'stack': [3], 'status': 'done'}),
('untaken br_if consumes its condition',
([['const', 30], ['block', 0], ['const', 0], ['br_if', 0], ['const', 3], ['add'], ['end']], [], 50),
{'locals': [], 'stack': [33], 'status': 'done'}),
('taken br_if exits the block',
([['const', 10], ['block', 0], ['const', 3], ['br_if', 0], ['const', 3], ['add'], ['end']], [], 50),
{'locals': [], 'stack': [10], 'status': 'done'}),
('control: fuel exhaustion',
([['block', 0],
['loop', 0],
['get', 0],
['eqz'],
['br_if', 1],
['get', 1],
['get', 0],
['add'],
['set', 1],
['get', 0],
['const', 1],
['sub'],
['set', 0],
['br', 0],
['end'],
['end']],
[50, 0],
23),
{'locals': [49, 99], 'stack': [49, 1], 'status': 'fuel'})],
[('regression: counted loop exits through outer block',
([['block', 0],
['loop', 0],
['get', 0],
['eqz'],
['br_if', 1],
['get', 1],
['get', 0],
['add'],
['set', 1],
['get', 0],
['const', 1],
['sub'],
['set', 0],
['br', 0],
['end'],
['end']],
[5, 0],
500),
{'locals': [0, 15], 'stack': [], 'status': 'done'}),
('continue from inside a nested block',
([['block', 0],
['loop', 0],
['get', 0],
['eqz'],
['br_if', 1],
['block', 0],
['get', 0],
['const', 1],
['sub'],
['set', 0],
['get', 1],
['const', 2],
['add'],
['set', 1],
['br', 1],
['end'],
['const', 999],
['set', 1],
['end'],
['end']],
[5, 0],
500),
{'locals': [0, 10], 'stack': [], 'status': 'done'}),
('continue loop with more iterations',
([['block', 0],
['loop', 0],
['get', 0],
['eqz'],
['br_if', 1],
['block', 0],
['get', 0],
['const', 1],
['sub'],
['set', 0],
['get', 1],
['const', 2],
['add'],
['set', 1],
['br', 1],
['end'],
['const', 999],
['set', 1],
['end'],
['end']],
[7, 0],
900),
{'locals': [0, 14], 'stack': [], 'status': 'done'}),
('block result keeps one value above outer operand',
([['const', 44], ['block', 1], ['const', 5], ['const', 7], ['br', 0], ['const', 99], ['end']], [], 50),
{'locals': [], 'stack': [44, 7], 'status': 'done'}),
('void block branch discards operands',
([['block', 0], ['const', 1], ['const', 4], ['br', 0], ['end'], ['const', 3]], [], 50),
{'locals': [], 'stack': [3], 'status': 'done'}),
('untaken br_if consumes its condition',
([['const', 40], ['block', 0], ['const', 0], ['br_if', 0], ['const', 3], ['add'], ['end']], [], 50),
{'locals': [], 'stack': [43], 'status': 'done'}),
('taken br_if exits the block',
([['const', 10], ['block', 0], ['const', 4], ['br_if', 0], ['const', 3], ['add'], ['end']], [], 50),
{'locals': [], 'stack': [10], 'status': 'done'}),
('control: fuel exhaustion',
([['block', 0],
['loop', 0],
['get', 0],
['eqz'],
['br_if', 1],
['get', 1],
['get', 0],
['add'],
['set', 1],
['get', 0],
['const', 1],
['sub'],
['set', 0],
['br', 0],
['end'],
['end']],
[50, 0],
24),
{'locals': [49, 99], 'stack': [48], 'status': 'fuel'})],
[('regression: counted loop exits through outer block',
([['block', 0],
['loop', 0],
['get', 0],
['eqz'],
['br_if', 1],
['get', 1],
['get', 0],
['add'],
['set', 1],
['get', 0],
['const', 1],
['sub'],
['set', 0],
['br', 0],
['end'],
['end']],
[6, 0],
500),
{'locals': [0, 21], 'stack': [], 'status': 'done'}),
('continue from inside a nested block',
([['block', 0],
['loop', 0],
['get', 0],
['eqz'],
['br_if', 1],
['block', 0],
['get', 0],
['const', 1],
['sub'],
['set', 0],
['get', 1],
['const', 2],
['add'],
['set', 1],
['br', 1],
['end'],
['const', 999],
['set', 1],
['end'],
['end']],
[6, 0],
500),
{'locals': [0, 12], 'stack': [], 'status': 'done'}),
('continue loop with more iterations',
([['block', 0],
['loop', 0],
['get', 0],
['eqz'],
['br_if', 1],
['block', 0],
['get', 0],
['const', 1],
['sub'],
['set', 0],
['get', 1],
['const', 2],
['add'],
['set', 1],
['br', 1],
['end'],
['const', 999],
['set', 1],
['end'],
['end']],
[8, 0],
900),
{'locals': [0, 16], 'stack': [], 'status': 'done'}),
('block result keeps one value above outer operand',
([['const', 45], ['block', 1], ['const', 5], ['const', 7], ['br', 0], ['const', 99], ['end']], [], 50),
{'locals': [], 'stack': [45, 7], 'status': 'done'}),
('void block branch discards operands',
([['block', 0], ['const', 1], ['const', 5], ['br', 0], ['end'], ['const', 3]], [], 50),
{'locals': [], 'stack': [3], 'status': 'done'}),
('untaken br_if consumes its condition',
([['const', 50], ['block', 0], ['const', 0], ['br_if', 0], ['const', 3], ['add'], ['end']], [], 50),
{'locals': [], 'stack': [53], 'status': 'done'}),
('taken br_if exits the block',
([['const', 10], ['block', 0], ['const', 5], ['br_if', 0], ['const', 3], ['add'], ['end']], [], 50),
{'locals': [], 'stack': [10], 'status': 'done'}),
('control: fuel exhaustion',
([['block', 0],
['loop', 0],
['get', 0],
['eqz'],
['br_if', 1],
['get', 1],
['get', 0],
['add'],
['set', 1],
['get', 0],
['const', 1],
['sub'],
['set', 0],
['br', 0],
['end'],
['end']],
[50, 0],
25),
{'locals': [48, 99], 'stack': [], 'status': 'fuel'})]]
for label, args, expected in cases[N - 1]:
check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
| Boundary fixture | Actual | Expected | Outcome |
|---|---|---|---|
| regression: counted loop exits through outer block | {'locals': [0, 3], 'stack': [], 'status': 'done'} | {'locals': [0, 3], 'stack': [], 'status': 'done'} | Passed |
| continue from inside a nested block | {'locals': [0, 4], 'stack': [], 'status': 'done'} | {'locals': [0, 4], 'stack': [], 'status': 'done'} | Passed |
| continue loop with more iterations | {'locals': [0, 8], 'stack': [], 'status': 'done'} | {'locals': [0, 8], 'stack': [], 'status': 'done'} | Passed |
| block result keeps one value above outer operand | {'locals': [], 'stack': [41, 5, 7], 'status': 'done'} | {'locals': [], 'stack': [41, 7], 'status': 'done'} | Failed |
| void block branch discards operands | {'locals': [], 'stack': [1, 1, 3], 'status': 'done'} | {'locals': [], 'stack': [3], 'status': 'done'} | Failed |
| untaken br_if consumes its condition | {'locals': [], 'stack': [13], 'status': 'done'} | {'locals': [], 'stack': [13], 'status': 'done'} | Passed |
| taken br_if exits the block | {'locals': [], 'stack': [10], 'status': 'done'} | {'locals': [], 'stack': [10], 'status': 'done'} | Passed |
| control: fuel exhaustion | {'locals': [49, 99], 'stack': [], 'status': 'fuel'} | {'locals': [49, 99], 'stack': [], 'status': 'fuel'} | Passed |
SHA-256 / ed60fb1e98dc1332ecf0ef53d18b3faffe85c27f888e485a5406a4644c19510a
2 / The unsuccessful fix
Exit 1"""Failure Map reference implementation. Python standard library only."""
import json
N = 1
observations = []
def solve(code, locals_, fuel):
match = {}
opens = []
for i, ins in enumerate(code):
if ins[0] in ('block', 'loop'):
opens.append(i)
elif ins[0] == 'end':
match[opens.pop()] = i
loc = list(locals_)
stack = []
labels = []
pc = 0
steps = 0
try:
while pc < len(code):
if steps == fuel:
return {'status': 'fuel', 'stack': stack, 'locals': loc}
steps += 1
ins = code[pc]
op = ins[0]
if op in ('block', 'loop'):
labels.append({'kind': op, 'pc': pc, 'end': match[pc], 'height': len(stack),
'arity': ins[1] if op == 'block' else 0})
pc += 1
elif op == 'end':
labels.pop()
pc += 1
elif op in ('br', 'br_if'):
if op == 'br_if' and stack.pop() == 0:
pc += 1
continue
target = labels[len(labels) - 1 - ins[1]]
keep = stack[len(stack) - target['arity']:] if target['arity'] else []
del stack[:target['height']]
stack.extend(keep)
if target['kind'] == 'loop':
del labels[len(labels) - ins[1]:]
pc = target['pc'] + 1
else:
del labels[len(labels) - 1 - ins[1]:]
pc = target['end'] + 1
elif op == 'const':
stack.append(ins[1])
pc += 1
elif op in ('add', 'sub'):
b = stack.pop()
a = stack.pop()
stack.append(a + b if op == 'add' else a - b)
pc += 1
elif op == 'eqz':
stack.append(1 if stack.pop() == 0 else 0)
pc += 1
elif op == 'get':
stack.append(loc[ins[1]])
pc += 1
elif op == 'set':
loc[ins[1]] = stack.pop()
pc += 1
else:
stack.pop()
pc += 1
except IndexError:
return {'status': 'trap', 'stack': stack, 'locals': loc}
return {'status': 'done', 'stack': stack, 'locals': loc}
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression: counted loop exits through outer block',
([['block', 0],
['loop', 0],
['get', 0],
['eqz'],
['br_if', 1],
['get', 1],
['get', 0],
['add'],
['set', 1],
['get', 0],
['const', 1],
['sub'],
['set', 0],
['br', 0],
['end'],
['end']],
[2, 0],
500),
{'locals': [0, 3], 'stack': [], 'status': 'done'}),
('continue from inside a nested block',
([['block', 0],
['loop', 0],
['get', 0],
['eqz'],
['br_if', 1],
['block', 0],
['get', 0],
['const', 1],
['sub'],
['set', 0],
['get', 1],
['const', 2],
['add'],
['set', 1],
['br', 1],
['end'],
['const', 999],
['set', 1],
['end'],
['end']],
[2, 0],
500),
{'locals': [0, 4], 'stack': [], 'status': 'done'}),
('continue loop with more iterations',
([['block', 0],
['loop', 0],
['get', 0],
['eqz'],
['br_if', 1],
['block', 0],
['get', 0],
['const', 1],
['sub'],
['set', 0],
['get', 1],
['const', 2],
['add'],
['set', 1],
['br', 1],
['end'],
['const', 999],
['set', 1],
['end'],
['end']],
[4, 0],
900),
{'locals': [0, 8], 'stack': [], 'status': 'done'}),
('block result keeps one value above outer operand',
([['const', 41], ['block', 1], ['const', 5], ['const', 7], ['br', 0], ['const', 99], ['end']], [], 50),
{'locals': [], 'stack': [41, 7], 'status': 'done'}),
('void block branch discards operands',
([['block', 0], ['const', 1], ['const', 1], ['br', 0], ['end'], ['const', 3]], [], 50),
{'locals': [], 'stack': [3], 'status': 'done'}),
('untaken br_if consumes its condition',
([['const', 10], ['block', 0], ['const', 0], ['br_if', 0], ['const', 3], ['add'], ['end']], [], 50),
{'locals': [], 'stack': [13], 'status': 'done'}),
('taken br_if exits the block',
([['const', 10], ['block', 0], ['const', 1], ['br_if', 0], ['const', 3], ['add'], ['end']], [], 50),
{'locals': [], 'stack': [10], 'status': 'done'}),
('control: fuel exhaustion',
([['block', 0],
['loop', 0],
['get', 0],
['eqz'],
['br_if', 1],
['get', 1],
['get', 0],
['add'],
['set', 1],
['get', 0],
['const', 1],
['sub'],
['set', 0],
['br', 0],
['end'],
['end']],
[50, 0],
21),
{'locals': [49, 99], 'stack': [], 'status': 'fuel'})],
[('regression: counted loop exits through outer block',
([['block', 0],
['loop', 0],
['get', 0],
['eqz'],
['br_if', 1],
['get', 1],
['get', 0],
['add'],
['set', 1],
['get', 0],
['const', 1],
['sub'],
['set', 0],
['br', 0],
['end'],
['end']],
[3, 0],
500),
{'locals': [0, 6], 'stack': [], 'status': 'done'}),
('continue from inside a nested block',
([['block', 0],
['loop', 0],
['get', 0],
['eqz'],
['br_if', 1],
['block', 0],
['get', 0],
['const', 1],
['sub'],
['set', 0],
['get', 1],
['const', 2],
['add'],
['set', 1],
['br', 1],
['end'],
['const', 999],
['set', 1],
['end'],
['end']],
[3, 0],
500),
{'locals': [0, 6], 'stack': [], 'status': 'done'}),
('continue loop with more iterations',
([['block', 0],
['loop', 0],
['get', 0],
['eqz'],
['br_if', 1],
['block', 0],
['get', 0],
['const', 1],
['sub'],
['set', 0],
['get', 1],
['const', 2],
['add'],
['set', 1],
['br', 1],
['end'],
['const', 999],
['set', 1],
['end'],
['end']],
[5, 0],
900),
{'locals': [0, 10], 'stack': [], 'status': 'done'}),
('block result keeps one value above outer operand',
([['const', 42], ['block', 1], ['const', 5], ['const', 7], ['br', 0], ['const', 99], ['end']], [], 50),
{'locals': [], 'stack': [42, 7], 'status': 'done'}),
('void block branch discards operands',
([['block', 0], ['const', 1], ['const', 2], ['br', 0], ['end'], ['const', 3]], [], 50),
{'locals': [], 'stack': [3], 'status': 'done'}),
('untaken br_if consumes its condition',
([['const', 20], ['block', 0], ['const', 0], ['br_if', 0], ['const', 3], ['add'], ['end']], [], 50),
{'locals': [], 'stack': [23], 'status': 'done'}),
('taken br_if exits the block',
([['const', 10], ['block', 0], ['const', 2], ['br_if', 0], ['const', 3], ['add'], ['end']], [], 50),
{'locals': [], 'stack': [10], 'status': 'done'}),
('control: fuel exhaustion',
([['block', 0],
['loop', 0],
['get', 0],
['eqz'],
['br_if', 1],
['get', 1],
['get', 0],
['add'],
['set', 1],
['get', 0],
['const', 1],
['sub'],
['set', 0],
['br', 0],
['end'],
['end']],
[50, 0],
22),
{'locals': [49, 99], 'stack': [49], 'status': 'fuel'})],
[('regression: counted loop exits through outer block',
([['block', 0],
['loop', 0],
['get', 0],
['eqz'],
['br_if', 1],
['get', 1],
['get', 0],
['add'],
['set', 1],
['get', 0],
['const', 1],
['sub'],
['set', 0],
['br', 0],
['end'],
['end']],
[4, 0],
500),
{'locals': [0, 10], 'stack': [], 'status': 'done'}),
('continue from inside a nested block',
([['block', 0],
['loop', 0],
['get', 0],
['eqz'],
['br_if', 1],
['block', 0],
['get', 0],
['const', 1],
['sub'],
['set', 0],
['get', 1],
['const', 2],
['add'],
['set', 1],
['br', 1],
['end'],
['const', 999],
['set', 1],
['end'],
['end']],
[4, 0],
500),
{'locals': [0, 8], 'stack': [], 'status': 'done'}),
('continue loop with more iterations',
([['block', 0],
['loop', 0],
['get', 0],
['eqz'],
['br_if', 1],
['block', 0],
['get', 0],
['const', 1],
['sub'],
['set', 0],
['get', 1],
['const', 2],
['add'],
['set', 1],
['br', 1],
['end'],
['const', 999],
['set', 1],
['end'],
['end']],
[6, 0],
900),
{'locals': [0, 12], 'stack': [], 'status': 'done'}),
('block result keeps one value above outer operand',
([['const', 43], ['block', 1], ['const', 5], ['const', 7], ['br', 0], ['const', 99], ['end']], [], 50),
{'locals': [], 'stack': [43, 7], 'status': 'done'}),
('void block branch discards operands',
([['block', 0], ['const', 1], ['const', 3], ['br', 0], ['end'], ['const', 3]], [], 50),
{'locals': [], 'stack': [3], 'status': 'done'}),
('untaken br_if consumes its condition',
([['const', 30], ['block', 0], ['const', 0], ['br_if', 0], ['const', 3], ['add'], ['end']], [], 50),
{'locals': [], 'stack': [33], 'status': 'done'}),
('taken br_if exits the block',
([['const', 10], ['block', 0], ['const', 3], ['br_if', 0], ['const', 3], ['add'], ['end']], [], 50),
{'locals': [], 'stack': [10], 'status': 'done'}),
('control: fuel exhaustion',
([['block', 0],
['loop', 0],
['get', 0],
['eqz'],
['br_if', 1],
['get', 1],
['get', 0],
['add'],
['set', 1],
['get', 0],
['const', 1],
['sub'],
['set', 0],
['br', 0],
['end'],
['end']],
[50, 0],
23),
{'locals': [49, 99], 'stack': [49, 1], 'status': 'fuel'})],
[('regression: counted loop exits through outer block',
([['block', 0],
['loop', 0],
['get', 0],
['eqz'],
['br_if', 1],
['get', 1],
['get', 0],
['add'],
['set', 1],
['get', 0],
['const', 1],
['sub'],
['set', 0],
['br', 0],
['end'],
['end']],
[5, 0],
500),
{'locals': [0, 15], 'stack': [], 'status': 'done'}),
('continue from inside a nested block',
([['block', 0],
['loop', 0],
['get', 0],
['eqz'],
['br_if', 1],
['block', 0],
['get', 0],
['const', 1],
['sub'],
['set', 0],
['get', 1],
['const', 2],
['add'],
['set', 1],
['br', 1],
['end'],
['const', 999],
['set', 1],
['end'],
['end']],
[5, 0],
500),
{'locals': [0, 10], 'stack': [], 'status': 'done'}),
('continue loop with more iterations',
([['block', 0],
['loop', 0],
['get', 0],
['eqz'],
['br_if', 1],
['block', 0],
['get', 0],
['const', 1],
['sub'],
['set', 0],
['get', 1],
['const', 2],
['add'],
['set', 1],
['br', 1],
['end'],
['const', 999],
['set', 1],
['end'],
['end']],
[7, 0],
900),
{'locals': [0, 14], 'stack': [], 'status': 'done'}),
('block result keeps one value above outer operand',
([['const', 44], ['block', 1], ['const', 5], ['const', 7], ['br', 0], ['const', 99], ['end']], [], 50),
{'locals': [], 'stack': [44, 7], 'status': 'done'}),
('void block branch discards operands',
([['block', 0], ['const', 1], ['const', 4], ['br', 0], ['end'], ['const', 3]], [], 50),
{'locals': [], 'stack': [3], 'status': 'done'}),
('untaken br_if consumes its condition',
([['const', 40], ['block', 0], ['const', 0], ['br_if', 0], ['const', 3], ['add'], ['end']], [], 50),
{'locals': [], 'stack': [43], 'status': 'done'}),
('taken br_if exits the block',
([['const', 10], ['block', 0], ['const', 4], ['br_if', 0], ['const', 3], ['add'], ['end']], [], 50),
{'locals': [], 'stack': [10], 'status': 'done'}),
('control: fuel exhaustion',
([['block', 0],
['loop', 0],
['get', 0],
['eqz'],
['br_if', 1],
['get', 1],
['get', 0],
['add'],
['set', 1],
['get', 0],
['const', 1],
['sub'],
['set', 0],
['br', 0],
['end'],
['end']],
[50, 0],
24),
{'locals': [49, 99], 'stack': [48], 'status': 'fuel'})],
[('regression: counted loop exits through outer block',
([['block', 0],
['loop', 0],
['get', 0],
['eqz'],
['br_if', 1],
['get', 1],
['get', 0],
['add'],
['set', 1],
['get', 0],
['const', 1],
['sub'],
['set', 0],
['br', 0],
['end'],
['end']],
[6, 0],
500),
{'locals': [0, 21], 'stack': [], 'status': 'done'}),
('continue from inside a nested block',
([['block', 0],
['loop', 0],
['get', 0],
['eqz'],
['br_if', 1],
['block', 0],
['get', 0],
['const', 1],
['sub'],
['set', 0],
['get', 1],
['const', 2],
['add'],
['set', 1],
['br', 1],
['end'],
['const', 999],
['set', 1],
['end'],
['end']],
[6, 0],
500),
{'locals': [0, 12], 'stack': [], 'status': 'done'}),
('continue loop with more iterations',
([['block', 0],
['loop', 0],
['get', 0],
['eqz'],
['br_if', 1],
['block', 0],
['get', 0],
['const', 1],
['sub'],
['set', 0],
['get', 1],
['const', 2],
['add'],
['set', 1],
['br', 1],
['end'],
['const', 999],
['set', 1],
['end'],
['end']],
[8, 0],
900),
{'locals': [0, 16], 'stack': [], 'status': 'done'}),
('block result keeps one value above outer operand',
([['const', 45], ['block', 1], ['const', 5], ['const', 7], ['br', 0], ['const', 99], ['end']], [], 50),
{'locals': [], 'stack': [45, 7], 'status': 'done'}),
('void block branch discards operands',
([['block', 0], ['const', 1], ['const', 5], ['br', 0], ['end'], ['const', 3]], [], 50),
{'locals': [], 'stack': [3], 'status': 'done'}),
('untaken br_if consumes its condition',
([['const', 50], ['block', 0], ['const', 0], ['br_if', 0], ['const', 3], ['add'], ['end']], [], 50),
{'locals': [], 'stack': [53], 'status': 'done'}),
('taken br_if exits the block',
([['const', 10], ['block', 0], ['const', 5], ['br_if', 0], ['const', 3], ['add'], ['end']], [], 50),
{'locals': [], 'stack': [10], 'status': 'done'}),
('control: fuel exhaustion',
([['block', 0],
['loop', 0],
['get', 0],
['eqz'],
['br_if', 1],
['get', 1],
['get', 0],
['add'],
['set', 1],
['get', 0],
['const', 1],
['sub'],
['set', 0],
['br', 0],
['end'],
['end']],
[50, 0],
25),
{'locals': [48, 99], 'stack': [], 'status': 'fuel'})]]
for label, args, expected in cases[N - 1]:
check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
| Boundary fixture | Actual | Expected | Outcome |
|---|---|---|---|
| regression: counted loop exits through outer block | {'locals': [0, 3], 'stack': [], 'status': 'done'} | {'locals': [0, 3], 'stack': [], 'status': 'done'} | Passed |
| continue from inside a nested block | {'locals': [0, 4], 'stack': [], 'status': 'done'} | {'locals': [0, 4], 'stack': [], 'status': 'done'} | Passed |
| continue loop with more iterations | {'locals': [0, 8], 'stack': [], 'status': 'done'} | {'locals': [0, 8], 'stack': [], 'status': 'done'} | Passed |
| block result keeps one value above outer operand | {'locals': [], 'stack': [5, 7, 7], 'status': 'done'} | {'locals': [], 'stack': [41, 7], 'status': 'done'} | Failed |
| void block branch discards operands | {'locals': [], 'stack': [1, 1, 3], 'status': 'done'} | {'locals': [], 'stack': [3], 'status': 'done'} | Failed |
| untaken br_if consumes its condition | {'locals': [], 'stack': [13], 'status': 'done'} | {'locals': [], 'stack': [13], 'status': 'done'} | Passed |
| taken br_if exits the block | {'locals': [], 'stack': [], 'status': 'done'} | {'locals': [], 'stack': [10], 'status': 'done'} | Failed |
| control: fuel exhaustion | {'locals': [49, 99], 'stack': [], 'status': 'fuel'} | {'locals': [49, 99], 'stack': [], 'status': 'fuel'} | Passed |
SHA-256 / 8c2ee72dfd60ef993f283abe0d73e85de67ab3aa82004a4d8dfdd67eb5c5f8b3
3 / The verified repair
Exit 0"""Failure Map reference implementation. Python standard library only."""
import json
N = 1
observations = []
def solve(code, locals_, fuel):
match = {}
opens = []
for i, ins in enumerate(code):
if ins[0] in ('block', 'loop'):
opens.append(i)
elif ins[0] == 'end':
match[opens.pop()] = i
loc = list(locals_)
stack = []
labels = []
pc = 0
steps = 0
try:
while pc < len(code):
if steps == fuel:
return {'status': 'fuel', 'stack': stack, 'locals': loc}
steps += 1
ins = code[pc]
op = ins[0]
if op in ('block', 'loop'):
labels.append({'kind': op, 'pc': pc, 'end': match[pc], 'height': len(stack),
'arity': ins[1] if op == 'block' else 0})
pc += 1
elif op == 'end':
labels.pop()
pc += 1
elif op in ('br', 'br_if'):
if op == 'br_if' and stack.pop() == 0:
pc += 1
continue
target = labels[len(labels) - 1 - ins[1]]
keep = stack[len(stack) - target['arity']:] if target['arity'] else []
del stack[target['height']:]
stack.extend(keep)
if target['kind'] == 'loop':
del labels[len(labels) - ins[1]:]
pc = target['pc'] + 1
else:
del labels[len(labels) - 1 - ins[1]:]
pc = target['end'] + 1
elif op == 'const':
stack.append(ins[1])
pc += 1
elif op in ('add', 'sub'):
b = stack.pop()
a = stack.pop()
stack.append(a + b if op == 'add' else a - b)
pc += 1
elif op == 'eqz':
stack.append(1 if stack.pop() == 0 else 0)
pc += 1
elif op == 'get':
stack.append(loc[ins[1]])
pc += 1
elif op == 'set':
loc[ins[1]] = stack.pop()
pc += 1
else:
stack.pop()
pc += 1
except IndexError:
return {'status': 'trap', 'stack': stack, 'locals': loc}
return {'status': 'done', 'stack': stack, 'locals': loc}
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression: counted loop exits through outer block',
([['block', 0],
['loop', 0],
['get', 0],
['eqz'],
['br_if', 1],
['get', 1],
['get', 0],
['add'],
['set', 1],
['get', 0],
['const', 1],
['sub'],
['set', 0],
['br', 0],
['end'],
['end']],
[2, 0],
500),
{'locals': [0, 3], 'stack': [], 'status': 'done'}),
('continue from inside a nested block',
([['block', 0],
['loop', 0],
['get', 0],
['eqz'],
['br_if', 1],
['block', 0],
['get', 0],
['const', 1],
['sub'],
['set', 0],
['get', 1],
['const', 2],
['add'],
['set', 1],
['br', 1],
['end'],
['const', 999],
['set', 1],
['end'],
['end']],
[2, 0],
500),
{'locals': [0, 4], 'stack': [], 'status': 'done'}),
('continue loop with more iterations',
([['block', 0],
['loop', 0],
['get', 0],
['eqz'],
['br_if', 1],
['block', 0],
['get', 0],
['const', 1],
['sub'],
['set', 0],
['get', 1],
['const', 2],
['add'],
['set', 1],
['br', 1],
['end'],
['const', 999],
['set', 1],
['end'],
['end']],
[4, 0],
900),
{'locals': [0, 8], 'stack': [], 'status': 'done'}),
('block result keeps one value above outer operand',
([['const', 41], ['block', 1], ['const', 5], ['const', 7], ['br', 0], ['const', 99], ['end']], [], 50),
{'locals': [], 'stack': [41, 7], 'status': 'done'}),
('void block branch discards operands',
([['block', 0], ['const', 1], ['const', 1], ['br', 0], ['end'], ['const', 3]], [], 50),
{'locals': [], 'stack': [3], 'status': 'done'}),
('untaken br_if consumes its condition',
([['const', 10], ['block', 0], ['const', 0], ['br_if', 0], ['const', 3], ['add'], ['end']], [], 50),
{'locals': [], 'stack': [13], 'status': 'done'}),
('taken br_if exits the block',
([['const', 10], ['block', 0], ['const', 1], ['br_if', 0], ['const', 3], ['add'], ['end']], [], 50),
{'locals': [], 'stack': [10], 'status': 'done'}),
('control: fuel exhaustion',
([['block', 0],
['loop', 0],
['get', 0],
['eqz'],
['br_if', 1],
['get', 1],
['get', 0],
['add'],
['set', 1],
['get', 0],
['const', 1],
['sub'],
['set', 0],
['br', 0],
['end'],
['end']],
[50, 0],
21),
{'locals': [49, 99], 'stack': [], 'status': 'fuel'})],
[('regression: counted loop exits through outer block',
([['block', 0],
['loop', 0],
['get', 0],
['eqz'],
['br_if', 1],
['get', 1],
['get', 0],
['add'],
['set', 1],
['get', 0],
['const', 1],
['sub'],
['set', 0],
['br', 0],
['end'],
['end']],
[3, 0],
500),
{'locals': [0, 6], 'stack': [], 'status': 'done'}),
('continue from inside a nested block',
([['block', 0],
['loop', 0],
['get', 0],
['eqz'],
['br_if', 1],
['block', 0],
['get', 0],
['const', 1],
['sub'],
['set', 0],
['get', 1],
['const', 2],
['add'],
['set', 1],
['br', 1],
['end'],
['const', 999],
['set', 1],
['end'],
['end']],
[3, 0],
500),
{'locals': [0, 6], 'stack': [], 'status': 'done'}),
('continue loop with more iterations',
([['block', 0],
['loop', 0],
['get', 0],
['eqz'],
['br_if', 1],
['block', 0],
['get', 0],
['const', 1],
['sub'],
['set', 0],
['get', 1],
['const', 2],
['add'],
['set', 1],
['br', 1],
['end'],
['const', 999],
['set', 1],
['end'],
['end']],
[5, 0],
900),
{'locals': [0, 10], 'stack': [], 'status': 'done'}),
('block result keeps one value above outer operand',
([['const', 42], ['block', 1], ['const', 5], ['const', 7], ['br', 0], ['const', 99], ['end']], [], 50),
{'locals': [], 'stack': [42, 7], 'status': 'done'}),
('void block branch discards operands',
([['block', 0], ['const', 1], ['const', 2], ['br', 0], ['end'], ['const', 3]], [], 50),
{'locals': [], 'stack': [3], 'status': 'done'}),
('untaken br_if consumes its condition',
([['const', 20], ['block', 0], ['const', 0], ['br_if', 0], ['const', 3], ['add'], ['end']], [], 50),
{'locals': [], 'stack': [23], 'status': 'done'}),
('taken br_if exits the block',
([['const', 10], ['block', 0], ['const', 2], ['br_if', 0], ['const', 3], ['add'], ['end']], [], 50),
{'locals': [], 'stack': [10], 'status': 'done'}),
('control: fuel exhaustion',
([['block', 0],
['loop', 0],
['get', 0],
['eqz'],
['br_if', 1],
['get', 1],
['get', 0],
['add'],
['set', 1],
['get', 0],
['const', 1],
['sub'],
['set', 0],
['br', 0],
['end'],
['end']],
[50, 0],
22),
{'locals': [49, 99], 'stack': [49], 'status': 'fuel'})],
[('regression: counted loop exits through outer block',
([['block', 0],
['loop', 0],
['get', 0],
['eqz'],
['br_if', 1],
['get', 1],
['get', 0],
['add'],
['set', 1],
['get', 0],
['const', 1],
['sub'],
['set', 0],
['br', 0],
['end'],
['end']],
[4, 0],
500),
{'locals': [0, 10], 'stack': [], 'status': 'done'}),
('continue from inside a nested block',
([['block', 0],
['loop', 0],
['get', 0],
['eqz'],
['br_if', 1],
['block', 0],
['get', 0],
['const', 1],
['sub'],
['set', 0],
['get', 1],
['const', 2],
['add'],
['set', 1],
['br', 1],
['end'],
['const', 999],
['set', 1],
['end'],
['end']],
[4, 0],
500),
{'locals': [0, 8], 'stack': [], 'status': 'done'}),
('continue loop with more iterations',
([['block', 0],
['loop', 0],
['get', 0],
['eqz'],
['br_if', 1],
['block', 0],
['get', 0],
['const', 1],
['sub'],
['set', 0],
['get', 1],
['const', 2],
['add'],
['set', 1],
['br', 1],
['end'],
['const', 999],
['set', 1],
['end'],
['end']],
[6, 0],
900),
{'locals': [0, 12], 'stack': [], 'status': 'done'}),
('block result keeps one value above outer operand',
([['const', 43], ['block', 1], ['const', 5], ['const', 7], ['br', 0], ['const', 99], ['end']], [], 50),
{'locals': [], 'stack': [43, 7], 'status': 'done'}),
('void block branch discards operands',
([['block', 0], ['const', 1], ['const', 3], ['br', 0], ['end'], ['const', 3]], [], 50),
{'locals': [], 'stack': [3], 'status': 'done'}),
('untaken br_if consumes its condition',
([['const', 30], ['block', 0], ['const', 0], ['br_if', 0], ['const', 3], ['add'], ['end']], [], 50),
{'locals': [], 'stack': [33], 'status': 'done'}),
('taken br_if exits the block',
([['const', 10], ['block', 0], ['const', 3], ['br_if', 0], ['const', 3], ['add'], ['end']], [], 50),
{'locals': [], 'stack': [10], 'status': 'done'}),
('control: fuel exhaustion',
([['block', 0],
['loop', 0],
['get', 0],
['eqz'],
['br_if', 1],
['get', 1],
['get', 0],
['add'],
['set', 1],
['get', 0],
['const', 1],
['sub'],
['set', 0],
['br', 0],
['end'],
['end']],
[50, 0],
23),
{'locals': [49, 99], 'stack': [49, 1], 'status': 'fuel'})],
[('regression: counted loop exits through outer block',
([['block', 0],
['loop', 0],
['get', 0],
['eqz'],
['br_if', 1],
['get', 1],
['get', 0],
['add'],
['set', 1],
['get', 0],
['const', 1],
['sub'],
['set', 0],
['br', 0],
['end'],
['end']],
[5, 0],
500),
{'locals': [0, 15], 'stack': [], 'status': 'done'}),
('continue from inside a nested block',
([['block', 0],
['loop', 0],
['get', 0],
['eqz'],
['br_if', 1],
['block', 0],
['get', 0],
['const', 1],
['sub'],
['set', 0],
['get', 1],
['const', 2],
['add'],
['set', 1],
['br', 1],
['end'],
['const', 999],
['set', 1],
['end'],
['end']],
[5, 0],
500),
{'locals': [0, 10], 'stack': [], 'status': 'done'}),
('continue loop with more iterations',
([['block', 0],
['loop', 0],
['get', 0],
['eqz'],
['br_if', 1],
['block', 0],
['get', 0],
['const', 1],
['sub'],
['set', 0],
['get', 1],
['const', 2],
['add'],
['set', 1],
['br', 1],
['end'],
['const', 999],
['set', 1],
['end'],
['end']],
[7, 0],
900),
{'locals': [0, 14], 'stack': [], 'status': 'done'}),
('block result keeps one value above outer operand',
([['const', 44], ['block', 1], ['const', 5], ['const', 7], ['br', 0], ['const', 99], ['end']], [], 50),
{'locals': [], 'stack': [44, 7], 'status': 'done'}),
('void block branch discards operands',
([['block', 0], ['const', 1], ['const', 4], ['br', 0], ['end'], ['const', 3]], [], 50),
{'locals': [], 'stack': [3], 'status': 'done'}),
('untaken br_if consumes its condition',
([['const', 40], ['block', 0], ['const', 0], ['br_if', 0], ['const', 3], ['add'], ['end']], [], 50),
{'locals': [], 'stack': [43], 'status': 'done'}),
('taken br_if exits the block',
([['const', 10], ['block', 0], ['const', 4], ['br_if', 0], ['const', 3], ['add'], ['end']], [], 50),
{'locals': [], 'stack': [10], 'status': 'done'}),
('control: fuel exhaustion',
([['block', 0],
['loop', 0],
['get', 0],
['eqz'],
['br_if', 1],
['get', 1],
['get', 0],
['add'],
['set', 1],
['get', 0],
['const', 1],
['sub'],
['set', 0],
['br', 0],
['end'],
['end']],
[50, 0],
24),
{'locals': [49, 99], 'stack': [48], 'status': 'fuel'})],
[('regression: counted loop exits through outer block',
([['block', 0],
['loop', 0],
['get', 0],
['eqz'],
['br_if', 1],
['get', 1],
['get', 0],
['add'],
['set', 1],
['get', 0],
['const', 1],
['sub'],
['set', 0],
['br', 0],
['end'],
['end']],
[6, 0],
500),
{'locals': [0, 21], 'stack': [], 'status': 'done'}),
('continue from inside a nested block',
([['block', 0],
['loop', 0],
['get', 0],
['eqz'],
['br_if', 1],
['block', 0],
['get', 0],
['const', 1],
['sub'],
['set', 0],
['get', 1],
['const', 2],
['add'],
['set', 1],
['br', 1],
['end'],
['const', 999],
['set', 1],
['end'],
['end']],
[6, 0],
500),
{'locals': [0, 12], 'stack': [], 'status': 'done'}),
('continue loop with more iterations',
([['block', 0],
['loop', 0],
['get', 0],
['eqz'],
['br_if', 1],
['block', 0],
['get', 0],
['const', 1],
['sub'],
['set', 0],
['get', 1],
['const', 2],
['add'],
['set', 1],
['br', 1],
['end'],
['const', 999],
['set', 1],
['end'],
['end']],
[8, 0],
900),
{'locals': [0, 16], 'stack': [], 'status': 'done'}),
('block result keeps one value above outer operand',
([['const', 45], ['block', 1], ['const', 5], ['const', 7], ['br', 0], ['const', 99], ['end']], [], 50),
{'locals': [], 'stack': [45, 7], 'status': 'done'}),
('void block branch discards operands',
([['block', 0], ['const', 1], ['const', 5], ['br', 0], ['end'], ['const', 3]], [], 50),
{'locals': [], 'stack': [3], 'status': 'done'}),
('untaken br_if consumes its condition',
([['const', 50], ['block', 0], ['const', 0], ['br_if', 0], ['const', 3], ['add'], ['end']], [], 50),
{'locals': [], 'stack': [53], 'status': 'done'}),
('taken br_if exits the block',
([['const', 10], ['block', 0], ['const', 5], ['br_if', 0], ['const', 3], ['add'], ['end']], [], 50),
{'locals': [], 'stack': [10], 'status': 'done'}),
('control: fuel exhaustion',
([['block', 0],
['loop', 0],
['get', 0],
['eqz'],
['br_if', 1],
['get', 1],
['get', 0],
['add'],
['set', 1],
['get', 0],
['const', 1],
['sub'],
['set', 0],
['br', 0],
['end'],
['end']],
[50, 0],
25),
{'locals': [48, 99], 'stack': [], 'status': 'fuel'})]]
for label, args, expected in cases[N - 1]:
check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
| Boundary fixture | Actual | Expected | Outcome |
|---|---|---|---|
| regression: counted loop exits through outer block | {'locals': [0, 3], 'stack': [], 'status': 'done'} | {'locals': [0, 3], 'stack': [], 'status': 'done'} | Passed |
| continue from inside a nested block | {'locals': [0, 4], 'stack': [], 'status': 'done'} | {'locals': [0, 4], 'stack': [], 'status': 'done'} | Passed |
| continue loop with more iterations | {'locals': [0, 8], 'stack': [], 'status': 'done'} | {'locals': [0, 8], 'stack': [], 'status': 'done'} | Passed |
| block result keeps one value above outer operand | {'locals': [], 'stack': [41, 7], 'status': 'done'} | {'locals': [], 'stack': [41, 7], 'status': 'done'} | Passed |
| void block branch discards operands | {'locals': [], 'stack': [3], 'status': 'done'} | {'locals': [], 'stack': [3], 'status': 'done'} | Passed |
| untaken br_if consumes its condition | {'locals': [], 'stack': [13], 'status': 'done'} | {'locals': [], 'stack': [13], 'status': 'done'} | Passed |
| taken br_if exits the block | {'locals': [], 'stack': [10], 'status': 'done'} | {'locals': [], 'stack': [10], 'status': 'done'} | Passed |
| control: fuel exhaustion | {'locals': [49, 99], 'stack': [], 'status': 'fuel'} | {'locals': [49, 99], 'stack': [], 'status': 'fuel'} | Passed |
SHA-256 / 7cdd541f5b8ab45b7ec2fc145d981a4f3c0a7ef5c748913149ba6798ac5a0afa
Verification & scope
A deterministic, bounded teaching model of one bytecode virtual machine mechanism with a stipulated instruction encoding; it is not a production VM and claims no conformance to any real specification. This reproducer isolates one failure mechanism. Results cover the supplied fixtures. Variants within a family share a test contract and should remain grouped when constructing evaluation splits. Related mechanisms with a shared evaluation_group must also remain together; these controlled models are not independent production incidents.
Observations recorded using Python 3.12.14 at 2026-09-29T14:51:23.867163+00:00.
Case digest / f2076015c7d49fabb1a7ef49f541f4c9dc8b6ad47b89b855518afe9dfe3c6732