From dea4cdc4c1a28524b9be9a0fd9f96d8fd5907196 Mon Sep 17 00:00:00 2001 From: Unique Divine <51418232+Unique-Divine@users.noreply.github.com> Date: Thu, 22 Aug 2024 10:45:54 -0500 Subject: [PATCH] chore(evm): Set appropriate gas value for the required gas of the "IFunToken.sol" precompile. (#2013) * chore(evm): Set appropriate gas value for the required gas of the "IFunToken.sol" precompile. * typo --- CHANGELOG.md | 1 + x/evm/precompile/funtoken.go | 16 ++++++++++------ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f6f536f43..b4103476e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -108,6 +108,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - [#2003](https://github.com/NibiruChain/nibiru/pull/2003) - fix(evm): fix FunToken conversions between Cosmos and EVM - [#2004](https://github.com/NibiruChain/nibiru/pull/2004) - refactor(evm)!: replace `HexAddr` with `EIP55Addr` - [#2008](https://github.com/NibiruChain/nibiru/pull/2008) - refactor(evm): clean up precompile setups +- [#2013](https://github.com/NibiruChain/nibiru/pull/2013) - chore(evm): Set appropriate gas value for the required gas of the "IFunToken.sol" precompile. #### Dapp modules: perp, spot, oracle, etc diff --git a/x/evm/precompile/funtoken.go b/x/evm/precompile/funtoken.go index 4e1f131cd..365cac8e1 100644 --- a/x/evm/precompile/funtoken.go +++ b/x/evm/precompile/funtoken.go @@ -12,6 +12,7 @@ import ( gethabi "github.com/ethereum/go-ethereum/accounts/abi" gethcommon "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/vm" + gethparams "github.com/ethereum/go-ethereum/params" "github.com/NibiruChain/nibiru/v2/app/keepers" "github.com/NibiruChain/nibiru/v2/x/evm" @@ -32,12 +33,15 @@ func (p precompileFunToken) Address() gethcommon.Address { } func (p precompileFunToken) RequiredGas(input []byte) (gasPrice uint64) { - // TODO: https://github.com/NibiruChain/nibiru/issues/1990 - // We need to determine an appropriate gas value for the transaction to - // configure this function and add a assertions around the gas usage to - // the precompile's test suite. UD-DEBUG: not implemented yet. Currently - // set to 0 gasPrice - return 22 + // Since [gethparams.TxGas] is the cost per (Ethereum) transaction that does not create + // a contract, it's value can be used to derive an appropriate value for the + // precompile call. The FunToken precompile performs 3 operations, labeld 1-3 + // below: + // 0 | Call the precompile (already counted in gas calculation) + // 1 | Send ERC20 to EVM. + // 2 | Convert ERC20 to coin + // 3 | Send coin to recipient. + return gethparams.TxGas * 3 } const (