-
Notifications
You must be signed in to change notification settings - Fork 14
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
refactor: skip 'from' account verification during contract query #787
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ package keeper | |
|
||
import ( | ||
"bytes" | ||
"context" | ||
"encoding/hex" | ||
"math/big" | ||
|
||
|
@@ -79,7 +80,7 @@ func (k *Keeper) DeployContract(ctx sdk.Context, from common.Address, abi abi.AB | |
return common.Address{}, err | ||
} | ||
|
||
_, err = k.CallEVMWithoutGas(ctx, from, nil, nil, data, true) | ||
_, err = k.callEvm(ctx, from, nil, nil, nonce, data, true) | ||
if err != nil { | ||
return common.Address{}, err | ||
} | ||
|
@@ -110,12 +111,12 @@ func (k *Keeper) DeployUpgradableContract(ctx sdk.Context, from, logic common.Ad | |
} | ||
|
||
// QueryContract query contract with args and res | ||
func (k *Keeper) QueryContract(ctx sdk.Context, from, contract common.Address, abi abi.ABI, method string, res interface{}, args ...interface{}) error { | ||
func (k *Keeper) QueryContract(ctx context.Context, from, contract common.Address, abi abi.ABI, method string, res interface{}, args ...interface{}) error { | ||
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. 💡 Codebase verification Inconsistent context type usage detected in the codebase The codebase shows mixed usage of context types:
These related contract operation methods should be updated to maintain consistency in context handling. 🔗 Analysis chainVerify consistent context type usage across the codebase Let's ensure all related methods have been updated to use context.Context consistently. Also applies to: 130-130 Let me gather more information to verify the context usage more thoroughly. 🏁 Scripts executedThe following scripts were executed for the analysis: Script: #!/bin/bash
# Description: Check for any remaining sdk.Context usage in related methods
# Test: Look for method signatures that might still be using sdk.Context
rg -A 1 "func.*QueryContract|func.*ApplyContract"
Length of output: 624 Script: #!/bin/bash
# Search for any remaining sdk.Context usage in the x/evm directory
rg "sdk\.Context" x/evm/
# Also check for any method signatures containing Context
ast-grep --pattern 'func $_($_Context$_, $$$) $$$'
Length of output: 1816 |
||
data, err := abi.Pack(method, args...) | ||
if err != nil { | ||
return types.ErrABIPack.Wrap(err.Error()) | ||
} | ||
resp, err := k.CallEVMWithoutGas(ctx, from, &contract, nil, data, false) | ||
resp, err := k.callEvm(sdk.UnwrapSDKContext(ctx), from, &contract, nil, 0, data, false) | ||
if err != nil { | ||
return err | ||
} | ||
|
@@ -126,12 +127,16 @@ func (k *Keeper) QueryContract(ctx sdk.Context, from, contract common.Address, a | |
} | ||
|
||
// ApplyContract apply contract with args | ||
func (k *Keeper) ApplyContract(ctx sdk.Context, from, contract common.Address, value *big.Int, abi abi.ABI, method string, constructorData ...interface{}) (*evmtypes.MsgEthereumTxResponse, error) { | ||
func (k *Keeper) ApplyContract(ctx context.Context, from, contract common.Address, value *big.Int, abi abi.ABI, method string, constructorData ...interface{}) (*evmtypes.MsgEthereumTxResponse, error) { | ||
args, err := abi.Pack(method, constructorData...) | ||
if err != nil { | ||
return nil, types.ErrABIPack.Wrap(err.Error()) | ||
} | ||
resp, err := k.CallEVMWithoutGas(ctx, from, &contract, value, args, true) | ||
nonce, err := k.accountKeeper.GetSequence(ctx, from.Bytes()) | ||
if err != nil { | ||
return nil, err | ||
} | ||
resp, err := k.callEvm(sdk.UnwrapSDKContext(ctx), from, &contract, value, nonce, args, true) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -80,7 +80,7 @@ func (s *EVMSuite) Call(abi abi.ABI, method string, res interface{}, args ...int | |
} | ||
|
||
func (s *EVMSuite) CallEVM(data []byte, gasLimit uint64) *evmtypes.MsgEthereumTxResponse { | ||
tx, err := s.evmKeeper.CallEVM(s.ctx, s.GetFrom(), &s.contractAddr, nil, gasLimit, data, false) | ||
tx, err := s.evmKeeper.ExecuteEVM(s.ctx, s.GetFrom(), &s.contractAddr, nil, gasLimit, data) | ||
s.NoError(err) | ||
return tx | ||
Comment on lines
+83
to
85
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. 💡 Codebase verification Update required: Several files still use the deprecated
The change in the reviewed file is incomplete as it introduces inconsistency by using 🔗 Analysis chainLGTM! Verify test coverage. The change from Let's verify the test coverage and usage of this method: 🏁 Scripts executedThe following scripts were executed for the analysis: Script: #!/bin/bash
# Description: Check for any test files that might still be using the old CallEVM method name
# or might need updates due to this change
# Search for test files using EVMSuite
rg -t go "EVMSuite" --files-with-matches
# Search for any remaining references to CallEVM that might need updating
rg -t go "CallEVM" -C 3
Length of output: 5431 |
||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,8 +45,8 @@ func (k Keeper) HandlerIbcCallEvm(ctx sdk.Context, sender common.Address, evmPac | |
} | ||
ctx.EventManager().EmitEvent(sdk.NewEvent(types.EventTypeIBCCall, attrs...)) | ||
}() | ||
txResp, err := k.evmKeeper.CallEVM(ctx, sender, | ||
evmPacket.GetToAddress(), evmPacket.Value.BigInt(), uint64(limit), evmPacket.MustGetData(), true) | ||
txResp, err := k.evmKeeper.ExecuteEVM(ctx, sender, | ||
evmPacket.GetToAddress(), evmPacket.Value.BigInt(), uint64(limit), evmPacket.MustGetData()) | ||
Comment on lines
+48
to
+49
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. 💡 Codebase verification Change from The verification revealed that:
Recommendations:
🔗 Analysis chainMethod call updated from The change aligns with the broader refactoring effort. Let's verify the consistency of this change across the codebase. Remaining references to The verification revealed inconsistencies in the codebase:
Let's verify if these are intentionally different methods or oversight: Let's check one more aspect to understand the complete picture: 🏁 Scripts executedThe following scripts were executed for the analysis: Script: #!/bin/bash
# Description: Verify that CallEVM is completely replaced with ExecuteEVM
# and there are no lingering references to the old method name.
echo "Checking for any remaining references to CallEVM..."
rg "CallEVM" --type go
echo "Verifying the new ExecuteEVM method signature in the EVM keeper interface..."
ast-grep --pattern 'interface {
$$$
ExecuteEVM($$$)
$$$
}'
Length of output: 2370 Script: #!/bin/bash
# Check the implementation and signature of CallEVMWithoutGas
ast-grep --pattern 'func $_ CallEVMWithoutGas($_) $_$ {
$$$
}'
# Check if ExecuteEVM is called within CallEVMWithoutGas (might be a wrapper)
echo "Checking relationship between CallEVMWithoutGas and ExecuteEVM..."
rg -A 5 "CallEVMWithoutGas" x/evm/keeper/keeper.go
Length of output: 392 Script: #!/bin/bash
# Get more context around CallEVMWithoutGas implementation
rg -B 2 -A 15 "func \(k \*Keeper\) CallEVMWithoutGas" x/evm/keeper/keeper.go
# Check if there are any direct ExecuteEVM calls in test files
echo "Checking ExecuteEVM usage in tests..."
rg "ExecuteEVM" --type go -g "*_test.go"
Length of output: 643 |
||
if err != nil { | ||
evmErrCause = err.Error() | ||
return err | ||
|
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.
💡 Codebase verification
Context type change requires attention in implementation
The implementation in
x/evm/keeper/contract_code.go
still usessdk.UnwrapSDKContext(ctx)
in theQueryContract
method, which indicates a potential issue with the context type change. This suggests that while the interface has been updated to usecontext.Context
, the implementation still relies on SDK context functionality.x/evm/keeper/contract_code.go
: TheQueryContract
implementation needs to be reviewed as it's converting the context back to SDK context:sdk.UnwrapSDKContext(ctx)
🔗 Analysis chain
Verify the impact of context type change.
The change from
sdk.Context
tocontext.Context
looks good and aligns with the PR objective. However, we should ensure that all implementations of this interface have been updated accordingly.🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
Length of output: 144
Script:
Length of output: 17379