Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
16b5d63
Add EarlyExit support code for hook error migration
andrei-marinica Oct 1, 2026
6d1fad8
Teach the VMHooks generator about trailing error results
andrei-marinica Oct 1, 2026
fa1f9e8
Regenerate VMHooks/wrapper with VMHooksErrorHandler embedded
andrei-marinica Oct 1, 2026
d673e15
Migrate manMapOps.go hooks to return error
andrei-marinica Oct 1, 2026
1a0a3d2
Migrate smallIntOps.go hooks to return error
andrei-marinica Oct 1, 2026
0446eb0
Migrate bigFloatOps.go hooks to return error
andrei-marinica Oct 1, 2026
02b23e2
Migrate manBufOps.go hooks to return error
andrei-marinica Oct 1, 2026
9237b49
Migrate cryptoei.go hooks to return error
andrei-marinica Oct 1, 2026
a20b082
Migrate managedei.go hooks to return error
andrei-marinica Oct 1, 2026
8e6bb0b
Migrate bigIntOps.go hooks to return error
andrei-marinica Oct 1, 2026
2b26717
Migrate baseOps.go hooks to return error — last of 8 files
andrei-marinica Oct 1, 2026
e307ad8
Make the trailing error result mandatory for all VM hooks
andrei-marinica Oct 1, 2026
c4989db
Delete unused (*VMHooksImpl).FailExecution method
andrei-marinica Oct 1, 2026
a6bcb31
executor - move EarlyExit from vmhost to the executor package
andrei-marinica Oct 22, 2026
938de9d
Merge branch opcodes-v2 into vmhooks-err (after VM advisory)
andrei-marinica Oct 26, 2026
4475305
executor - revert legacy VMHooks, VMHooksLegacyAdapter, revert hook e…
andrei-marinica Oct 26, 2026
504b49f
VM hooks test cleanup (handleHookError refactor)
andrei-marinica Oct 27, 2026
1f70fe3
executor - VM hooks reorg
andrei-marinica Oct 27, 2026
8739890
Merge branch 'opcodes-v2' into vmhooks-err2
andrei-marinica Nov 4, 2026
4196a46
Merge branch 'feat/new-executor' into vmhooks-err2
andrei-marinica Nov 5, 2026
dc62a48
merge error fix
andrei-marinica Nov 5, 2026
23ee4f8
sentinel fixes after merge
andrei-marinica Nov 5, 2026
15db825
merge error fix - additional test
andrei-marinica Nov 5, 2026
894f6cc
Merge branch 'feat/new-executor' into vmhooks-err2
andrei-marinica Nov 5, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions executor/earlyExit.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package executor

import (
vmcommon "github.com/multiversx/mx-chain-vm-common-go"
)

// defaultEarlyExitCode is what an error that does not describe its own early exit means.
//
// Named rather than inlined into ExitExecutionFailed, because an executor that learns to
// report early exits of its own will have to agree with it.
const defaultEarlyExitCode = vmcommon.ExecutionFailed

// EarlyExit is an error that describes how execution must be terminated from inside a VM
// hook.
//
// Counterpart of the Rust `VMHooksEarlyExit` (new_traits/vm_hooks_early_exit.rs). Hooks only
// need to build one for the cases that deviate from the default failure behaviour; for
// everything else a plain error is enough, and the VM supplies the default.
//
// It lives here rather than in the vmhost package because it is what crosses the boundary: an
// executor that reports early exits to the VM reads Code off it. The other fields are the
// VM's own business, and no executor touches them.
type EarlyExit struct {
// Code selects which termination routine the VM applies, and is also the code reported
// to the executor. Only vmcommon.ExecutionFailed, vmcommon.UserError and
// vmcommon.OutOfGas are meaningful today.
//
// Never vmcommon.Ok, which is what leaves code 0 free to mean "legacy async call" on
// the wire.
Code vmcommon.ReturnCode

// Message is the VMOutput return message. For a user error this is the contract's own
// text, which is not the same as Cause.Error().
Message string

// ConsumeAllGas burns all remaining gas before the termination routine runs.
ConsumeAllGas bool

// Cause is the underlying error, used for the error trace and errors.Is.
Cause error
}

// Error implements the error interface.
func (e *EarlyExit) Error() string { return e.Message }

// Unwrap keeps errors.Is/errors.As working through an EarlyExit.
func (e *EarlyExit) Unwrap() error { return e.Cause }

// ExitExecutionFailed is the early exit for an error that does not describe one itself.
//
// This is the default the overwhelming majority of hook failures take, and the only place it
// is defined. The constructors for the two exits that deviate from it, ExitUserError and
// ExitOutOfGas, stay in the vmhost package with the sentinel errors they carry.
func ExitExecutionFailed(err error) *EarlyExit {
return &EarlyExit{
Code: defaultEarlyExitCode,
Message: err.Error(),
ConsumeAllGas: true,
Cause: err,
}
}
49 changes: 31 additions & 18 deletions executor/vmHooks.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions executor/vmHooksErrorHandler.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package executor

// VMHooksErrorHandler applies the side effects of an error returned by a VM hook.
//
// It is implemented by the VM, and called only by VMHooksLegacyAdapter, which is the one
// place that has an error it cannot return. It is deliberately not part of VMHooks: a hook
// that can report its error has no use for it.
//
// Counterpart of the Rust VMHooksSetEarlyExit, and like it, it lives next to the adapter
// rather than in a backend, because more than one caller adapts hooks this way.
type VMHooksErrorHandler interface {
// HandleHookError applies the failure side effects for err. It is a no-op
// when err is nil.
HandleHookError(err error)
}
Loading
Loading