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

[action] add evm london test #3402

Merged
merged 17 commits into from
Jun 23, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
113 changes: 111 additions & 2 deletions action/protocol/execution/protocol_test.go
Original file line number Diff line number Diff line change
@@ -17,6 +17,8 @@ import (
"os"
"testing"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/pkg/errors"
"github.com/stretchr/testify/require"
"go.uber.org/zap"
@@ -64,13 +66,19 @@ type (
GenesisBlockHeight struct {
IsBering bool `json:"isBering"`
IsIceland bool `json:"isIceland"`
IsLondon bool `json:"isLondon"`
}

Log struct {
Topics []string `json:"topics"`
Data string `json:"data"`
}

AccessTuple struct {
Address string `json:"address"`
StorageKeys []string `json:"storageKeys"`
}

ExecutionConfig struct {
Comment string `json:"comment"`
ContractIndex int `json:"contractIndex"`
@@ -83,6 +91,7 @@ type (
RawAmount string `json:"rawAmount"`
RawGasLimit uint `json:"rawGasLimit"`
RawGasPrice string `json:"rawGasPrice"`
RawAccessList []AccessTuple `json:"rawAccessList"`
Failed bool `json:"failed"`
RawReturnValue string `json:"rawReturnValue"`
RawExpectedGasConsumed uint `json:"rawExpectedGasConsumed"`
@@ -188,6 +197,23 @@ func (cfg *ExecutionConfig) GasLimit() uint64 {
return uint64(cfg.RawGasLimit)
}

func (cfg *ExecutionConfig) AccessList() types.AccessList {
if len(cfg.RawAccessList) == 0 {
return nil
}
accessList := make(types.AccessList, len(cfg.RawAccessList))
for i, rawAccessList := range cfg.RawAccessList {
accessList[i].Address = common.HexToAddress(rawAccessList.Address)
if numKey := len(rawAccessList.StorageKeys); numKey > 0 {
accessList[i].StorageKeys = make([]common.Hash, numKey)
for j, rawStorageKey := range rawAccessList.StorageKeys {
accessList[i].StorageKeys[j] = common.HexToHash(rawStorageKey)
}
}
}
return accessList
}

func (cfg *ExecutionConfig) ExpectedGasConsumed() uint64 {
return uint64(cfg.RawExpectedGasConsumed)
}
@@ -237,13 +263,14 @@ func readExecution(
if err != nil {
return nil, nil, err
}
exec, err := action.NewExecution(
exec, err := action.NewExecutionWithAccessList(
contractAddr,
state.Nonce+1,
ecfg.Amount(),
ecfg.GasLimit(),
ecfg.GasPrice(),
ecfg.ByteCode(),
ecfg.AccessList(),
)
if err != nil {
return nil, nil, err
@@ -284,13 +311,14 @@ func runExecutions(
}
nonce = nonce + 1
nonces[executor.String()] = nonce
exec, err := action.NewExecution(
exec, err := action.NewExecutionWithAccessList(
contractAddrs[i],
nonce,
ecfg.Amount(),
ecfg.GasLimit(),
ecfg.GasPrice(),
ecfg.ByteCode(),
ecfg.AccessList(),
)
if err != nil {
return nil, nil, err
@@ -372,6 +400,9 @@ func (sct *SmartContractTest) prepareBlockchain(
cfg.Genesis.GreenlandBlockHeight = 0
cfg.Genesis.IcelandBlockHeight = 0
}
if sct.InitGenesis.IsLondon {
cfg.Genesis.Blockchain.ToBeEnabledBlockHeight = 0
}
for _, expectedBalance := range sct.InitBalances {
cfg.Genesis.InitBalanceMap[expectedBalance.Account] = expectedBalance.Balance().String()
}
@@ -1002,6 +1033,84 @@ func TestIstanbulEVM(t *testing.T) {
})
}

func TestLondonEVM(t *testing.T) {
t.Run("ArrayReturn", func(t *testing.T) {
NewSmartContractTest(t, "testdata-london/array-return.json")
})
t.Run("BasicToken", func(t *testing.T) {
NewSmartContractTest(t, "testdata-london/basic-token.json")
})
t.Run("CallDynamic", func(t *testing.T) {
NewSmartContractTest(t, "testdata-london/call-dynamic.json")
})
t.Run("chainid-selfbalance", func(t *testing.T) {
NewSmartContractTest(t, "testdata-london/chainid-selfbalance.json")
})
t.Run("ChangeState", func(t *testing.T) {
NewSmartContractTest(t, "testdata-london/changestate.json")
})
t.Run("F.value", func(t *testing.T) {
NewSmartContractTest(t, "testdata-london/f.value.json")
})
t.Run("Gas-test", func(t *testing.T) {
NewSmartContractTest(t, "testdata-london/gas-test.json")
})
t.Run("InfiniteLoop", func(t *testing.T) {
NewSmartContractTest(t, "testdata-london/infiniteloop.json")
})
t.Run("MappingDelete", func(t *testing.T) {
NewSmartContractTest(t, "testdata-london/mapping-delete.json")
})
t.Run("max-time", func(t *testing.T) {
NewSmartContractTest(t, "testdata-london/maxtime.json")
})
t.Run("Modifier", func(t *testing.T) {
NewSmartContractTest(t, "testdata-london/modifiers.json")
})
t.Run("Multisend", func(t *testing.T) {
NewSmartContractTest(t, "testdata-london/multisend.json")
})
t.Run("NoVariableLengthReturns", func(t *testing.T) {
NewSmartContractTest(t, "testdata-london/no-variable-length-returns.json")
})
t.Run("PublicMapping", func(t *testing.T) {
NewSmartContractTest(t, "testdata-london/public-mapping.json")
})
t.Run("reentry-attack", func(t *testing.T) {
NewSmartContractTest(t, "testdata-london/reentry-attack.json")
})
t.Run("RemoveFromArray", func(t *testing.T) {
NewSmartContractTest(t, "testdata-london/remove-from-array.json")
})
t.Run("SendEth", func(t *testing.T) {
NewSmartContractTest(t, "testdata-london/send-eth.json")
})
t.Run("Sha3", func(t *testing.T) {
NewSmartContractTest(t, "testdata-london/sha3.json")
})
t.Run("storage-test", func(t *testing.T) {
NewSmartContractTest(t, "testdata-london/storage-test.json")
})
t.Run("TailRecursion", func(t *testing.T) {
NewSmartContractTest(t, "testdata-london/tail-recursion.json")
})
t.Run("Tuple", func(t *testing.T) {
NewSmartContractTest(t, "testdata-london/tuple.json")
})
t.Run("wireconnection", func(t *testing.T) {
NewSmartContractTest(t, "testdata-london/wireconnection.json")
})
t.Run("self-destruct", func(t *testing.T) {
NewSmartContractTest(t, "testdata-london/self-destruct.json")
})
t.Run("datacopy", func(t *testing.T) {
NewSmartContractTest(t, "testdata-london/datacopy.json")
})
t.Run("CVE-2021-39137-attack-replay", func(t *testing.T) {
NewSmartContractTest(t, "testdata/CVE-2021-39137-attack-replay.json")
})
}

func benchmarkHotContractWithFactory(b *testing.B, async bool) {
sct := SmartContractTest{
InitBalances: []ExpectedBalance{
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"initGenesis": {
"isBering" : true,
"isIceland" : true,
"isLondon" : true
},
"initBalances": [{
"account": "io1mflp9m6hcgm2qcghchsdqj3z3eccrnekx9p0ms",
"rawBalance": "1000000000000000000000000000"
}],
"deployments": [{
"rawByteCode": "0000000000000000000000008eae784e072e961f76948a785b62c9a950fb17ae62c9a950fb17ae00000000000000000000000000000000000000000000000000",
"rawPrivateKey": "cfa6ef757dee2e50351620dca002d32b9c090cfda55fb81f37f1d26b273743f1",
"rawAmount": "0",
"rawGasLimit": 5000000,
"rawGasPrice": "0",
"rawExpectedGasConsumed": 16400,
"expectedBalances": [],
"comment": "deploy attack contract(https://etherscan.io/address/0x8eae784e072e961f76948a785b62c9a950fb17ae)"
}],
"executions": [{
"rawPrivateKey": "cfa6ef757dee2e50351620dca002d32b9c090cfda55fb81f37f1d26b273743f1",
"rawByteCode": "3034526020600760203460045afa602034343e604034f3",
"rawAmount": "0",
"rawGasLimit": 1000000,
"rawGasPrice": "0",
"rawAccessList": [],
"rawExpectedGasConsumed": 12300,
"comment": "launch attack(https://etherscan.io/tx/0x1cb6fb36633d270edefc04d048145b4298e67b8aa82a9e5ec4aa1435dd770ce4)",
"expectedBlockInfos" : {
"txRootHash" : "a59ead74a3870e9b5ca352c5f59108df402ca203ef2109799fe2d8e1da49c83d",
"stateRootHash" : "ed9bd589ee5ab5660a3d5d863bbeea13020a0aacab18e8655a626beaf9a54713",
"receiptRootHash" : "3285579efa8521fbf95829b868ff5d37632c4feac6167e9ab2dc4961004c9272"
}
}]
}
45 changes: 45 additions & 0 deletions action/protocol/execution/testdata-london/array-return.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{
"initGenesis": {
"isBering" : true,
"isIceland" : true,
"isLondon" : true
},
"initBalances": [{
"account": "io1mflp9m6hcgm2qcghchsdqj3z3eccrnekx9p0ms",
"rawBalance": "1000000000000000000000000000"
}],
"deployments": [{
"rawByteCode": "608060405234801561001057600080fd5b50610115806100206000396000f3fe6080604052348015600f57600080fd5b506004361060285760003560e01c8063c298557814602d575b600080fd5b60336047565b604051603e9190609d565b60405180910390f35b60606000805480602002602001604051908101604052809291908181526020018280548015609357602002820191906000526020600020905b8154815260200190600101908083116080575b5050505050905090565b6020808252825182820181905260009190848201906040850190845b8181101560d35783518352928401929184019160010160b9565b5090969550505050505056fea2646970667358221220003153ac66045f6e4649a560a665c439bafefa3a32ad368e45a214ceeb75fdbe64736f6c634300080e0033",
"rawPrivateKey": "cfa6ef757dee2e50351620dca002d32b9c090cfda55fb81f37f1d26b273743f1",
"rawAmount": "0",
"rawGasLimit": 5000000,
"rawGasPrice": "0",
"rawExpectedGasConsumed": 96405,
"expectedStatus": 1,
"expectedBalances": [],
"comment": "deploy array-return contract A"
},{
"rawByteCode": "608060405234801561001057600080fd5b50610212806100206000396000f3fe608060405234801561001057600080fd5b506004361061002b5760003560e01c8063febb0f7e14610030575b600080fd5b61003861004e565b60405161004591906100c4565b60405180910390f35b60008054604080516318530aaf60e31b815290516060936001600160a01b039093169263c298557892600480820193918290030181865afa158015610097573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040526100bf919081019061011e565b905090565b6020808252825182820181905260009190848201906040850190845b818110156100fc578351835292840192918401916001016100e0565b50909695505050505050565b634e487b7160e01b600052604160045260246000fd5b6000602080838503121561013157600080fd5b825167ffffffffffffffff8082111561014957600080fd5b818501915085601f83011261015d57600080fd5b81518181111561016f5761016f610108565b8060051b604051601f19603f8301168101818110858211171561019457610194610108565b6040529182528482019250838101850191888311156101b257600080fd5b938501935b828510156101d0578451845293850193928501926101b7565b9897505050505050505056fea2646970667358221220e2e424aa63507945438677689f578de59a4ff358c3b0332310e7341459ee099164736f6c634300080e0033",
"rawPrivateKey": "cfa6ef757dee2e50351620dca002d32b9c090cfda55fb81f37f1d26b273743f1",
"rawAmount": "0",
"rawGasLimit": 5000000,
"rawGasPrice": "0",
"rawExpectedGasConsumed": 172353,
"expectedStatus": 1,
"expectedBalances": [],
"comment": "deploy array-return contract B"
}],
"executions": [{
"readOnly": true,
"rawPrivateKey": "cfa6ef757dee2e50351620dca002d32b9c090cfda55fb81f37f1d26b273743f1",
"rawByteCode": "febb0f7e",
"rawAmount": "0",
"rawGasLimit": 1000000,
"rawGasPrice": "0",
"rawAccessList": [],
"rawExpectedGasConsumed": 10504,
"expectedStatus": 106,
"failed": true,
"comment": "call bar"
}]
}
34 changes: 34 additions & 0 deletions action/protocol/execution/testdata-london/array-return.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// SPDX-License-Identifier: GPL-3.0

pragma solidity ^0.8.14;

contract A {
uint256[] xs;

function Apush() internal {
xs.push(100);
xs.push(200);
xs.push(300);
}

// can be called from web3
function foo() public view returns (uint256[] memory) {
return xs;
}
}

// trying to call foo from another contract does not work
contract B {
A a;

function Bnew() internal {
a = new A();
}

// COMPILATION ERROR
// Return argument type inaccessible dynamic type is not implicitly convertible
// to expected type (type of first return variable) uint256[] memory.
function bar() public view returns (uint256[] memory) {
return a.foo();
}
}
57 changes: 57 additions & 0 deletions action/protocol/execution/testdata-london/basic-token.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
{
"initGenesis": {
"isBering" : true,
"isIceland" : true,
"isLondon" : true
},
"initBalances": [{
"account": "io1mflp9m6hcgm2qcghchsdqj3z3eccrnekx9p0ms",
"rawBalance": "1000000000000000000000000000"
}],
"deployments": [{
"rawByteCode": "608060405234801561001057600080fd5b506101da806100206000396000f3fe608060405234801561001057600080fd5b50600436106100365760003560e01c806370a082311461003b578063a9059cbb14610076575b600080fd5b610064610049366004610113565b6001600160a01b031660009081526020819052604090205490565b60405190815260200160405180910390f35b610089610084366004610135565b61008b565b005b3360009081526020819052604090205481116100c65733600090815260208190526040812080548392906100c0908490610175565b90915550505b6001600160a01b038216600090815260208190526040812080548392906100ee90849061018c565b90915550505050565b80356001600160a01b038116811461010e57600080fd5b919050565b60006020828403121561012557600080fd5b61012e826100f7565b9392505050565b6000806040838503121561014857600080fd5b610151836100f7565b946020939093013593505050565b634e487b7160e01b600052601160045260246000fd5b6000828210156101875761018761015f565b500390565b6000821982111561019f5761019f61015f565b50019056fea2646970667358221220df940e6c929cec5606a2caf0706e2b729904e0a4d6887c561d2dd6c976bd05a464736f6c634300080e0033",
"rawPrivateKey": "cfa6ef757dee2e50351620dca002d32b9c090cfda55fb81f37f1d26b273743f1",
"rawAmount": "0",
"rawGasLimit": 5000000,
"rawGasPrice": "0",
"rawExpectedGasConsumed": 155541,
"expectedStatus": 1,
"expectedBalances": [],
"comment": "deploy an basic token contract"
}],
"executions": [{
"rawPrivateKey": "cfa6ef757dee2e50351620dca002d32b9c090cfda55fb81f37f1d26b273743f1",
"rawByteCode": "a9059cbb0000000000000000000000003328358128832a260c76a4141e19e2a943cd4b6d0000000000000000000000000000000000000000000000000000000000002710",
"rawAmount": "0",
"rawGasLimit": 1000000,
"rawGasPrice": "0",
"rawAccessList": [{
"address": "06abb2ca03834bd4f62c610ca7627e3dd12d9a97",
"storageKeys": [
"cd7bfe84e3fe161aeb958aa899cea602147a8edb25bcc4cc49f4753fa3410c17"
]
}],
"rawExpectedGasConsumed": 43909,
"expectedStatus": 1,
"expectedBalances": [],
"comment": "transfer 10000 tokens from producer"
}, {
"rawPrivateKey": "cfa6ef757dee2e50351620dca002d32b9c090cfda55fb81f37f1d26b273743f1",
"rawByteCode": "70a082310000000000000000000000003328358128832a260c76a4141e19e2a943cd4b6d",
"rawAmount": "0",
"rawGasLimit": 1000000,
"rawGasPrice": "0",
"rawAccessList": [{
"address": "06abb2ca03834bd4f62c610ca7627e3dd12d9a97",
"storageKeys": [
"cd7bfe84e3fe161aeb958aa899cea602147a8edb25bcc4cc49f4753fa3410c17"
]
}],
"rawExpectedGasConsumed": 18406,
"expectedStatus": 1,
"readOnly": true,
"rawReturnValue": "0000000000000000000000000000000000000000000000000000000000002710",
"expectedBalances": [],
"comment": "read the balance"
}]
}
18 changes: 18 additions & 0 deletions action/protocol/execution/testdata-london/basic-token.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// SPDX-License-Identifier: GPL-3.0

pragma solidity ^0.8.14;

contract BasicToken {
mapping(address => uint256) balances;

function transfer(address recipient, uint256 value) public {
if (balances[msg.sender] >= value) {
balances[msg.sender] -= value;
}
balances[recipient] += value;
}

function balanceOf(address account) public view returns (uint256) {
return balances[account];
}
}
Loading