Skip to content

Commit 584fa5f

Browse files
committed
refactor: WithUNSAFEForceDelegate() replaces WithCaller()
1 parent c63b031 commit 584fa5f

File tree

2 files changed

+18
-14
lines changed

2 files changed

+18
-14
lines changed

core/vm/contracts.libevm.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -220,22 +220,23 @@ func (args *evmCallArgs) Call(addr common.Address, input []byte, gas uint64, val
220220
// methods to pass to [EVMInterpreter.Run], which are then propagated by the
221221
// *CALL* opcodes as the caller.
222222
precompile := NewContract(args.caller, AccountRef(args.self()), args.value, args.gas)
223-
if args.delegation == delegated {
224-
precompile = precompile.AsDelegate()
225-
}
226-
var caller ContractRef = precompile
227223

224+
asDelegate := args.delegation == delegated // precompile was DELEGATECALLed
228225
for _, o := range opts {
229226
switch o := o.(type) {
230-
case withCallerOpt:
231-
caller = o.ContractRef
227+
case callOptForceDelegate:
228+
// See documentation of [WithUNSAFEForceDelegate].
229+
asDelegate = true
232230
case nil:
233231
default:
234232
return nil, gas, fmt.Errorf("unsupported option %T", o)
235233
}
236234
}
235+
if asDelegate {
236+
precompile = precompile.AsDelegate()
237+
}
237238

238-
return args.evm.Call(caller, addr, input, gas, value)
239+
return args.evm.Call(precompile, addr, input, gas, value)
239240
}
240241

241242
var (

core/vm/options.libevm.go

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,16 @@ type CallOption interface {
2121
libevmCallOption() // noop to only allow internally defined options
2222
}
2323

24-
// WithCaller overrides the default caller.
25-
func WithCaller(c ContractRef) CallOption {
26-
return withCallerOpt{c}
24+
// WithUNSAFEForceDelegate results in precompiles making contract calls acting
25+
// as if they themselves were DELEGATECALLed. This is not safe for regular use
26+
// as the precompile will act as its own caller even when not expected to.
27+
//
28+
// Deprecated: this option MUST NOT be used other than to allow migration to
29+
// libevm when backwards compatibility is required.
30+
func WithUNSAFEForceDelegate() CallOption {
31+
return callOptForceDelegate{}
2732
}
2833

29-
type withCallerOpt struct {
30-
ContractRef
31-
}
34+
type callOptForceDelegate struct{}
3235

33-
func (withCallerOpt) libevmCallOption() {}
36+
func (callOptForceDelegate) libevmCallOption() {}

0 commit comments

Comments
 (0)