Skip to content

Commit

Permalink
Do not return remaining gas
Browse files Browse the repository at this point in the history
  • Loading branch information
qdm12 committed Feb 19, 2025
1 parent 71a0837 commit 6267f42
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 12 deletions.
2 changes: 1 addition & 1 deletion nativeasset/contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ func (c *NativeAssetCall) Run(accessibleState contract.AccessibleState, caller c
stateDB.SubBalanceMultiCoin(caller, assetID, assetAmount)
stateDB.AddBalanceMultiCoin(to, assetID, assetAmount)

ret, remainingGas, err = accessibleState.Call(to, callData, remainingGas, new(uint256.Int), vm.WithUNSAFECallerAddressProxying())
ret, err = accessibleState.Call(to, callData, remainingGas, new(uint256.Int), vm.WithUNSAFECallerAddressProxying())

// When an error was returned by the EVM or when setting the creation code
// above we revert to the snapshot and consume any gas remaining. Additionally
Expand Down
9 changes: 3 additions & 6 deletions params/hooks_libevm.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,17 +172,14 @@ func (a accessableState) GetSnowContext() *snow.Context {
return GetExtra(a.env.ChainConfig()).SnowCtx
}

func (a accessableState) Call(addr common.Address, input []byte, gas uint64, value *uint256.Int, opts ...vm.CallOption) (ret []byte, gasRemaining uint64, err error) {
func (a accessableState) Call(addr common.Address, input []byte, gas uint64, value *uint256.Int, opts ...vm.CallOption) (ret []byte, err error) {
start := a.env.Gas()
ret, err = a.env.Call(addr, input, gas, value, opts...)
used := start - a.env.Gas()
if used > gas {
return ret, 0, vm.ErrOutOfGas
return ret, vm.ErrOutOfGas
}
// `gasRemaining` is `gas` because [vm.PrecompileEnvironment]'s `Call` method
// should consume the gas from the environment directly
gasRemaining = gas
return ret, gasRemaining, err
return ret, err
}

type precompileBlockContext struct {
Expand Down
2 changes: 1 addition & 1 deletion precompile/contract/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ type AccessibleState interface {
GetBlockContext() BlockContext
GetSnowContext() *snow.Context
GetChainConfig() precompileconfig.ChainConfig
Call(addr common.Address, input []byte, gas uint64, value *uint256.Int, opts ...vm.CallOption) (ret []byte, gasRemaining uint64, _ error)
Call(addr common.Address, input []byte, gas uint64, value *uint256.Int, opts ...vm.CallOption) (ret []byte, _ error)
}

// ConfigurationBlockContext defines the interface required to configure a precompile.
Expand Down
7 changes: 3 additions & 4 deletions precompile/contract/mocks.go

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

0 comments on commit 6267f42

Please sign in to comment.