File tree Expand file tree Collapse file tree 1 file changed +35
-0
lines changed Expand file tree Collapse file tree 1 file changed +35
-0
lines changed Original file line number Diff line number Diff line change 1+ package vm
2+
3+ import "github.com/ethereum/go-ethereum/params"
4+
5+ // RegisterHooks registers the Hooks. It is expected to be called in an `init()`
6+ // function and MUST NOT be called more than once.
7+ func RegisterHooks (h Hooks ) {
8+ if libevmHooks != nil {
9+ panic ("already registered" )
10+ }
11+ libevmHooks = h
12+ }
13+
14+ var libevmHooks Hooks
15+
16+ // Hooks are arbitrary configuration functions to modify default VM behaviour.
17+ type Hooks interface {
18+ // OverrideJumpTable will only be called if
19+ // [params.RulesHooks.OverrideJumpTable] returns true. This allows for
20+ // recursive calling into [LookupInstructionSet].
21+ OverrideJumpTable (params.Rules , * JumpTable ) * JumpTable
22+ }
23+
24+ // overrideJumpTable returns `libevmHooks.OverrideJumpTable(r,jt)“ i.f.f. the
25+ // Rules' hooks indicate that it must, otherwise it echoes `jt` unchanged.
26+ func overrideJumpTable (r params.Rules , jt * JumpTable ) * JumpTable {
27+ if ! r .Hooks ().OverrideJumpTable () {
28+ return jt
29+ }
30+ // We don't check that libevmHooks is non-nil because the user has clearly
31+ // signified that they want an override. A nil-pointer dereference will
32+ // occur in tests whereas graceful degradation would frustrate the user with
33+ // a hard-to-find bug.
34+ return libevmHooks .OverrideJumpTable (r , jt )
35+ }
You can’t perform that action at this time.
0 commit comments