Skip to content

Fix signed div overflow, call checks & add tests#213

Open
zanville wants to merge 2 commits intoOverclock-Validator:devfrom
zanville:fix/126-side-effects-after-error-in-vm-interpreter
Open

Fix signed div overflow, call checks & add tests#213
zanville wants to merge 2 commits intoOverclock-Validator:devfrom
zanville:fix/126-side-effects-after-error-in-vm-interpreter

Conversation

@zanville
Copy link

Fixes #126

Signed division overflow no longer mutates the destination register, the operation just gets skipped. Divide-by-zero behavior is unchanged.

For calls, stack push result is now checked before we update pc, and callx validates the target is actually inside the text segment. Added ExcCallOutsideTextSegment for the out-of-bounds case so it's not a mystery when it happens.

Exception now saves register state in R when a fault occurs, and errors are wrapped with %w so they're inspectable.
Also fixed the Sdiv opcode mappings and added tests for call depth, out-of-bounds callx, signed div overflow, and divide-by-zero.

Avoid mutating destination registers when signed division/remainder overflows by only performing the operation in the non-overflow branch; preserve semantics for divide-by-zero errors. Improve call handling: check stack push result before changing pc, validate Callx target is inside the text segment and return a dedicated ExcCallOutsideTextSegment error on out-of-bounds. Add Exception.R to capture registers and wrap error with %w for better error inspection. Update opcode mappings for Sdiv variants and extend tests (pkg/sbpf/interpreter_test.go) to cover call depth/out-of-bounds, signed divide overflow and divide-by-zero cases.
…ator#125)

stack.Pop() returns (0, false) when the call stack is empty,
which overwrote pc to 0 on top-level exits. Save pc before
Pop() and restore it when the stack is empty so the final
register state reports the correct exit instruction address.

Adds regression test TestOpExitTopLevel.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[F-D16] Side Effects Occurring After Error in VM Interpreter

1 participant