Skip to content

Commit

Permalink
Make IBC precompile nonpayable (#2032)
Browse files Browse the repository at this point in the history
IBC precompile -> nonpayable

Co-authored-by: cordt-sei <165932662+cordt-sei@users.noreply.github.com>
  • Loading branch information
dssei and cordt-sei authored Jan 24, 2025
1 parent acf122d commit 2418932
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion precompiles/ibc/abi.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[{"inputs":[{"internalType":"string","name":"toAddress","type":"string"},{"internalType":"string","name":"port","type":"string"},{"internalType":"string","name":"channel","type":"string"},{"internalType":"string","name":"denom","type":"string"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint64","name":"revisionNumber","type":"uint64"},{"internalType":"uint64","name":"revisionHeight","type":"uint64"},{"internalType":"uint64","name":"timeoutTimestamp","type":"uint64"},{"internalType":"string","name":"memo","type":"string"}],"name":"transfer","outputs":[{"internalType":"bool","name":"success","type":"bool"}],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"string","name":"toAddress","type":"string"},{"internalType":"string","name":"port","type":"string"},{"internalType":"string","name":"channel","type":"string"},{"internalType":"string","name":"denom","type":"string"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"string","name":"memo","type":"string"}],"name":"transferWithDefaultTimeout","outputs":[{"internalType":"bool","name":"success","type":"bool"}],"stateMutability":"payable","type":"function"}]
[{"inputs":[{"internalType":"string","name":"toAddress","type":"string"},{"internalType":"string","name":"port","type":"string"},{"internalType":"string","name":"channel","type":"string"},{"internalType":"string","name":"denom","type":"string"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint64","name":"revisionNumber","type":"uint64"},{"internalType":"uint64","name":"revisionHeight","type":"uint64"},{"internalType":"uint64","name":"timeoutTimestamp","type":"uint64"},{"internalType":"string","name":"memo","type":"string"}],"name":"transfer","outputs":[{"internalType":"bool","name":"success","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"string","name":"toAddress","type":"string"},{"internalType":"string","name":"port","type":"string"},{"internalType":"string","name":"channel","type":"string"},{"internalType":"string","name":"denom","type":"string"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"string","name":"memo","type":"string"}],"name":"transferWithDefaultTimeout","outputs":[{"internalType":"bool","name":"success","type":"bool"}],"stateMutability":"nonpayable","type":"function"}]
4 changes: 4 additions & 0 deletions precompiles/ibc/ibc.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ func NewPrecompile(
}

func (p PrecompileExecutor) Execute(ctx sdk.Context, method *abi.Method, caller common.Address, callingContract common.Address, args []interface{}, value *big.Int, readOnly bool, evm *vm.EVM, suppliedGas uint64) (ret []byte, remainingGas uint64, err error) {
if err = pcommon.ValidateNonPayable(value); err != nil {
return nil, 0, err
}

if readOnly {
return nil, 0, errors.New("cannot call IBC precompile from staticcall")
}
Expand Down
16 changes: 16 additions & 0 deletions precompiles/ibc/ibc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,14 @@ func TestPrecompile_Run(t *testing.T) {
wantErr: true,
wantErrMsg: "cannot delegatecall IBC",
},
{
name: "failed transfer: value is not nil",
fields: fields{transferKeeper: &MockTransferKeeper{}},
args: args{caller: senderEvmAddress, callingContract: common.Address{}, input: commonArgs.input, suppliedGas: 1000000, value: big.NewInt(100), isFromDelegateCall: true},
wantBz: nil,
wantErr: true,
wantErrMsg: "sending funds to a non-payable function",
},
{
name: "failed transfer: empty sourcePort",
fields: fields{transferKeeper: &MockTransferKeeper{}},
Expand Down Expand Up @@ -357,6 +365,14 @@ func TestTransferWithDefaultTimeoutPrecompile_Run(t *testing.T) {
wantErr: true,
wantErrMsg: "cannot delegatecall IBC",
},
{
name: "failed transfer: value is not nil",
fields: fields{transferKeeper: &MockTransferKeeper{}},
args: args{caller: senderEvmAddress, callingContract: common.Address{}, input: commonArgs.input, suppliedGas: 1000000, value: big.NewInt(100), isFromDelegateCall: true},
wantBz: nil,
wantErr: true,
wantErrMsg: "sending funds to a non-payable function",
},
{
name: "failed transfer: empty sourcePort",
fields: fields{transferKeeper: &MockTransferKeeper{}},
Expand Down

0 comments on commit 2418932

Please sign in to comment.