diff --git a/.github/workflows/post-merge-run.yml b/.github/workflows/post-merge-run.yml index 36c4d74..7273eba 100644 --- a/.github/workflows/post-merge-run.yml +++ b/.github/workflows/post-merge-run.yml @@ -46,5 +46,8 @@ jobs: # Test vectors against Reth - name: Apply vectors to Reth run: bash ./scripts/apply_test_vectors_reth.sh + # Manual sanity checks + - name: Run EIP-1559 sanity checks + run: bash ./scripts/test_eip1559.sh diff --git a/scripts/apply_test_vectors_reth.sh b/scripts/apply_test_vectors_reth.sh index 443f6cf..e8242c8 100755 --- a/scripts/apply_test_vectors_reth.sh +++ b/scripts/apply_test_vectors_reth.sh @@ -10,6 +10,7 @@ BG_PID=$! # Set the trap to call cleanup if an error occurs cleanup() { echo "Stopping node process (PID: $BG_PID)..." + ps aux | grep "reth node" | grep -v grep | awk '{print $2}' | xargs kill kill $BG_PID 2>/dev/null || true } trap cleanup EXIT diff --git a/scripts/blocks/block_1.json b/scripts/blocks/block_1.json index 1d9aff2..66b3b4a 100644 --- a/scripts/blocks/block_1.json +++ b/scripts/blocks/block_1.json @@ -1,16 +1,16 @@ { "baseFeePerGas": "0x342770c0", - "blockHash": "0xc0f683b61355455d49af3dbb11fe1f65e9ae8670890d6fb1aadcbf5f8acc960b", + "blockHash": "0x9636978fddf349fc5e92e85b2080d99b5c3e44c745359a77e603e7f1a76f440c", "blockNumber": "0x1", "extraData": "0x4e65746865726d696e64", "feeRecipient": "0x0000000000000000000000000000000000000000", "gasLimit": "0x989680", "gasUsed": "0x0", "logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", - "parentHash": "0xa7931c99fd2b7b5e323a2fda8a2dd607cea04f03835c3f29bfe7c057c8b5672e", + "parentHash": "0x574c165efc3205be13affbd3bc165df6a6a023e21d142dd4f4c682d2aa3a054e", "prevRandao": "0x0000000000000000000000000000000000000000000000000000000000000000", "receiptsRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", - "stateRoot": "0xa59f6ea19d9ee6d7e79bcb286e6d8838b47b48351b37960e24c0a72d41fa1629", + "stateRoot": "0xe65e8c7050e23e1f25c7f56416f899b1ce15ec130ee0460b12529b92b4a8ba81", "timestamp": "0x6553f101", "transactions": [] } diff --git a/scripts/blocks/block_2.json b/scripts/blocks/block_2.json index 13829d0..2d60d0c 100644 --- a/scripts/blocks/block_2.json +++ b/scripts/blocks/block_2.json @@ -1,16 +1,16 @@ { "baseFeePerGas": "0x2da282a8", - "blockHash": "0xc314b27368528ec560d035ef9f5dc46e2aea6d21b618eeb37e91723fefdfb2d9", + "blockHash": "0xb413c62db3a7b82636aa984736933c1956d930d085d04a1b184298c76e56c786", "blockNumber": "0x2", "extraData": "0x4e65746865726d696e64", "feeRecipient": "0x0000000000000000000000000000000000000000", "gasLimit": "0x989680", "gasUsed": "0x0", "logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", - "parentHash": "0xc0f683b61355455d49af3dbb11fe1f65e9ae8670890d6fb1aadcbf5f8acc960b", + "parentHash": "0x9636978fddf349fc5e92e85b2080d99b5c3e44c745359a77e603e7f1a76f440c", "prevRandao": "0x0000000000000000000000000000000000000000000000000000000000000000", "receiptsRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", - "stateRoot": "0xa59f6ea19d9ee6d7e79bcb286e6d8838b47b48351b37960e24c0a72d41fa1629", + "stateRoot": "0xe65e8c7050e23e1f25c7f56416f899b1ce15ec130ee0460b12529b92b4a8ba81", "timestamp": "0x6553f102", "transactions": [] } diff --git a/scripts/blocks/block_3.json b/scripts/blocks/block_3.json index bb45fcc..272729e 100644 --- a/scripts/blocks/block_3.json +++ b/scripts/blocks/block_3.json @@ -1,16 +1,16 @@ { "baseFeePerGas": "0x27ee3253", - "blockHash": "0xd51a4d79676ddad8e938c38ec1344a77feefa369475acb358563f37a74a4d9d6", + "blockHash": "0xe49ebede05072552a7b99bb2e75db0e69d88640ec1dbdcf08cb3f579fd9a504d", "blockNumber": "0x3", "extraData": "0x4e65746865726d696e64", "feeRecipient": "0x0000000000000000000000000000000000000000", "gasLimit": "0x989680", "gasUsed": "0x0", "logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", - "parentHash": "0xc314b27368528ec560d035ef9f5dc46e2aea6d21b618eeb37e91723fefdfb2d9", + "parentHash": "0xb413c62db3a7b82636aa984736933c1956d930d085d04a1b184298c76e56c786", "prevRandao": "0x0000000000000000000000000000000000000000000000000000000000000000", "receiptsRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", - "stateRoot": "0xa59f6ea19d9ee6d7e79bcb286e6d8838b47b48351b37960e24c0a72d41fa1629", + "stateRoot": "0xe65e8c7050e23e1f25c7f56416f899b1ce15ec130ee0460b12529b92b4a8ba81", "timestamp": "0x6553f103", "transactions": [] } diff --git a/scripts/blocks/block_4.json b/scripts/blocks/block_4.json index 61d8deb..c711376 100644 --- a/scripts/blocks/block_4.json +++ b/scripts/blocks/block_4.json @@ -1,16 +1,16 @@ { "baseFeePerGas": "0x22f06c09", - "blockHash": "0x011405450b1431877c952c73d0ea0c964c67d006b3134aea5be7a59823e40e39", + "blockHash": "0xfc5dc793bc70c93c53fe3c37578b197b07a0173a76d5ac553f590b8da404fa81", "blockNumber": "0x4", "extraData": "0x4e65746865726d696e64", "feeRecipient": "0x0000000000000000000000000000000000000000", "gasLimit": "0x989680", "gasUsed": "0x0", "logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", - "parentHash": "0xd51a4d79676ddad8e938c38ec1344a77feefa369475acb358563f37a74a4d9d6", + "parentHash": "0xe49ebede05072552a7b99bb2e75db0e69d88640ec1dbdcf08cb3f579fd9a504d", "prevRandao": "0x0000000000000000000000000000000000000000000000000000000000000000", "receiptsRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", - "stateRoot": "0xa59f6ea19d9ee6d7e79bcb286e6d8838b47b48351b37960e24c0a72d41fa1629", + "stateRoot": "0xe65e8c7050e23e1f25c7f56416f899b1ce15ec130ee0460b12529b92b4a8ba81", "timestamp": "0x6553f104", "transactions": [] } diff --git a/scripts/blocks/block_5.json b/scripts/blocks/block_5.json index 26df740..45f7cb4 100644 --- a/scripts/blocks/block_5.json +++ b/scripts/blocks/block_5.json @@ -1,16 +1,16 @@ { "baseFeePerGas": "0x1e925e88", - "blockHash": "0x9a86f6d4d524388c300b8a09a145d0406fcf13d343ef8574c46fc0ffad9a45a0", + "blockHash": "0x656513d04face451d8c08cdfcc98f2270193f13a665b1c216c5a9c21fbcdf373", "blockNumber": "0x5", "extraData": "0x4e65746865726d696e64", "feeRecipient": "0x0000000000000000000000000000000000000000", "gasLimit": "0x989680", "gasUsed": "0x0", "logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", - "parentHash": "0x011405450b1431877c952c73d0ea0c964c67d006b3134aea5be7a59823e40e39", + "parentHash": "0xfc5dc793bc70c93c53fe3c37578b197b07a0173a76d5ac553f590b8da404fa81", "prevRandao": "0x0000000000000000000000000000000000000000000000000000000000000000", "receiptsRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", - "stateRoot": "0xa59f6ea19d9ee6d7e79bcb286e6d8838b47b48351b37960e24c0a72d41fa1629", + "stateRoot": "0xe65e8c7050e23e1f25c7f56416f899b1ce15ec130ee0460b12529b92b4a8ba81", "timestamp": "0x6553f105", "transactions": [] } diff --git a/scripts/chiado_genesis_alloc.json b/scripts/chiado_genesis_alloc.json index 58926b7..f41e729 100644 --- a/scripts/chiado_genesis_alloc.json +++ b/scripts/chiado_genesis_alloc.json @@ -415,6 +415,11 @@ "nonce": "0", "balance": "0", "code": "" + }, + "0x38e3E7Aca6762E296F659Fcb4E460a3A621dcD3D": { + "nonce": "0", + "balance": "1000000000000000000000000000000", + "code": "" } } } diff --git a/scripts/generate_test_vectors_reth.sh b/scripts/generate_test_vectors_reth.sh index 906adfd..3045a0f 100755 --- a/scripts/generate_test_vectors_reth.sh +++ b/scripts/generate_test_vectors_reth.sh @@ -18,6 +18,7 @@ BG_PID=$! # Set the trap to call cleanup if an error occurs cleanup() { echo "Stopping node process (PID: $BG_PID)..." + ps aux | grep "reth node" | grep -v grep | awk '{print $2}' | xargs kill kill $BG_PID 2>/dev/null || true } trap cleanup EXIT diff --git a/scripts/networkdata/chainspec.json b/scripts/networkdata/chainspec.json index 95eafc5..ea4131c 100644 --- a/scripts/networkdata/chainspec.json +++ b/scripts/networkdata/chainspec.json @@ -563,6 +563,10 @@ "0x0000000000000000000000000000000000000000": { "nonce": "0", "balance": "0" + }, + "0x38e3E7Aca6762E296F659Fcb4E460a3A621dcD3D": { + "nonce": "0", + "balance": "1000000000000000000000000000000" } } } diff --git a/scripts/run_reth.sh b/scripts/run_reth.sh index a99a3ca..0f7f44d 100755 --- a/scripts/run_reth.sh +++ b/scripts/run_reth.sh @@ -14,6 +14,8 @@ rm -rf $DATA_DIR # Script's directory DIR="$(dirname "$0")" +echo "Using chain file: $CHAIN_FILE" + # $PWD/target/release/reth \ cargo run -- \ node \ diff --git a/scripts/test_eip1559.sh b/scripts/test_eip1559.sh new file mode 100755 index 0000000..b042462 --- /dev/null +++ b/scripts/test_eip1559.sh @@ -0,0 +1,303 @@ +#!/bin/bash +set -e + +# Script's directory +DIR="$(dirname "$0")" + +sleep 3 + +"$DIR/run_reth.sh" & +BG_PID=$! + +# Set the trap to call cleanup if an error occurs +cleanup() { + echo "Stopping node process (PID: $BG_PID)..." + ps aux | grep "reth node" | grep -v grep | awk '{print $2}' | xargs kill + kill $BG_PID 2>/dev/null || true +} +trap cleanup EXIT + +# Retry the curl command until it succeeds +until curl -X POST -H "Content-Type: application/json" \ + --data '{"jsonrpc":"2.0","method":"eth_getBlockByNumber","params":["0x0", false],"id":1}' \ + http://localhost:8545; do + echo "Retrying..." + sleep 2 +done + +echo "EL is available" + +declare -i BLOCK_COUNTER=1 + +echo "Making block $BLOCK_COUNTER" + +HEAD_BLOCK=$(curl -X POST -H "Content-Type: application/json" \ + --data "{ + \"jsonrpc\":\"2.0\", + \"method\":\"eth_getBlockByNumber\", + \"params\":[ + \"latest\", + false + ], + \"id\":1 + }" \ + http://localhost:8545 \ +) + +HEAD_BLOCK_HASH=$(echo $HEAD_BLOCK | jq --raw-output '.result.hash') +echo HEAD_BLOCK_HASH=$HEAD_BLOCK_HASH + +# The ASCII representation of `2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a` +JWT_SECRET="********************************" +# Generate a JWT token using the secret key +# jwt is this CLI tool https://github.com/mike-engel/jwt-cli/tree/main +# iat is appended automatically +JWT_TOKEN=$(jwt encode --alg HS256 --secret "$JWT_SECRET") +echo JWT_TOKEN: $JWT_TOKEN + +TIMESTAMP=$((1700000000 + BLOCK_COUNTER)) + +# Request to produce block on current head + +RESPONSE=$(curl -X POST -H "Content-Type: application/json" \ + -H "Authorization: Bearer $JWT_TOKEN" \ + --data "{ + \"jsonrpc\":\"2.0\", + \"method\":\"engine_forkchoiceUpdatedV1\", + \"params\":[ + { + \"headBlockHash\": \"$HEAD_BLOCK_HASH\", + \"safeBlockHash\": \"0x0000000000000000000000000000000000000000000000000000000000000000\", + \"finalizedBlockHash\": \"0x0000000000000000000000000000000000000000000000000000000000000000\" + }, + { + \"timestamp\": $TIMESTAMP, + \"prevRandao\": \"0x0000000000000000000000000000000000000000000000000000000000000000\", + \"suggestedFeeRecipient\": \"0x0000000000000000000000000000000000000000\" + } + ], + \"id\":1 + }" \ + http://localhost:8546 \ +) +echo engine_forkchoiceUpdatedV1 trigger block production RESPONSE $RESPONSE + +PAYLOAD_ID=$(echo $RESPONSE | jq --raw-output '.result.payloadId') +echo PAYLOAD_ID=$PAYLOAD_ID + +echo "Sending transaction on block $BLOCK_COUNTER" + +# sending RLP encoded form of: +# transaction = { +# 'from': "0x38e3E7Aca6762E296F659Fcb4E460a3A621dcD3D", +# 'to': "0xb42a8c62f3278AFc9343A8FcCD5232CBe8aA5117", +# 'value': 1100000000, +# 'nonce': 0, +# 'gas': 200000, +# 'maxFeePerGas': 2500000000, +# 'maxPriorityFeePerGas': 2500000000, +# 'chainId': 10200 +# } +# signed using pvt key: 0x000038e28d32db8e509354d6b359eb58646e84bc942e3c79f470b08ebc976e1c + +RESPONSE=$(curl -X POST -H "Content-Type: application/json" \ + -H "Authorization: Bearer $JWT_TOKEN" \ + --data '{"jsonrpc":"2.0","method":"eth_sendRawTransaction","params":["02f8718227d880849502f900849502f90083030d4094b42a8c62f3278afc9343a8fccd5232cbe8aa5117844190ab0080c080a098913733bc37a052351fadc62ec860dc341c9f1c6876801097b42514604c7657a05d8529fba214e8562803529af696cdca2f8d5545ca05f1bd2328ef9c175f57d9"],"id":1}' \ + http://localhost:8546 \ +) +echo eth_sendRawTransaction RESPONSE $RESPONSE +TX1HASH=$(echo $RESPONSE | jq --raw-output '.result') +echo TX1HASH=$TX1HASH + +# exit if the transaction is not sent +if [ "$TX1HASH" == "null" ]; then + echo "Transaction not sent" + exit 1 +fi + +# sending RLP encoded form of: +# transaction = { +# 'from': "0x38e3E7Aca6762E296F659Fcb4E460a3A621dcD3D", +# 'to': "0xc390cC49a32736a58733Cf46bE42f734dD4f53cb", +# 'value': 1000000000, +# 'nonce': 1, +# 'gas': 200000, +# 'maxFeePerGas': 2000000000, +# 'maxPriorityFeePerGas': 1000000000, +# 'chainId': 10200 +# } +# signed using pvt key: 0x000038e28d32db8e509354d6b359eb58646e84bc942e3c79f470b08ebc976e1c + +RESPONSE=$(curl -X POST -H "Content-Type: application/json" \ + -H "Authorization: Bearer $JWT_TOKEN" \ + --data '{"jsonrpc":"2.0","method":"eth_sendRawTransaction","params":["02f8708227d801849502f900849502f90083030d4094b42a8c62f3278afc9343a8fccd5232cbe8aa5117844190ab0080c0809fe483006f558948cb15b00a3f17c706f2c6ae084c131fca3a84042b23be3f51a05c550f5d70d8c6deb405250cb75e68d5c7daee4e7c202d841df0338b9fcd0838"],"id":2}' \ + http://localhost:8546 \ +) +echo eth_sendRawTransaction RESPONSE $RESPONSE +TX2HASH=$(echo $RESPONSE | jq --raw-output '.result') +echo TX2HASH=$TX2HASH + +if [ "$TX2HASH" == "null" ]; then + echo "Transaction not sent" + exit 1 +fi + +# sleep for 1 sec +sleep 1 + +# Fetch producing block by payload ID + +RESPONSE=$(curl -X POST -H "Content-Type: application/json" \ + -H "Authorization: Bearer $JWT_TOKEN" \ + --data "{ + \"jsonrpc\":\"2.0\", + \"method\":\"engine_getPayloadV1\", + \"params\":[ + \"$PAYLOAD_ID\" + ], + \"id\":1 + }" \ + http://localhost:8546 \ +) +echo engine_getPayloadV1 RESPONSE $RESPONSE + +BLOCK=$(echo $RESPONSE | jq '.result') +# BLOCK_NUMBER_HEX = 0x1, 0x2, etc +BLOCK_NUMBER_HEX_PREFIX=$(echo $BLOCK | jq --raw-output '.blockNumber') +BLOCK_NUMBER_HEX=${BLOCK_NUMBER_HEX_PREFIX#"0x"} +BLOCK_NUMBER=$((16#$BLOCK_NUMBER_HEX)) +BLOCK_HASH=$(echo $BLOCK | jq --raw-output '.blockHash') + +# send the new block as payload + +RESPONSE=$(curl -X POST -H "Content-Type: application/json" \ + -H "Authorization: Bearer $JWT_TOKEN" \ + --data "{ + \"jsonrpc\":\"2.0\", + \"method\":\"engine_newPayloadV1\", + \"params\":[ + $BLOCK + ], + \"id\":1 + }" \ + http://localhost:8546 \ +) +echo engine_newPayloadV1 with new block RESPONSE $RESPONSE + + +# set the block as head + +RESPONSE=$(curl -X POST -H "Content-Type: application/json" \ + -H "Authorization: Bearer $JWT_TOKEN" \ + --data "{ + \"jsonrpc\":\"2.0\", + \"method\":\"engine_forkchoiceUpdatedV1\", + \"params\":[ + { + \"headBlockHash\": \"$BLOCK_HASH\", + \"safeBlockHash\": \"0x0000000000000000000000000000000000000000000000000000000000000000\", + \"finalizedBlockHash\": \"0x0000000000000000000000000000000000000000000000000000000000000000\" + }, + null + ], + \"id\":1 + }" \ + http://localhost:8546 \ +) +echo engine_forkchoiceUpdatedV1 set new block as head RESPONSE $RESPONSE + +HEAD_BLOCK=$(curl -X POST -H "Content-Type: application/json" \ + --data "{ + \"jsonrpc\":\"2.0\", + \"method\":\"eth_getBlockByNumber\", + \"params\":[ + \"latest\", + false + ], + \"id\":1 + }" \ + http://localhost:8545 \ +) +echo HEAD_BLOCK $HEAD_BLOCK + +BASE_FEE_PER_GAS_HEX_PREFIX=$(echo $HEAD_BLOCK | jq --raw-output '.result.baseFeePerGas') +BASE_FEE_PER_GAS_HEX=${BASE_FEE_PER_GAS_HEX_PREFIX#"0x"} +BASE_FEE_PER_GAS=$((16#$BASE_FEE_PER_GAS_HEX)) + +GAS_USED_HEX_PREFIX=$(echo $HEAD_BLOCK | jq --raw-output '.result.gasUsed') +GAS_USED_HEX=${GAS_USED_HEX_PREFIX#"0x"} +GAS_USED=$((16#$GAS_USED_HEX)) + +echo DECIMAL BASE_FEE_PER_GAS $BASE_FEE_PER_GAS GAS_USED $GAS_USED + +TX1RECEIPT=$(curl http://localhost:8545 \ + -X POST \ + -H "Content-Type: application/json" \ + -H "Authorization: Bearer $JWT_TOKEN" \ + --data '{"method":"eth_getTransactionReceipt","params":["'$TX1HASH'"],"id":1,"jsonrpc":"2.0"}' +) +echo eth_getTransactionReceipt "0x1" RESPONSE $TX1RECEIPT + +TX1_EFF_GAS_PRICE_HEX_PREFIX=$(echo $TX1RECEIPT | jq --raw-output '.result.effectiveGasPrice') +TX1_EFF_GAS_PRICE_HEX=${TX1_EFF_GAS_PRICE_HEX_PREFIX#"0x"} +TX1_EFF_GAS_PRICE=$((16#$TX1_EFF_GAS_PRICE_HEX)) + +TX1_GAS_USED_HEX_PREFIX=$(echo $TX1RECEIPT | jq --raw-output '.result.gasUsed') +TX1_GAS_USED_HEX=${TX1_GAS_USED_HEX_PREFIX#"0x"} +TX1_GAS_USED=$((16#$TX1_GAS_USED_HEX)) + +TX2RECEIPT=$(curl http://localhost:8545 \ + -X POST \ + -H "Content-Type: application/json" \ + -H "Authorization: Bearer $JWT_TOKEN" \ + --data '{"method":"eth_getTransactionReceipt","params":["'$TX2HASH'"],"id":1,"jsonrpc":"2.0"}' +) +echo eth_getTransactionReceipt "0x1" RESPONSE $TX2RECEIPT + +TX2_EFF_GAS_PRICE_HEX_PREFIX=$(echo $TX2RECEIPT | jq --raw-output '.result.effectiveGasPrice') +TX2_EFF_GAS_PRICE_HEX=${TX2_EFF_GAS_PRICE_HEX_PREFIX#"0x"} +TX2_EFF_GAS_PRICE=$((16#$TX2_EFF_GAS_PRICE_HEX)) + +TX2_GAS_USED_HEX_PREFIX=$(echo $TX2RECEIPT | jq --raw-output '.result.gasUsed') +TX2_GAS_USED_HEX=${TX2_GAS_USED_HEX_PREFIX#"0x"} +TX2_GAS_USED=$((16#$TX2_GAS_USED_HEX)) + +echo TX1_EFF_GAS_PRICE $TX1_EFF_GAS_PRICE TX2_EFF_GAS_PRICE $TX2_EFF_GAS_PRICE + +RESPONSE=$(curl -X POST -H "Content-Type: application/json" --data '{"jsonrpc":"2.0","method":"eth_getBalance","params":["0x1559000000000000000000000000000000000000", "latest"],"id":1}' http://localhost:8545) +echo collector balance RESPONSE $RESPONSE + +COLLECTOR_BALANCE_HEX_PREFIX=$(echo $RESPONSE | jq --raw-output '.result') +COLLECTOR_BALANCE_HEX=${COLLECTOR_BALANCE_HEX_PREFIX#"0x"} +COLLECTOR_BALANCE=$((16#$COLLECTOR_BALANCE_HEX)) + +RESPONSE=$(curl -X POST -H "Content-Type: application/json" --data '{"jsonrpc":"2.0","method":"eth_getBalance","params":["0x0000000000000000000000000000000000000000", "latest"],"id":1}' http://localhost:8545) +echo fee_recipient balance RESPONSE $RESPONSE + +FEE_RECIPIENT_BALANCE_HEX_PREFIX=$(echo $RESPONSE | jq --raw-output '.result') +FEE_RECIPIENT_BALANCE_HEX=${FEE_RECIPIENT_BALANCE_HEX_PREFIX#"0x"} +FEE_RECIPIENT_BALANCE=$((16#$FEE_RECIPIENT_BALANCE_HEX)) + +TIP_1_FEE=$((TX1_EFF_GAS_PRICE - BASE_FEE_PER_GAS)) +TIP_1=$((TIP_1_FEE * TX1_GAS_USED)) + +TIP_2_FEE=$((TX2_EFF_GAS_PRICE - BASE_FEE_PER_GAS)) +TIP_2=$((TIP_2_FEE * TX2_GAS_USED)) + +TOTAL_TIP=$((TIP_1 + TIP_2)) +echo TOTAL_TIP $TOTAL_TIP + +TOTAL_BASE_FEE=$((BASE_FEE_PER_GAS * GAS_USED)) +echo TOTAL_BASE_FEE $TOTAL_BASE_FEE + +if ((COLLECTOR_BALANCE != TOTAL_BASE_FEE)); then + echo "Collector balance is not equal to total base fee" + exit 1 +fi + +if ((FEE_RECIPIENT_BALANCE != TOTAL_TIP)); then + echo "Fee recipient balance is not equal to total tip" + exit 1 +fi + +echo "Collector balance is equal to total base fee and fee recipient balance is equal to total tip" \ No newline at end of file