Skip to content
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: support accesslist type tx and handle rpc transaction #73

Merged
merged 10 commits into from
Oct 21, 2024
16 changes: 8 additions & 8 deletions app/ibc-hooks/ack_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func Test_onAckIcs20Packet_memo(t *testing.T) {
codeBz, err := hexutil.Decode(counter.CounterBin)
require.NoError(t, err)

_, contractAddr, _, err := input.EVMKeeper.EVMCreate(ctx, evmAddr, codeBz, nil)
_, contractAddr, _, err := input.EVMKeeper.EVMCreate(ctx, evmAddr, codeBz, nil, nil)
require.NoError(t, err)

abi, err := counter.CounterMetaData.GetAbi()
Expand Down Expand Up @@ -87,7 +87,7 @@ func Test_onAckIcs20Packet_memo(t *testing.T) {
// check the contract state
queryInputBz, err := abi.Pack("count")
require.NoError(t, err)
queryRes, logs, err := input.EVMKeeper.EVMCall(ctx, evmAddr, contractAddr, queryInputBz, nil)
queryRes, logs, err := input.EVMKeeper.EVMCall(ctx, evmAddr, contractAddr, queryInputBz, nil, nil)
require.NoError(t, err)
require.Equal(t, uint256.NewInt(0).Bytes32(), [32]byte(queryRes))
require.Empty(t, logs)
Expand All @@ -102,7 +102,7 @@ func Test_onAckIcs20Packet_memo(t *testing.T) {
require.NoError(t, err)

// check the contract state; increased by 99 if ack is success
queryRes, logs, err = input.EVMKeeper.EVMCall(ctx, evmAddr, contractAddr, queryInputBz, nil)
queryRes, logs, err = input.EVMKeeper.EVMCall(ctx, evmAddr, contractAddr, queryInputBz, nil, nil)
require.NoError(t, err)
require.Equal(t, uint256.NewInt(99).Bytes32(), [32]byte(queryRes))
require.Empty(t, logs)
Expand All @@ -114,7 +114,7 @@ func Test_onAckIcs20Packet_memo(t *testing.T) {
require.NoError(t, err)

// check the contract state; increased by 1 if ack is failed
queryRes, logs, err = input.EVMKeeper.EVMCall(ctx, evmAddr, contractAddr, queryInputBz, nil)
queryRes, logs, err = input.EVMKeeper.EVMCall(ctx, evmAddr, contractAddr, queryInputBz, nil, nil)
require.NoError(t, err)
require.Equal(t, uint256.NewInt(100).Bytes32(), [32]byte(queryRes))
require.Empty(t, logs)
Expand Down Expand Up @@ -157,7 +157,7 @@ func Test_onAckPacket_memo_ICS721(t *testing.T) {
codeBz, err := hexutil.Decode(counter.CounterBin)
require.NoError(t, err)

_, contractAddr, _, err := input.EVMKeeper.EVMCreate(ctx, evmAddr, codeBz, nil)
_, contractAddr, _, err := input.EVMKeeper.EVMCreate(ctx, evmAddr, codeBz, nil, nil)
require.NoError(t, err)

abi, err := counter.CounterMetaData.GetAbi()
Expand Down Expand Up @@ -197,7 +197,7 @@ func Test_onAckPacket_memo_ICS721(t *testing.T) {
// check the contract state
queryInputBz, err := abi.Pack("count")
require.NoError(t, err)
queryRes, logs, err := input.EVMKeeper.EVMCall(ctx, evmAddr, contractAddr, queryInputBz, nil)
queryRes, logs, err := input.EVMKeeper.EVMCall(ctx, evmAddr, contractAddr, queryInputBz, nil, nil)
require.NoError(t, err)
require.Equal(t, uint256.NewInt(0).Bytes32(), [32]byte(queryRes))
require.Empty(t, logs)
Expand All @@ -212,7 +212,7 @@ func Test_onAckPacket_memo_ICS721(t *testing.T) {
require.NoError(t, err)

// check the contract state; increased by 99 if ack is success
queryRes, logs, err = input.EVMKeeper.EVMCall(ctx, evmAddr, contractAddr, queryInputBz, nil)
queryRes, logs, err = input.EVMKeeper.EVMCall(ctx, evmAddr, contractAddr, queryInputBz, nil, nil)
require.NoError(t, err)
require.Equal(t, uint256.NewInt(99).Bytes32(), [32]byte(queryRes))
require.Empty(t, logs)
Expand All @@ -224,7 +224,7 @@ func Test_onAckPacket_memo_ICS721(t *testing.T) {
require.NoError(t, err)

// check the contract state; increased by 1 if ack is failed
queryRes, logs, err = input.EVMKeeper.EVMCall(ctx, evmAddr, contractAddr, queryInputBz, nil)
queryRes, logs, err = input.EVMKeeper.EVMCall(ctx, evmAddr, contractAddr, queryInputBz, nil, nil)
require.NoError(t, err)
require.Equal(t, uint256.NewInt(100).Bytes32(), [32]byte(queryRes))
require.Empty(t, logs)
Expand Down
18 changes: 9 additions & 9 deletions app/ibc-hooks/receive_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func Test_onReceiveIcs20Packet_memo(t *testing.T) {
codeBz, err := hexutil.Decode(counter.CounterBin)
require.NoError(t, err)

_, contractAddr, _, err := input.EVMKeeper.EVMCreate(ctx, evmAddr, codeBz, nil)
_, contractAddr, _, err := input.EVMKeeper.EVMCreate(ctx, evmAddr, codeBz, nil, nil)
require.NoError(t, err)

abi, err := counter.CounterMetaData.GetAbi()
Expand Down Expand Up @@ -105,7 +105,7 @@ func Test_onReceiveIcs20Packet_memo(t *testing.T) {
require.NoError(t, err)

// check the contract state
queryRes, err := input.EVMKeeper.EVMStaticCall(ctx, evmAddr, contractAddr, queryInputBz)
queryRes, err := input.EVMKeeper.EVMStaticCall(ctx, evmAddr, contractAddr, queryInputBz, nil)
require.NoError(t, err)
require.Equal(t, uint256.NewInt(1).Bytes32(), [32]byte(queryRes))

Expand All @@ -114,7 +114,7 @@ func Test_onReceiveIcs20Packet_memo(t *testing.T) {
require.NoError(t, err)
queryInputBz, err = input.EVMKeeper.ERC20Keeper().GetERC20ABI().Pack("allowance", common.BytesToAddress(intermediateSender.Bytes()), contractAddr)
require.NoError(t, err)
queryRes, err = input.EVMKeeper.EVMStaticCall(ctx, evmtypes.StdAddress, erc20Addr, queryInputBz)
queryRes, err = input.EVMKeeper.EVMStaticCall(ctx, evmtypes.StdAddress, erc20Addr, queryInputBz, nil)
require.NoError(t, err)
require.Equal(t, uint256.NewInt(10000).Bytes32(), [32]byte(queryRes))
}
Expand Down Expand Up @@ -155,7 +155,7 @@ func Test_onReceivePacket_memo_ICS721(t *testing.T) {
codeBz, err := hexutil.Decode(counter.CounterBin)
require.NoError(t, err)

_, contractAddr, _, err := input.EVMKeeper.EVMCreate(ctx, evmAddr, codeBz, nil)
_, contractAddr, _, err := input.EVMKeeper.EVMCreate(ctx, evmAddr, codeBz, nil, nil)
require.NoError(t, err)

abi, err := counter.CounterMetaData.GetAbi()
Expand Down Expand Up @@ -222,7 +222,7 @@ func Test_onReceivePacket_memo_ICS721(t *testing.T) {
require.NoError(t, err)

// check the contract state
queryRes, logs, err := input.EVMKeeper.EVMCall(ctx, evmAddr, contractAddr, queryInputBz, nil)
queryRes, logs, err := input.EVMKeeper.EVMCall(ctx, evmAddr, contractAddr, queryInputBz, nil, nil)
require.NoError(t, err)
require.Equal(t, uint256.NewInt(1).Bytes32(), [32]byte(queryRes))
require.Empty(t, logs)
Expand All @@ -234,7 +234,7 @@ func Test_onReceivePacket_memo_ICS721(t *testing.T) {
require.NoError(t, err)
queryInputBz, err = input.EVMKeeper.ERC721Keeper().GetERC721ABI().Pack("getApproved", tokenId)
require.NoError(t, err)
queryRes, err = input.EVMKeeper.EVMStaticCall(ctx, evmtypes.StdAddress, erc721Addr, queryInputBz)
queryRes, err = input.EVMKeeper.EVMStaticCall(ctx, evmtypes.StdAddress, erc721Addr, queryInputBz, nil)
require.NoError(t, err)
require.Equal(t, contractAddr.Bytes(), common.HexToAddress(hexutil.Encode(queryRes)).Bytes())
}
Expand All @@ -248,7 +248,7 @@ func Test_onReceivePacket_memo_ICS721_Wasm(t *testing.T) {
codeBz, err := hexutil.Decode(counter.CounterBin)
require.NoError(t, err)

_, contractAddr, _, err := input.EVMKeeper.EVMCreate(ctx, evmAddr, codeBz, nil)
_, contractAddr, _, err := input.EVMKeeper.EVMCreate(ctx, evmAddr, codeBz, nil, nil)
require.NoError(t, err)

abi, err := counter.CounterMetaData.GetAbi()
Expand Down Expand Up @@ -316,7 +316,7 @@ func Test_onReceivePacket_memo_ICS721_Wasm(t *testing.T) {
require.NoError(t, err)

// check the contract state
queryRes, logs, err := input.EVMKeeper.EVMCall(ctx, evmAddr, contractAddr, queryInputBz, nil)
queryRes, logs, err := input.EVMKeeper.EVMCall(ctx, evmAddr, contractAddr, queryInputBz, nil, nil)
require.NoError(t, err)
require.Equal(t, uint256.NewInt(1).Bytes32(), [32]byte(queryRes))
require.Empty(t, logs)
Expand All @@ -328,7 +328,7 @@ func Test_onReceivePacket_memo_ICS721_Wasm(t *testing.T) {
require.NoError(t, err)
queryInputBz, err = input.EVMKeeper.ERC721Keeper().GetERC721ABI().Pack("getApproved", tokenId)
require.NoError(t, err)
queryRes, err = input.EVMKeeper.EVMStaticCall(ctx, evmtypes.StdAddress, erc721Addr, queryInputBz)
queryRes, err = input.EVMKeeper.EVMStaticCall(ctx, evmtypes.StdAddress, erc721Addr, queryInputBz, nil)
require.NoError(t, err)
require.Equal(t, contractAddr.Bytes(), common.HexToAddress(hexutil.Encode(queryRes)).Bytes())
}
12 changes: 6 additions & 6 deletions app/ibc-hooks/timeout_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func Test_onTimeoutIcs20Packet_memo(t *testing.T) {
codeBz, err := hexutil.Decode(counter.CounterBin)
require.NoError(t, err)

_, contractAddr, _, err := input.EVMKeeper.EVMCreate(ctx, evmAddr, codeBz, nil)
_, contractAddr, _, err := input.EVMKeeper.EVMCreate(ctx, evmAddr, codeBz, nil, nil)
require.NoError(t, err)

abi, err := counter.CounterMetaData.GetAbi()
Expand Down Expand Up @@ -81,7 +81,7 @@ func Test_onTimeoutIcs20Packet_memo(t *testing.T) {
// check the contract state
queryInputBz, err := abi.Pack("count")
require.NoError(t, err)
queryRes, logs, err := input.EVMKeeper.EVMCall(ctx, evmAddr, contractAddr, queryInputBz, nil)
queryRes, logs, err := input.EVMKeeper.EVMCall(ctx, evmAddr, contractAddr, queryInputBz, nil, nil)
require.NoError(t, err)
require.Equal(t, uint256.NewInt(0).Bytes32(), [32]byte(queryRes))
require.Empty(t, logs)
Expand All @@ -96,7 +96,7 @@ func Test_onTimeoutIcs20Packet_memo(t *testing.T) {
require.NoError(t, err)

// check the contract state; increased by 99
queryRes, logs, err = input.EVMKeeper.EVMCall(ctx, evmAddr, contractAddr, queryInputBz, nil)
queryRes, logs, err = input.EVMKeeper.EVMCall(ctx, evmAddr, contractAddr, queryInputBz, nil, nil)
require.NoError(t, err)
require.Equal(t, uint256.NewInt(99).Bytes32(), [32]byte(queryRes))
require.Empty(t, logs)
Expand Down Expand Up @@ -136,7 +136,7 @@ func Test_onTimeoutPacket_memo_ICS721(t *testing.T) {
codeBz, err := hexutil.Decode(counter.CounterBin)
require.NoError(t, err)

_, contractAddr, _, err := input.EVMKeeper.EVMCreate(ctx, evmAddr, codeBz, nil)
_, contractAddr, _, err := input.EVMKeeper.EVMCreate(ctx, evmAddr, codeBz, nil, nil)
require.NoError(t, err)

abi, err := counter.CounterMetaData.GetAbi()
Expand Down Expand Up @@ -169,7 +169,7 @@ func Test_onTimeoutPacket_memo_ICS721(t *testing.T) {
// check the contract state
queryInputBz, err := abi.Pack("count")
require.NoError(t, err)
queryRes, logs, err := input.EVMKeeper.EVMCall(ctx, evmAddr, contractAddr, queryInputBz, nil)
queryRes, logs, err := input.EVMKeeper.EVMCall(ctx, evmAddr, contractAddr, queryInputBz, nil, nil)
require.NoError(t, err)
require.Equal(t, uint256.NewInt(0).Bytes32(), [32]byte(queryRes))
require.Empty(t, logs)
Expand All @@ -184,7 +184,7 @@ func Test_onTimeoutPacket_memo_ICS721(t *testing.T) {
require.NoError(t, err)

// check the contract state; increased by 99
queryRes, logs, err = input.EVMKeeper.EVMCall(ctx, evmAddr, contractAddr, queryInputBz, nil)
queryRes, logs, err = input.EVMKeeper.EVMCall(ctx, evmAddr, contractAddr, queryInputBz, nil, nil)
require.NoError(t, err)
require.Equal(t, uint256.NewInt(99).Bytes32(), [32]byte(queryRes))
require.Empty(t, logs)
Expand Down
4 changes: 2 additions & 2 deletions integration-tests/erc721_transfer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ func (suite *KeeperTestSuite) CreateNftClass(
inputBz, err := nftKeeper.ABI.Pack("", name, name)
suite.Require().NoError(err)

_, contractAddr, _, err := evmKeeper.EVMCreate(ctx, createAccountAddr, append(nftKeeper.ERC721Bin, inputBz...), nil)
_, contractAddr, _, err := evmKeeper.EVMCreate(ctx, createAccountAddr, append(nftKeeper.ERC721Bin, inputBz...), nil, nil)
suite.Require().NoError(err)

classId, err := evmtypes.ClassIdFromCollectionAddress(endpoint.Chain.GetContext(), nftKeeper, contractAddr)
Expand Down Expand Up @@ -166,7 +166,7 @@ func (suite *KeeperTestSuite) MintNft(
contractAddr, err := evmtypes.ContractAddressFromClassId(ctx, nftKeeper, classId)
suite.Require().NoError(err)

_, _, err = nftKeeper.EVMCall(ctx, createAccountAddr, contractAddr, inputBz, nil)
_, _, err = nftKeeper.EVMCall(ctx, createAccountAddr, contractAddr, inputBz, nil, nil)
suite.Require().NoError(err)
}

Expand Down
10 changes: 8 additions & 2 deletions jsonrpc/types/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,13 @@
from, _ := coretypes.Sender(signer, tx)
v, r, s := tx.RawSignatureValues()
al := tx.AccessList()
yparity := hexutil.Uint64(v.Sign())
var yparity *hexutil.Uint64 = new(hexutil.Uint64)
switch tx.Type() {
case coretypes.LegacyTxType:
yparity = nil
default: // Dynamic and Access List use yParity
*yparity = hexutil.Uint64(v.Sign())

Check warning on line 47 in jsonrpc/types/tx.go

View check run for this annotation

Codecov / codecov/patch

jsonrpc/types/tx.go#L42-L47

Added lines #L42 - L47 were not covered by tests
}
beer-1 marked this conversation as resolved.
Show resolved Hide resolved
djm07073 marked this conversation as resolved.
Show resolved Hide resolved

result := &RPCTransaction{
Type: hexutil.Uint64(tx.Type()),
Expand All @@ -58,7 +64,7 @@
S: (*hexutil.Big)(s),
ChainID: (*hexutil.Big)(chainID),
Accesses: &al,
YParity: &yparity,
YParity: yparity,

Check warning on line 67 in jsonrpc/types/tx.go

View check run for this annotation

Codecov / codecov/patch

jsonrpc/types/tx.go#L67

Added line #L67 was not covered by tests
}
if blockHash != (common.Hash{}) {
result.BlockHash = &blockHash
Expand Down
8 changes: 8 additions & 0 deletions proto/minievm/evm/v1/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ message MsgCreate {
(gogoproto.nullable) = false,
(amino.dont_omitempty) = true
];
// AccessList is a predefined list of Ethereum addresses and their corresponding storage slots that a transaction will interact with during its execution. can be none
repeated AccessTuple access_list = 4 [(gogoproto.nullable) = false, (amino.dont_omitempty) = true];
}

// MsgCreateResponse defines the Msg/Create response type.
Expand Down Expand Up @@ -79,6 +81,9 @@ message MsgCreate2 {
(gogoproto.nullable) = false,
(amino.dont_omitempty) = true
];

// AccessList is a predefined list of Ethereum addresses and their corresponding storage slots that a transaction will interact with during its execution. can be none
repeated AccessTuple access_list = 5 [(gogoproto.nullable) = false, (amino.dont_omitempty) = true];
}

// MsgCreate2Response defines the Msg/Create2 response type.
Expand Down Expand Up @@ -117,6 +122,9 @@ message MsgCall {
(gogoproto.nullable) = false,
(amino.dont_omitempty) = true
];

// AccessList is a predefined list of Ethereum addresses and their corresponding storage slots that a transaction will interact with during its execution. can be none
repeated AccessTuple access_list = 5 [(gogoproto.nullable) = false, (amino.dont_omitempty) = true];
}

// MsgCallResponse defines the Msg/Call response type.
Expand Down
9 changes: 9 additions & 0 deletions proto/minievm/evm/v1/types.proto
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,12 @@ message Log {
// supplied by the contract, usually ABI-encoded
string data = 3;
}

message AccessTuple {
// Address of the contract that will be accessed during the transaction execution.
string address = 1;

// A list of storage keys that the transaction will interact with within the specified contract.
// These keys represent specific storage slots in the contract's storage that are accessed or modified.
repeated string storage_keys = 2;
}
Loading
Loading