diff --git a/docs/compilation_and_testing_guide.md b/docs/compilation_and_testing_guide.md index 1ffa52c3..ce783f9a 100644 --- a/docs/compilation_and_testing_guide.md +++ b/docs/compilation_and_testing_guide.md @@ -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: @@ -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 @@ -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":[]}} ``` @@ -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"} ``` @@ -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) diff --git a/docs/local_testnet_deployment_plan.md b/docs/local_testnet_deployment_plan.md index 3ebe2327..a9c485c6 100644 --- a/docs/local_testnet_deployment_plan.md +++ b/docs/local_testnet_deployment_plan.md @@ -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" @@ -1018,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: @@ -1032,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: @@ -1046,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: @@ -1061,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: diff --git a/docs/public_testnet_deployment_plan.md b/docs/public_testnet_deployment_plan.md index 6293ef5f..63bc570f 100644 --- a/docs/public_testnet_deployment_plan.md +++ b/docs/public_testnet_deployment_plan.md @@ -365,177 +365,33 @@ See the [cleos create account](https://docs.eosnetwork.com/leap/latest/cleos/com See the [cleos create key pair](https://docs.eosnetwork.com/leap/latest/cleos/command-reference/create/key) reference for details on how to create a key pair. -### 2. Deploy The Debug EVM Contract - -Later in this procedure you must use the `setbal` smart contract action to set the balance of the inital account. This action is available only in the `debug` version of the smart contract. - -Compile the `debug` version of the EVM smart contract and note the wasm and abi path, e.g. `EVM_DEBUG_PATH`. +### 2. Deploy EVM Contract For details on how to compile the EVM smart contract see the [Compilation And Testing Guide](https://github.com/eosnetworkfoundation/eos-evm/blob/main/docs/compilation_and_testing_guide.md). -Run the following `cleos` commands to deploy the `debug` version of the EVM contract to the EVM account: +Run the following `cleos` commands to EVM contract to the EVM account: ```sh -./cleos set code evmevmevmevm EVM_DEBUG_PATH/evm_runtime.wasm -./cleos set abi evmevmevmevm EVM_DEBUG_PATH/evm_runtime.abi +./cleos set code evmevmevmevm EVM_PATH_to_evm_runtime.wasm +./cleos set abi evmevmevmevm EVM_PATH_to_evm_runtime.abi ``` ### 2a. Initialize EVM contract The EVM contract will not allow any actions except `init` until its chain id & native token is configured. Exact values to use here are TBD. ``` -./cleos push action evmevmevmevm init '{"chainid": 15555}' +./cleos push action evmevmevmevm init "{\"chainid\":$EVM_CHAINID,\"fee_params\":{\"gas_price\":150000000000,\"miner_cut\":10000,\"ingress_bridge_fee\":\"0.0100 EOS\"}}" -x 60 -p evmevmevmevm ``` -### 3. Setup The Initial EVM Token Balance - -We need to set the EVM token balance for the initial ETH account, which is specially managed by EOS EVM team. - -For example: -```sh -./cleos push action evmevmevmevm setbal '{"addy":"2787b98fc4e731d0456b3941f0b3fe2e01439961", "bal":"0000000000000000000000000000000100000000000000000000000000000000"}' -p evmevmevmevm +add eosio.code to active permission ``` - -> :warning: Be careful: the balance string value must be in the form of exactly 64 hex-digits (meaning a 256-bit integer) - - -### 4. Deploy The Release EVM Contract - -Compile the `release` version of the EVM smart contract and note the wasm and abi path, e.g. `EVM_RELEASE_PATH`. - -For details on how to compile the EVM smart contract see the [Compilation And Testing Guide](https://github.com/eosnetworkfoundation/eos-evm/blob/main/docs/compilation_and_testing_guide.md). - -Run the following `cleos` commands to deploy the `release` version of the EVM contract to the EVM account: - -```sh -./cleos set code evmevmevmevm EVM_RELEASE_PATH/evm_runtime.wasm -./cleos set abi evmevmevmevm EVM_RELEASE_PATH/evm_runtime.abi +./cleos set account permission evmevmevmevm active --add-code ``` -### 5. Initialize The Participant Accounts Balances - -Send EVM tokens from the initial account to participant accounts. - -Use the token distribution script, [distribute_to_accounts.py](https://github.com/eosnetworkfoundation/eos-evm/blob/main/peripherals/token_distribution/distribute_to_accounts.py), to distribute tokens to the initial EVM accounts: - -#### Prepare The Account Balance CSV File - -You need to list all the account balances in a `.csv` file, without the header row, where the first column represents the account name and the second column respresents the balance number in decimal, such as: - -``` -0x00000000219ab540356cbb839cbe05303d7705fa,14708999007718564869804029 -0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,3930560351933256293096325 -0xf977814e90da44bfa03b6295a0616a897441acec,2604596263728749700480557 -0xda9dfa130df4de4673b89022ee50ff26f6ea73cf,2113030086367224616200000 -0x0716a17fbaee714f1e6ab0f9d59edbc5f09815c0,1998606574289842563751000 -0xbe0eb53f46cd790cd13851d5eff43d12404d33e8,1996008352588563830743490 -0x742d35cc6634c0532925a3b844bc454e4438f44e,1383424850937541446672785 -``` - -#### Prepare Enviroment Variables - -Have your EVM private key of the EVM sender account, and the `nodeos`'s RPC endpoint defined in the corresponding enviroment variables, as in the following example: - -```sh -export EVM_SENDER_KEY=a3f1b69da92a0233ce29485d3049a4ace39e8d384bbc2557e3fc60940ce4e954 -export NODEOS_ENDPOINT=http://127.0.0.1:8888 -``` - -#### Find Out The Starting Nonce Number - -Find out the starting nonce number and the current balance of the sender account. Use the following command to find the starting nonce number of any existing EVM account: - -```sh -./cleos get table evmevmevmevm evmevmevmevm account --index 2 --key-type sha256 --limit 1 -L EVM_ACCOUNT_NAME +transfer initial balance ``` - -For example: -```sh -./cleos get table evmevmevmevm evmevmevmevm account --index 2 --key-type sha256 --limit 1 -L 2787b98fc4e731d0456b3941f0b3fe2e01439961 -``` -```json -{ - "rows": [{ - "id": 0, - "eth_address": "2787b98fc4e731d0456b3941f0b3fe2e01439961", - "nonce": 1005, - "balance": "00000000000000000000000000000000ffffffffffbee2eeb107b6ea020924bd", - "eos_account": "", - "code": "", - "code_hash": "c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470" - } - ], - "more": true, - "next_key": "27ca5d05bb99a31c1cb793c8679f605ea58c1dd3000000000000000000000000" -} +./cleos transfer eosio evmevmevmevm "1.0000 EOS" "evmevmevmevm" ``` -Ensure the sender account has enough balance to distribute to all the accounts in the distribution list. - -##### Locate the starting_nonce variable - -Open token distribution script, [distribute_to_accounts.py](https://github.com/eosnetworkfoundation/eos-evm/blob/main/peripherals/token_distribution/distribute_to_accounts.py), in your editor and search for the `starting_nonce` variable. It should look similar to the code lines below: - -```python -# staring_nonce is the nonce number that maps to the transfer of the first account in the list -# it is used to ensure each transfer is idempotent -# be careful when you change it -starting_nonce = 3 -``` - -##### Update the starting_nonce variable - -In the token distribution script, [distribute_to_accounts.py](https://github.com/eosnetworkfoundation/eos-evm/blob/main/peripherals/token_distribution/distribute_to_accounts.py), update the `starting_nonce` value to match your current sender account's nonce number. The nonce number is to mark the progress of distribution. You should not change the `starting_nonce` once it is correctly set. Save the script. - -#### Prepare Account And Keys - -Prepare your Antelope wrapping account, such as `evmevmevmevm`, and import your private key to your local Antelope wallet (managed by `keosd`). - -For example: -```sh -./cleos wallet create -n w123 --to-console -./cleos wallet import -n w123 --private-key 5JURSKS1BrJ1TagNBw1uVSzTQL2m9eHGkjknWeZkjSt33Awtior -``` - -#### Verify Other Parameters In The Script - -In the token distribution script, [distribute_to_accounts.py](https://github.com/eosnetworkfoundation/eos-evm/blob/main/peripherals/token_distribution/distribute_to_accounts.py), these parameters should read as follows: -```python -EVM_CONTRACT = os.getenv("EVM_CONTRACT", "evmevmevmevm") -NODEOS_ENDPOINT = os.getenv("NODEOS_ENDPOINT", "http://127.0.0.1:8888") -EOS_SENDER = os.getenv("EOS_SENDER", "evmevmevmevm") -EVM_SENDER_KEY = os.getenv("EVM_SENDER_KEY", None) -EOS_SENDER_KEY = os.getenv("EOS_SENDER_KEY", None) -EVM_CHAINID = int(os.getenv("EVM_CHAINID", "15555")) -``` - -#### Run The Distribution Script - -Command syntax: -```sh -python3 ./distribute_to_accounts.py FROM_ACCOUNT DISTRIBUTION_CSV -``` - -For example: -```sh -export EVM_SENDER_KEY=a3f1b69da92a0233ce29485d3049a4ace39e8d384bbc2557e3fc60940ce4e954 -export NODEOS_ENDPOINT=http://127.0.0.1:8888 -python3 ./distribute_to_accounts.py 2787b98fc4e731d0456b3941f0b3fe2e01439961 ~/Downloads/eth_acc_bals_100k.csv -``` - -The script will sign the transactions and call `cleos` to push the transactions to the `NODEOS_ENDPOINT`. - -> :information_source: You can stop and restart the script from time to time and it can continue from the last point of distribution. But do not forget that the `account` and the `starting_nonce` in your script must not be changed. - -#### Final Verification - -For the final verification, check the nonce number again after the entire script is finished. - -```sh -./cleos get table evmevmevmevm evmevmevmevm account --index 2 --key-type sha256 --limit 1 -L EVM_ACCOUNT_NAME -``` -Make sure the current nonce number has been increased by x, where x is the number of accounts in the distribution list. - - ## For EVM Service Providers This part is very similar to the [Enable EVM Support For Local Testnet](https://github.com/eosnetworkfoundation/eos-evm/blob/main/docs/local_testnet_deployment_plan.md) guide. @@ -547,7 +403,7 @@ Run at least one Antelope node to sync with the public testnet, running in irrev Example command: ```sh -./build/programs/nodeos/nodeos --data-dir=./data-dir --config-dir=./data-dir --genesis-json=./data-dir/genesis.json --disable-replay-opts --read-mode=irreversible +./build/programs/nodeos/nodeos --data-dir=./data-dir --config-dir=./data-dir --genesis-json=./data-dir/genesis.json --disable-replay-opts ``` ### 2. Run eos-evm-node @@ -573,7 +429,12 @@ Refer to the *Start up eos-evm-rpc (silkworm RPC)* section in the [Enable EVM Fo ### 4. Ensure Enough Resources -You must have at least one Antelope account, the sender account, with enough CPU/NET/RAM resources. The service providers can create one or more testnet accounts with some CPU, NET, and RAM resources. +You must have at least one Antelope account, the sender account, with enough CPU/NET/RAM resources. The service providers can create one or more testnet accounts with some CPU, NET, and RAM resources. We use account a123 as example: + +open sender account balance +``` +./cleos push action evmevmevmevm open '{"owner":"a123"}' -p a123 +``` ### 5. Run a Transaction Wrapper Service @@ -582,17 +443,22 @@ Run at least one Transaction Wrapper service to wrap ETH transactions into Antel For example: ```conf -EOS_RPC="http://127.0.0.1:8888" +# one or more EOS_RPC endpoints, separated by '|' +EOS_RPC="http://127.0.0.1:8888|http://192.168.1.1:8888" EOS_KEY="5JURSKS1BrJ1TagNBw1uVSzTQL2m9eHGkjknWeZkjSt33Awtior" + +# the listening IP & port of this service HOST="127.0.0.1" PORT="18888" -EOS_EVM_ACCOUNT="evmevmevmevm" +EOS_PERMISSION="active" +EXPIRE_SEC=60 +EOS_EVM_ACCOUNT="evmevmevm" EOS_SENDER="a123" ``` In the above environment settings, the Transaction Wrapper is set to: -- Listen to `127.0.0.1:18888` Antelope endpoint +- Listen to `127.0.0.1:18888` - Use the `5JURSKS1BrJ1TagNBw1uVSzTQL2m9eHGkjknWeZkjSt33Awtior` key to wrap and sign the incoming ETH trasnactions into Antelope transactions and push them into the Antelope RPC endpoint `http://127.0.0.1:8888` Use the `index.js` file from https://github.com/eosnetworkfoundation/eos-evm/tree/main/peripherals/tx_wrapper: @@ -644,4 +510,4 @@ Refer to the *Setup proxy to separate read requests and write requests* section - 64 GB - AMD Ryzen 9 5950X (*or other CPU with good single threaded performance*) -- 4TB NVMe \ No newline at end of file +- 4TB NVMe diff --git a/peripherals/tx_wrapper/README.md b/peripherals/tx_wrapper/README.md index 5ba76098..cc6af93d 100644 --- a/peripherals/tx_wrapper/README.md +++ b/peripherals/tx_wrapper/README.md @@ -1,5 +1,11 @@ # evm_poc_tx_wrapper +## Prerequisite +You need to have a miner account (for example: a123) with enough CPU & NET resource. Then open the evm account balance +``` +./cleos push action eosio.evm open '{"owner":"a123"}' -p a123 +``` + ## Build ``` yarn @@ -13,13 +19,21 @@ Create a .env file: # one or more EOS_RPC endpoints, separated by '|' EOS_RPC="http://127.0.0.1:8888|http://192.168.1.1:8888" EOS_KEY="5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3" +HOST="0.0.0.0" +PORT="18888" + +# the evm contract account, eosio.evm for testnet & mainnet. +EOS_EVM_ACCOUNT="eosio.evm" -# the listening IP & port of this service -HOST="127.0.0.1" -PORT="3335" +# the miner account +EOS_SENDER="a123" + +# the miner's permission to use EOS_PERMISSION="active" + EXPIRE_SEC=60 ``` + Then ``` node index.js