@@ -135,7 +135,10 @@ type PrecompileEnvironment interface {
135
135
BlockNumber () * big.Int
136
136
BlockTime () uint64
137
137
138
- Call (common.Address , []byte , uint64 , * uint256.Int ) ([]byte , uint64 , error )
138
+ // Call is equivalent to [EVM.Call], with the caller defaulting to the
139
+ // precompile receiving the environment, or to its own caller if invoked via
140
+ // a delegated call.
141
+ Call (addr common.Address , input []byte , gas uint64 , value * uint256.Int , _ ... CallOption ) (ret []byte , gasRemaining uint64 , _ error )
139
142
}
140
143
141
144
var _ PrecompileEnvironment = (* evmCallArgs )(nil )
@@ -198,7 +201,7 @@ func (args *evmCallArgs) BlockNumber() *big.Int {
198
201
199
202
func (args * evmCallArgs ) BlockTime () uint64 { return args .evm .Context .Time }
200
203
201
- func (args * evmCallArgs ) Call (addr common.Address , input []byte , gas uint64 , value * uint256.Int ) ([]byte , uint64 , error ) {
204
+ func (args * evmCallArgs ) Call (addr common.Address , input []byte , gas uint64 , value * uint256.Int , opts ... CallOption ) ([]byte , uint64 , error ) {
202
205
in := args .evm .interpreter
203
206
204
207
// The precompile run didn't increment the depth so this is necessary even
@@ -220,7 +223,19 @@ func (args *evmCallArgs) Call(addr common.Address, input []byte, gas uint64, val
220
223
if args .delegation == delegated {
221
224
precompile = precompile .AsDelegate ()
222
225
}
223
- return args .evm .Call (precompile , addr , input , gas , value )
226
+ var caller ContractRef = precompile
227
+
228
+ for _ , o := range opts {
229
+ switch o := o .(type ) {
230
+ case withCallerOpt :
231
+ caller = o .ContractRef
232
+ case nil :
233
+ default :
234
+ return nil , gas , fmt .Errorf ("unsupported option %T" , o )
235
+ }
236
+ }
237
+
238
+ return args .evm .Call (caller , addr , input , gas , value )
224
239
}
225
240
226
241
var (
0 commit comments