-
Notifications
You must be signed in to change notification settings - Fork 195
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(evm): consume gas in CallContractWithInput #2180
Changes from 9 commits
efcfde1
1cb2068
9947330
53c1500
be10743
60f3b5c
7387a40
4850501
52f3293
a55e5b2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,7 +39,7 @@ func (k Keeper) CallContractWithInput( | |
) (evmResp *evm.MsgEthereumTxResponse, err error) { | ||
// This is a `defer` pattern to add behavior that runs in the case that the | ||
// error is non-nil, creating a concise way to add extra information. | ||
defer HandleOutOfGasPanic(&err, "CallContractError") | ||
defer HandleOutOfGasPanic(&err, "CallContractError")() | ||
nonce := k.GetAccNonce(ctx, fromAcc) | ||
|
||
unusedBigInt := big.NewInt(0) | ||
|
@@ -61,11 +61,13 @@ func (k Keeper) CallContractWithInput( | |
// sent by a user | ||
txConfig := k.TxConfig(ctx, gethcommon.BigToHash(big.NewInt(0))) | ||
evmResp, err = k.ApplyEvmMsg( | ||
ctx, evmMsg, evmObj, evm.NewNoOpTracer(), commit, txConfig.TxHash, true, | ||
ctx, evmMsg, evmObj, evm.NewNoOpTracer(), commit, txConfig.TxHash, | ||
) | ||
if evmResp != nil { | ||
ctx.GasMeter().ConsumeGas(evmResp.GasUsed, "CallContractWithInput") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should always consume gas after |
||
} | ||
if err != nil { | ||
err = errors.Wrap(err, "failed to apply ethereum core message") | ||
return | ||
return nil, errors.Wrap(err, "failed to apply ethereum core message") | ||
} | ||
|
||
if evmResp.Failed() { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -196,7 +196,7 @@ func (e erc20Calls) loadERC20String( | |
if err != nil { | ||
return out, err | ||
} | ||
res, err := e.Keeper.CallContractWithInput( | ||
evmResp, err := e.Keeper.CallContractWithInput( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. just a minor rename |
||
ctx, | ||
evmObj, | ||
evm.EVM_MODULE_ADDRESS, | ||
|
@@ -211,13 +211,13 @@ func (e erc20Calls) loadERC20String( | |
|
||
erc20Val := new(ERC20String) | ||
if err := erc20Abi.UnpackIntoInterface( | ||
erc20Val, methodName, res.Ret, | ||
erc20Val, methodName, evmResp.Ret, | ||
); err == nil { | ||
return erc20Val.Value, err | ||
} | ||
|
||
erc20Bytes32Val := new(ERC20Bytes32) | ||
if err := erc20Abi.UnpackIntoInterface(erc20Bytes32Val, methodName, res.Ret); err == nil { | ||
if err := erc20Abi.UnpackIntoInterface(erc20Bytes32Val, methodName, evmResp.Ret); err == nil { | ||
return bytes32ToString(erc20Bytes32Val.Value), nil | ||
} | ||
|
||
|
@@ -239,7 +239,7 @@ func (e erc20Calls) loadERC20Uint8( | |
if err != nil { | ||
return out, err | ||
} | ||
res, err := e.Keeper.CallContractWithInput( | ||
evmResp, err := e.Keeper.CallContractWithInput( | ||
ctx, | ||
evmObj, | ||
evm.EVM_MODULE_ADDRESS, | ||
|
@@ -254,14 +254,14 @@ func (e erc20Calls) loadERC20Uint8( | |
|
||
erc20Val := new(ERC20Uint8) | ||
if err := erc20Abi.UnpackIntoInterface( | ||
erc20Val, methodName, res.Ret, | ||
erc20Val, methodName, evmResp.Ret, | ||
); err == nil { | ||
return erc20Val.Value, err | ||
} | ||
|
||
erc20Uint256Val := new(ERC20BigInt) | ||
if err := erc20Abi.UnpackIntoInterface( | ||
erc20Uint256Val, methodName, res.Ret, | ||
erc20Uint256Val, methodName, evmResp.Ret, | ||
); err == nil { | ||
// We can safely cast to uint8 because it's nonsense for decimals to be larger than 255 | ||
return uint8(erc20Uint256Val.Value.Uint64()), err | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -102,7 +102,7 @@ func (k *Keeper) deployERC20ForBankCoin( | |
k.Bank.StateDB = nil | ||
}() | ||
evmObj := k.NewEVM(ctx, evmMsg, evmCfg, nil /*tracer*/, stateDB) | ||
evmResp, err := k.CallContractWithInput( | ||
_, err = k.CallContractWithInput( | ||
ctx, evmObj, evm.EVM_MODULE_ADDRESS, nil, true /*commit*/, input, Erc20GasLimitDeploy, | ||
) | ||
if err != nil { | ||
|
@@ -114,7 +114,5 @@ func (k *Keeper) deployERC20ForBankCoin( | |
return gethcommon.Address{}, errors.Wrap(err, "failed to commit stateDB") | ||
} | ||
|
||
ctx.GasMeter().ConsumeGas(evmResp.GasUsed, "deploy erc20 funtoken contract") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We no longer need to consume gas here since we consume it at a lower level in |
||
|
||
return erc20Addr, nil | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missing parentheses was causing issues with catching OOG errors lol