Skip to content

Commit

Permalink
Merge branch 'main' into yarkin/call_action
Browse files Browse the repository at this point in the history
  • Loading branch information
yarkinwho committed Jul 27, 2023
2 parents d3b8233 + f352bbb commit 65a6227
Show file tree
Hide file tree
Showing 20 changed files with 2,577 additions and 1,577 deletions.
4 changes: 2 additions & 2 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
url = https://github.com/lemire/CRoaringUnityBuild
[submodule "silkworm"]
path = silkworm
url = git@github.com:eosnetworkfoundation/silkworm
url = https://github.com/eosnetworkfoundation/silkworm
[submodule "contract/external/ethash"]
path = contract/external/ethash
url = git@github.com:eosnetworkfoundation/ethash
url = https://github.com/eosnetworkfoundation/ethash
[submodule "contract/external/intx"]
path = contract/external/intx
url = https://github.com/chfast/intx
Expand Down
1 change: 1 addition & 0 deletions contract/src/actions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,7 @@ void evm_contract::pushtx( eosio::name miner, const bytes& rlptx ) {

engine.finalize(ep.state(), ep.evm().block(), ep.evm().revision());
ep.state().write_to_db(ep.evm().block().header.number);
LOGTIME("EVM END");
}

void evm_contract::open(eosio::name owner) {
Expand Down
4 changes: 2 additions & 2 deletions contract/tests/mapping_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ try {
BOOST_REQUIRE(produce_blocks_until_timestamp_satisfied(timestamp_at_second_boundary));

init();
time_point_sec expected_genesis_time = control->pending_block_time(); // Rounds down to nearest second.
time_point_sec expected_genesis_time = time_point_sec(control->pending_block_time()); // Rounds down to nearest second.

time_point_sec actual_genesis_time = get_genesis_time();
ilog("Genesis time: ${time}", ("time", actual_genesis_time));
Expand All @@ -115,7 +115,7 @@ try {
BOOST_REQUIRE(produce_blocks_until_timestamp_satisfied(timestamp_not_at_second_boundary));

init();
time_point_sec expected_genesis_time = control->pending_block_time(); // Rounds down to nearest second.
time_point_sec expected_genesis_time = time_point_sec(control->pending_block_time()); // Rounds down to nearest second.

time_point_sec actual_genesis_time = get_genesis_time();
ilog("Genesis time: ${time}", ("time", actual_genesis_time));
Expand Down
15 changes: 10 additions & 5 deletions docs/compilation_and_testing_guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,11 @@ The EVM contract will not allow any actions except `init` until its chain id & n
./cleos push action evmevmevmevm init '{"chainid": 15555}'
```

add eosio.code to active permission
```
./cleos set account permission evmevmevmevm active --add-code
```

## Set balance and transfer native EVM token via EVM smart contract: ##

Prerequisite:
Expand Down Expand Up @@ -471,7 +476,7 @@ to get all the storages, for example:
## Make sure RPC response:
- eth_getBlockByNumber:
```
kayan-u20@kayan-u20:~/workspaces/eos-evm$ curl --location --request POST 'localhost:8881/' --header 'Content-Type: application/json' --data-raw '{"method":"eth_blockNumber","id":0}'
curl --location --request POST 'localhost:8881/' --header 'Content-Type: application/json' --data-raw '{"method":"eth_blockNumber","id":0,"jsonrpc":"2.0"}'
{"error":{"code":100,"message":"unknown bucket: SyncStage"},"id":0,"jsonrpc":"2.0"}
```
At the very beginning it is normal to see "unknown bucket: SyncStage" because there's no block
Expand All @@ -484,13 +489,13 @@ python3 ./send_data_via_cleos.py 2787b98fc4e731d0456b3941f0b3fe2e01439961 "" 0 6

## get blocknumber again
```
kayan-u20@kayan-u20:~/workspaces/eos-evm$ curl --location --request POST 'localhost:8881/' --header 'Content-Type: application/json' --data-raw '{"method":"eth_blockNumber","id":0}'
curl --location --request POST 'localhost:8881/' --header 'Content-Type: application/json' --data-raw '{"method":"eth_blockNumber","id":0,"jsonrpc":"2.0"}'
{"id":0,"jsonrpc":"2.0","result":"0x1"}
```

## now try get block by number
```
kayan-u20@kayan-u20:~/workspaces/eos-evm$ curl --location --request POST 'localhost:8881/' --header 'Content-Type: application/json' --data-raw '{"method":"eth_getBlockByNumber","params":["0x1",true],"id":0}'
curl --location --request POST 'localhost:8881/' --header 'Content-Type: application/json' --data-raw '{"method":"eth_getBlockByNumber","params":["0x1",true],"id":0,"jsonrpc":"2.0"}'
{"id":0,"jsonrpc":"2.0","result":{"difficulty":"0x","extraData":"0x","gasLimit":"0xffffffffffffffff","gasUsed":"0x0","hash":"0x62438d9e228c32a3033a961161f913b700e0d6aecf0ecb141e92ae41d1fb9845","logsBloom":"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","miner":"0x0000000000000000000000000000000000000000","mixHash":"0x0000000000000000000000000000000000000000000000000000000000000000","nonce":"0x0000000000000000","number":"0x1","parentHash":"0x0000000000000000000000000000000000000000000000000000000000000000","receiptsRoot":"0x0000000000000000000000000000000000000000000000000000000000000000","sha3Uncles":"0x0000000000000000000000000000000000000000000000000000000000000000","size":"0x3cc","stateRoot":"0x0000000000000000000000000000000000000000000000000000000000000000","timestamp":"0x183c5f2fea0","totalDifficulty":"0x","transactions":[{"blockHash":"0x62438d9e228c32a3033a961161f913b700e0d6aecf0ecb141e92ae41d1fb9845","blockNumber":"0x1","from":"0x2787b98fc4e731d0456b3941f0b3fe2e01439961","gas":"0xf4240","gasPrice":"0x3b9aca00","hash":"0xc4372998d1f7fc02a24fbb381947f7a10ed0826c404b7533e8431df9e48a27d0","input":"0x608060405234801561001057600080fd5b50610150806100206000396000f3fe608060405234801561001057600080fd5b50600436106100365760003560e01c80632e64cec11461003b5780636057361d14610059575b600080fd5b610043610075565b60405161005091906100d9565b60405180910390f35b610073600480360381019061006e919061009d565b61007e565b005b60008054905090565b8060008190555050565b60008135905061009781610103565b92915050565b6000602082840312156100b3576100b26100fe565b5b60006100c184828501610088565b91505092915050565b6100d3816100f4565b82525050565b60006020820190506100ee60008301846100ca565b92915050565b6000819050919050565b600080fd5b61010c816100f4565b811461011757600080fd5b5056fea26469706673582212209a159a4f3847890f10bfb87871a61eba91c5dbf5ee3cf6398207e292eee22a1664736f6c63430008070033","nonce":"0x0","r":"0x8cd1b11f5a5a9a811ad415b3f3d360a4d8aa4a8bae20467ad3649cfbad25a5ae","s":"0x5eab2829885d473747727d54caae01a8076244c3f6a4af8cad742a248b7a19ec","to":null,"transactionIndex":"0x0","type":"0x0","v":"0x79aa","value":"0x0"}],"transactionsRoot":"0x0000000000000000000000000000000000000000000000000000000000000000","uncles":[]}}
```

Expand All @@ -501,7 +506,7 @@ python3 ./send_data_via_cleos.py 2787b98fc4e731d0456b3941f0b3fe2e01439961 3f4b0f

## and then execute the view action "retrieve" from RPC
```
kayan-u20@kayan-u20:~/workspaces/eos-evm$ curl --location --request POST 'localhost:8881/' --header 'Content-Type: application/json' --data-raw '{"method":"eth_call","params":[{"from":" 2787b98fc4e731d0456b3941f0b3fe2e01439961","to":"3f4b0f92007341792aa61e065484e48e583ebeb9","data":"0x2e64cec1"},"latest"],"id":11}'
curl --location --request POST 'localhost:8881/' --header 'Content-Type: application/json' --data-raw '{"method":"eth_call","params":[{"from":" 2787b98fc4e731d0456b3941f0b3fe2e01439961","to":"3f4b0f92007341792aa61e065484e48e583ebeb9","data":"0x2e64cec1"},"latest"],"id":11,"jsonrpc":"2.0"}'
{"id":11,"jsonrpc":"2.0","result":"0x000000000000000000000000000000000000000000000000000000000000007b"}
```

Expand All @@ -512,7 +517,7 @@ python3 ./send_via_cleos.py 2787b98fc4e731d0456b3941f0b3fe2e01439961 0x9edf02200

## get balance via RPC
```
kayan-u20@kayan-u20:~/workspaces/eos-evm$ curl --location --request POST 'localhost:8881/' --header 'Content-Type: application/json' --data-raw '{"method":"eth_getBalance","params":["9edf022004846bc987799d552d1b8485b317b7ed","latest"],"id":0}'
curl --location --request POST 'localhost:8881/' --header 'Content-Type: application/json' --data-raw '{"method":"eth_getBalance","params":["9edf022004846bc987799d552d1b8485b317b7ed","latest"],"id":0,"jsonrpc":"2.0"}'
{"id":0,"jsonrpc":"2.0","result":"0x100"}
```
(Note the balance of 2787b98fc4e731d0456b3941f0b3fe2e01439900 may not work, because it is hacked)
Expand Down
25 changes: 20 additions & 5 deletions docs/local_testnet_deployment_plan.md
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,11 @@ Set chain ID & native token configuration (in this example, gas price is 150 Gwe
\"}}" -p evmevmevmevm
```

Add eosio.code to active permission
```
./cleos set account permission evmevmevmevm active --add-code
```

after the init action we need a small amount of token (1 EOS) to be transferred into the contract account (with memo=contract account), for example:
```
./cleos transfer eosio evmevmevmevm "1.0000 EOS" "evmevmevmevm"
Expand Down Expand Up @@ -944,7 +949,17 @@ This determines the value of the "timestamp" field in EVM genesis.

Set the "mixHash" field to be "0x + Antelope starting block id", e.g. "0x000000026d392f1bfeddb000555bcb03ca6e31a54c0cf9edc23cede42bda17e6"

Set the "nonce" field to be the hex encoding of the value of the Antelope name of the account on which the EVM contract is deployed. So if the `evmevmevmevm` account name is used, then set the nonce to "0x56e4adc95b92b720". If the `eosio.evm` account name is used, then set the nonce to "0x56e4adc95b92b720". This is re-purposed to be the block time (in mill-second) of the EVM chain.
Set the "nonce" field to be the hex encoding of the value of the Antelope name of the account on which the EVM contract is deployed. So if the `evmevmevmevm` account name is used, then set the nonce to "0x56e4adc95b92b720". If the `eosio.evm` account name is used, then set the nonce to "0x5530ea015b900000".

The function `convert_name_to_value` from https://github.com/eosnetworkfoundation/eos-evm/blob/main/tests/leap/antelope_name.py can be used to get the appropriate nonce value using Python:

```shell
>>> from antelope_name import convert_name_to_value
>>> print(f'0x{convert_name_to_value("evmevmevmevm"):x}')
0x56e4adc95b92b720
>>> print(f'0x{convert_name_to_value("eosio.evm"):x}')
0x5530ea015b900000
```

In the "alloc" part, setup the genesis EVM account balance (should be all zeros)

Expand Down Expand Up @@ -1008,7 +1023,7 @@ In the above command, eos-evm-rpc will listen on port 8881 for RPC requests.
To verify the RPC response run below command:

```shell
curl --location --request POST 'localhost:8881/' --header 'Content-Type: application/json' --data-raw '{"method":"eth_blockNumber","id":0}'
curl --location --request POST 'localhost:8881/' --header 'Content-Type: application/json' --data-raw '{"method":"eth_blockNumber","id":0,"jsonrpc":"2.0"}'
```

You'll recevie a response similar to the one below:
Expand All @@ -1022,7 +1037,7 @@ You'll recevie a response similar to the one below:
Request:

```shell
curl --location --request POST 'localhost:8881/' --header 'Content-Type: application/json' --data-raw '{"method":"eth_getBlockByNumber","params":["0x1",true],"id":0}'
curl --location --request POST 'localhost:8881/' --header 'Content-Type: application/json' --data-raw '{"method":"eth_getBlockByNumber","params":["0x1",true],"id":0,"jsonrpc":"2.0"}'
```

Response:
Expand All @@ -1036,7 +1051,7 @@ Response:
Request:

```shell
curl --location --request POST 'localhost:8881/' --header 'Content-Type: application/json' --data-raw '{"method":"eth_getBalance","params":["9edf022004846bc987799d552d1b8485b317b7ed","latest"],"id":0}'
curl --location --request POST 'localhost:8881/' --header 'Content-Type: application/json' --data-raw '{"method":"eth_getBalance","params":["9edf022004846bc987799d552d1b8485b317b7ed","latest"],"id":0,"jsonrpc":"2.0"}'
```

response:
Expand All @@ -1051,7 +1066,7 @@ Request:
data - 0x2e64cec1 is the hash of a solidity function `retrieve() public view returns (uint256)`

```shell
curl --location --request POST 'localhost:8881/' --header 'Content-Type: application/json' --data-raw '{"method":"eth_call","params":[{"from":" 2787b98fc4e731d0456b3941f0b3fe2e01439961","to":"3f4b0f92007341792aa61e065484e48e583ebeb9","data":"0x2e64cec1"},"latest"],"id":11}'
curl --location --request POST 'localhost:8881/' --header 'Content-Type: application/json' --data-raw '{"method":"eth_call","params":[{"from":" 2787b98fc4e731d0456b3941f0b3fe2e01439961","to":"3f4b0f92007341792aa61e065484e48e583ebeb9","data":"0x2e64cec1"},"latest"],"id":11,"jsonrpc":"2.0"}'
```

Response:
Expand Down
Loading

0 comments on commit 65a6227

Please sign in to comment.