@@ -45,11 +45,11 @@ type evmCallArgs struct {
4545 callType CallType
4646
4747 // args:start
48- caller ContractRef
49- addr common.Address
50- input []byte
51- gas uint64
52- value * uint256.Int
48+ caller ContractRef
49+ addr common.Address
50+ input []byte
51+ gasRemaining uint64
52+ value * uint256.Int
5353 // args:end
5454}
5555
@@ -89,16 +89,17 @@ func (t CallType) OpCode() OpCode {
8989}
9090
9191// run runs the [PrecompiledContract], differentiating between stateful and
92- // regular types.
93- func (args * evmCallArgs ) run (p PrecompiledContract , input []byte , suppliedGas uint64 ) (ret []byte , remainingGas uint64 , err error ) {
94- if p , ok := p .(statefulPrecompile ); ok {
95- // `suppliedGas` is already held by the args, and captured by `env()`.
96- return p .run (args .env (), input )
92+ // regular types, updating `gasRemaining` in the stateful case.
93+ func (args * evmCallArgs ) run (p PrecompiledContract , input []byte ) (ret []byte , err error ) {
94+ switch p := p .(type ) {
95+ default :
96+ return p .Run (input )
97+ case statefulPrecompile :
98+ env := args .env ()
99+ ret , err := p (env , input )
100+ args .gasRemaining = env .Gas ()
101+ return ret , err
97102 }
98- // Gas consumption for regular precompiles was already handled by the native
99- // RunPrecompiledContract(), which called this method.
100- ret , err = p .Run (input )
101- return ret , suppliedGas , err
102103}
103104
104105// PrecompiledStatefulContract is the stateful equivalent of a
@@ -123,11 +124,6 @@ func NewStatefulPrecompile(run PrecompiledStatefulContract) PrecompiledContract
123124// [PrecompiledStatefulContract] to hide implementation details.
124125type statefulPrecompile PrecompiledStatefulContract
125126
126- func (p statefulPrecompile ) run (env * environment , input []byte ) ([]byte , uint64 , error ) {
127- ret , err := p (env , input )
128- return ret , env .self .Gas , err
129- }
130-
131127// RequiredGas always returns zero as this gas is consumed by native geth code
132128// before the contract is run.
133129func (statefulPrecompile ) RequiredGas ([]byte ) uint64 { return 0 }
@@ -189,7 +185,7 @@ func (args *evmCallArgs) env() *environment {
189185
190186 // This is equivalent to the `contract` variables created by evm.*Call*()
191187 // methods, for non precompiles, to pass to [EVMInterpreter.Run].
192- contract := NewContract (args .caller , AccountRef (self ), value , args .gas )
188+ contract := NewContract (args .caller , AccountRef (self ), value , args .gasRemaining )
193189 if args .callType == DelegateCall {
194190 contract = contract .AsDelegate ()
195191 }
0 commit comments