From 74750ab82796669e621fd07d2e04e89a9aa4c8f2 Mon Sep 17 00:00:00 2001 From: debjit Date: Wed, 6 Nov 2024 22:05:18 +0530 Subject: [PATCH 1/8] logic changes --- src/execute.rs | 8 ++---- src/payload_builder.rs | 64 ++++++++++++++++++------------------------ 2 files changed, 30 insertions(+), 42 deletions(-) diff --git a/src/execute.rs b/src/execute.rs index 14b9305..7fb81cc 100644 --- a/src/execute.rs +++ b/src/execute.rs @@ -231,7 +231,7 @@ where fn apply_post_execution_changes( &mut self, block: &BlockWithSenders, - total_difficulty: U256, + _total_difficulty: U256, receipts: &[Receipt], ) -> Result { let cfg = CfgEnvWithHandlerCfg::new(Default::default(), Default::default()); @@ -249,9 +249,6 @@ where block.beneficiary, )?; - let env = self.evm_env_for_block(&block.header, total_difficulty); - let mut evm = self.evm_config.evm_with_env(&mut self.state, env); - let requests = if self .chain_spec .is_prague_active_at_timestamp(block.timestamp) @@ -259,8 +256,7 @@ where // Collect all EIP-6110 deposits let deposit_requests = parse_deposits_from_receipts(&self.chain_spec, receipts)?; - let mut requests = Requests::new(vec![deposit_requests]); - requests.extend(self.system_caller.apply_post_execution_changes(&mut evm)?); + let requests = Requests::new(vec![deposit_requests]); requests } else { Requests::default() diff --git a/src/payload_builder.rs b/src/payload_builder.rs index 852785b..ce3f924 100644 --- a/src/payload_builder.rs +++ b/src/payload_builder.rs @@ -18,7 +18,7 @@ use reth::{ transaction_pool::{noop::NoopTransactionPool, BestTransactionsAttributes, TransactionPool}, }; use reth_basic_payload_builder::{ - commit_withdrawals, is_better_payload, BasicPayloadJobGenerator, + is_better_payload, BasicPayloadJobGenerator, BasicPayloadJobGeneratorConfig, BuildArguments, BuildOutcome, PayloadBuilder, PayloadConfig, WithdrawalsOutcome, }; @@ -423,34 +423,6 @@ where }); } - // calculate the requests and the requests root - let requests = if chain_spec.is_prague_active_at_timestamp(attributes.timestamp) { - let deposit_requests = parse_deposits_from_receipts(&chain_spec, receipts.iter().flatten()) - .map_err(|err| PayloadBuilderError::Internal(RethError::Execution(err.into())))?; - let withdrawal_requests = system_caller - .post_block_withdrawal_requests_contract_call( - &mut db, - &initialized_cfg, - &initialized_block_env, - ) - .map_err(|err| PayloadBuilderError::Internal(err.into()))?; - let consolidation_requests = system_caller - .post_block_consolidation_requests_contract_call( - &mut db, - &initialized_cfg, - &initialized_block_env, - ) - .map_err(|err| PayloadBuilderError::Internal(err.into()))?; - - Some(Requests::new(vec![ - deposit_requests, - withdrawal_requests, - consolidation_requests, - ])) - } else { - None - }; - // < GNOSIS SPECIFIC apply_post_block_system_calls( &chain_spec, @@ -466,15 +438,36 @@ where .map_err(|err| PayloadBuilderError::Internal(err.into()))?; // GNOSIS SPECIFIC > + // calculate the requests and the requests root + let requests = if chain_spec.is_prague_active_at_timestamp(attributes.timestamp) { + let deposit_requests = parse_deposits_from_receipts(&chain_spec, receipts.iter().flatten()) + .map_err(|err| PayloadBuilderError::Internal(RethError::Execution(err.into())))?; + + println!("debjit debug (payload) requests (building): {:?}", Requests::new(vec![ + deposit_requests.clone(), + ])); + + Some(Requests::new(vec![deposit_requests])) + } else { + None + }; + let WithdrawalsOutcome { withdrawals_root, withdrawals, - } = commit_withdrawals( - &mut db, - &chain_spec, - attributes.timestamp, - attributes.withdrawals, - )?; + } = if !chain_spec.is_shanghai_active_at_timestamp(attributes.timestamp) { + WithdrawalsOutcome::pre_shanghai() + } else if attributes.withdrawals.is_empty() { + WithdrawalsOutcome::empty() + } else { + let withdrawals_root = proofs::calculate_withdrawals_root(&attributes.withdrawals); + + // calculate withdrawals root + WithdrawalsOutcome { + withdrawals: Some(attributes.withdrawals), + withdrawals_root: Some(withdrawals_root), + } + }; // merge all transitions into bundle state, this would apply the withdrawal balance changes // and 4788 contract call @@ -580,7 +573,6 @@ where }; let sealed_block = block.seal_slow(); - debug!(target: "payload_builder", ?sealed_block, "sealed built block"); // create the executed block data let executed = ExecutedBlock { From edd85cfc8d47d402962d2a76a25dbe8bcf16d46f Mon Sep 17 00:00:00 2001 From: debjit Date: Mon, 11 Nov 2024 12:51:55 +0700 Subject: [PATCH 2/8] withdrawals test script --- scripts/chiado_genesis_alloc.json | 3 + scripts/withdrawals.sh | 478 ++++++++++++++++++++++++++++++ 2 files changed, 481 insertions(+) create mode 100755 scripts/withdrawals.sh diff --git a/scripts/chiado_genesis_alloc.json b/scripts/chiado_genesis_alloc.json index f41e729..47aa154 100644 --- a/scripts/chiado_genesis_alloc.json +++ b/scripts/chiado_genesis_alloc.json @@ -1,6 +1,9 @@ { "config": { "chainId": 10200, + "depositContractAddress": + "0x566b8783a28a46dc8d88ebf712303938985e121e", + "consensus": "aura", "homesteadBlock": 0, "eip150Block": 0, diff --git a/scripts/withdrawals.sh b/scripts/withdrawals.sh new file mode 100755 index 0000000..206cd2c --- /dev/null +++ b/scripts/withdrawals.sh @@ -0,0 +1,478 @@ +#!/bin/bash +set -e + +# Script's directory +DIR="$(dirname "$0")" + +# sleep 3 + +"$DIR/run_reth.sh" & +# $DIR/run_nethermind.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 + docker rm -f neth-vec-gen 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=$((19999999999 + 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_forkchoiceUpdatedV3\", + \"params\":[ + { + \"headBlockHash\": \"$HEAD_BLOCK_HASH\", + \"safeBlockHash\": \"0x0000000000000000000000000000000000000000000000000000000000000000\", + \"finalizedBlockHash\": \"0x0000000000000000000000000000000000000000000000000000000000000000\" + }, + { + \"timestamp\": $TIMESTAMP, + \"prevRandao\": \"0x0000000000000000000000000000000000000000000000000000000000000000\", + \"suggestedFeeRecipient\": \"0x0000000000000000000000000000000000000000\", + \"withdrawals\": [], + \"parentBeaconBlockRoot\": \"0x11f780a954bcba8889998e4e61deaae6388dd2391e9c810bd9c94962cc1eadc1\" + } + ], + \"id\":1 + }" \ + http://localhost:8546 \ +) +echo engine_forkchoiceUpdatedV3 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" + +RESPONSE=$(curl -X POST -H "Content-Type: application/json" \ + -H "Authorization: Bearer $JWT_TOKEN" \ + --data '{"jsonrpc":"2.0","method":"eth_sendRawTransaction","params":["f938098083989680830f42408080b937b860a06040523480156200001157600080fd5b506040516200379838038062003798833981016040819052620000349162000050565b6000805460ff191690556001600160a01b031660805262000082565b6000602082840312156200006357600080fd5b81516001600160a01b03811681146200007b57600080fd5b9392505050565b6080516136d0620000c86000396000818161020401528181610415015281816105d80152818161078101528181610b2f01528181610b78015261158d01526136d06000f3fe608060405234801561001057600080fd5b50600436106101365760003560e01c806369ffa08a116100b2578063a4c0ed3611610081578063be7ab51b11610066578063be7ab51b146102b2578063c5f2892f146102d2578063c82655b7146102da57600080fd5b8063a4c0ed361461028c578063bb30b8fd1461029f57600080fd5b806369ffa08a1461024b57806379d0c0bc1461025e5780638456cb5914610271578063a3066aab1461027957600080fd5b80633f4ba83a116101095780635c975abb116100ee5780635c975abb146101df578063621fd130146101ea578063640415bf146101ff57600080fd5b80633f4ba83a146101c45780634694bd1e146101cc57600080fd5b806301ffc9a71461013b5780630cac9f311461016357806324db4c4614610178578063319ebe9c146101b1575b600080fd5b61014e610149366004612b43565b6102ed565b60405190151581526020015b60405180910390f35b610176610171366004612c66565b6103d2565b005b6101a3610186366004612d00565b805160208183018101805160428252928201919093012091525481565b60405190815260200161015a565b6101766101bf366004612d81565b6104bb565b6101766104cf565b6101766101da366004612e12565b610532565b60005460ff1661014e565b6101f26106fd565b60405161015a9190612ec1565b6102267f000000000000000000000000000000000000000000000000000000000000000081565b60405173ffffffffffffffffffffffffffffffffffffffff909116815260200161015a565b610176610259366004612e12565b61070f565b61017661026c366004612ed4565b610857565b610176610a75565b610176610287366004612f4e565b610ad6565b61014e61029a366004612fad565b610b56565b6101766102ad366004612ffd565b611010565b6101a36102c0366004612f4e565b60436020526000908152604090205481565b6101a3611055565b6101766102e836600461303f565b611284565b60007fffffffff0000000000000000000000000000000000000000000000000000000082167f01ffc9a700000000000000000000000000000000000000000000000000000000148061038057507fffffffff0000000000000000000000000000000000000000000000000000000082167fab41c72e00000000000000000000000000000000000000000000000000000000145b806103cc57507fffffffff0000000000000000000000000000000000000000000000000000000082167fa4c0ed3600000000000000000000000000000000000000000000000000000000145b92915050565b6103da6117d5565b6040517f23b872dd000000000000000000000000000000000000000000000000000000008152336004820152306024820152604481018290527f000000000000000000000000000000000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff16906323b872dd90606401602060405180830381600087803b15801561046e57600080fd5b505af1158015610482573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906104a69190613103565b506104b48585858585611842565b5050505050565b6104c9600085858585610857565b50505050565b7fb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d61035473ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff161461052857600080fd5b6105306122c5565b565b7fb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d61035473ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff161461058b57600080fd5b6040517f70a0823100000000000000000000000000000000000000000000000000000000815230600482015273ffffffffffffffffffffffffffffffffffffffff808416916339f47693917f000000000000000000000000000000000000000000000000000000000000000091908516906370a082319060240160206040518083038186803b15801561061d57600080fd5b505afa158015610631573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906106559190613125565b6040517fffffffff0000000000000000000000000000000000000000000000000000000060e085901b16815273ffffffffffffffffffffffffffffffffffffffff90921660048301526024820152604401602060405180830381600087803b1580156106c057600080fd5b505af11580156106d4573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906106f89190613125565b505050565b606061070a604154612342565b905090565b7fb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d61035473ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff161461076857600080fd5b8173ffffffffffffffffffffffffffffffffffffffff167f000000000000000000000000000000000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff161415610849576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152603360248201527f4465706f736974436f6e74726163743a206e6f7420616c6c6f77656420746f2060448201527f636c61696d206465706f73697420746f6b656e0000000000000000000000000060648201526084015b60405180910390fd5b61085382826125b6565b5050565b3373fffffffffffffffffffffffffffffffffffffffe14806108c557507fb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d61035473ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16145b610977576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152604d60248201527f546869732066756e6374696f6e2073686f756c642062652063616c6c6564206f60448201527f6e6c792062792053595354454d5f5749544844524157414c5f4558454355544f60648201527f52206f72205f61646d696e282900000000000000000000000000000000000000608482015260a401610840565b8281146109865761098661313e565b60005b83811015610a6d57600060208686848181106109a7576109a761316d565b90506020020160208101906109bc919061319c565b6109d49067ffffffffffffffff16633b9aca006131f5565b6109de9190613261565b905080604360008686868181106109f7576109f761316d565b9050602002016020810190610a0c9190612f4e565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000828254610a559190613275565b90915550610a66915082905061328d565b9050610989565b505050505050565b7fb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d61035473ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614610ace57600080fd5b6105306125e4565b73ffffffffffffffffffffffffffffffffffffffff811660009081526043602052604090205480156108535773ffffffffffffffffffffffffffffffffffffffff808316600090815260436020526040812055610853907f000000000000000000000000000000000000000000000000000000000000000016838361263f565b6000610b606117d5565b3373ffffffffffffffffffffffffffffffffffffffff7f00000000000000000000000000000000000000000000000000000000000000001614610c24576040517f08c379a0000000000000000000000000000000000000000000000000000000008152602060048201526024808201527f4465706f736974436f6e74726163743a206e6f742061206465706f736974207460448201527f6f6b656e000000000000000000000000000000000000000000000000000000006064820152608401610840565b610c2f60b0836132c6565b602014610cbe576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602e60248201527f4465706f736974436f6e74726163743a20696e636f7272656374206465706f7360448201527f69742064617461206c656e6774680000000000000000000000000000000000006064820152608401610840565b6000610ccb60b084613261565b905060008111610d5d576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152603760248201527f42617463684465706f7369743a20596f752073686f756c64206465706f73697460448201527f206174206c65617374206f6e652076616c696461746f720000000000000000006064820152608401610840565b846001821115610ea3576080821115610df8576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152603a60248201527f42617463684465706f7369743a20596f752063616e206465706f736974206d6160448201527f78203132382076616c696461746f727320617420612074696d650000000000006064820152608401610840565b610e0a82670de0b6b3a76400006131f5565b8614610e98576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152603960248201527f42617463684465706f7369743a206261746368206465706f736974732072657160448201527f75697265203120474e4f206465706f73697420616d6f756e74000000000000006064820152608401610840565b50670de0b6b3a76400005b6000610eb260208287896132da565b8080601f0160208091040260200160405190810160405280939291908181526020018383808284376000920191909152509293506020925050505b85811015610fff576000878288610f05826030613275565b92610f12939291906132da565b8080601f01602080910402602001604051908101604052809392919081815260200183838082843760009201829052509394508b92508a9150610f589050856030613275565b90610f64866090613275565b92610f71939291906132da565b8080601f01602080910402602001604051908101604052809392919081815260200183838082843760009201829052509394508c92508b9150610fb79050866090613275565b90610fc38760b0613275565b92610fd0939291906132da565b610fd991613304565b9050610fe8838684848a611842565b50505060b081610ff89190613275565b9050610eed565b50600193505050505b949350505050565b60005b818110156106f8576110458383838181106110305761103061316d565b90506020020160208101906102879190612f4e565b61104e8161328d565b9050611013565b6041546000908190815b60208110156111e257816001166001141561111e576002602182602081106110895761108961316d565b01546040805160208101929092528101859052606001604080517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0818403018152908290526110d791613340565b602060405180830381855afa1580156110f4573d6000803e3d6000fd5b5050506040513d601f19601f820116820180604052508101906111179190613125565b92506111c3565b600283600183602081106111345761113461316d565b0154604080516020810193909352820152606001604080517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe08184030181529082905261118091613340565b602060405180830381855afa15801561119d573d6000803e3d6000fd5b5050506040513d601f19601f820116820180604052508101906111c09190613125565b92505b6111ce600283613261565b9150806111da8161328d565b91505061105f565b506002826111f1604154612342565b60405161120592919060009060200161335c565b604080517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe08184030181529082905261123d91613340565b602060405180830381855afa15801561125a573d6000803e3d6000fd5b5050506040513d601f19601f8201168201806040525081019061127d9190613125565b9250505090565b61128c6117d5565b808061131a576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152603760248201527f42617463684465706f7369743a20596f752073686f756c64206465706f73697460448201527f206174206c65617374206f6e652076616c696461746f720000000000000000006064820152608401610840565b60808111156113ab576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152603a60248201527f42617463684465706f7369743a20596f752063616e206465706f736974206d6160448201527f78203132382076616c696461746f727320617420612074696d650000000000006064820152608401610840565b6113b68160306131f5565b8814611444576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602660248201527f42617463684465706f7369743a205075626b657920636f756e7420646f6e277460448201527f206d6174636800000000000000000000000000000000000000000000000000006064820152608401610840565b61144f8160606131f5565b84146114dd576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602a60248201527f42617463684465706f7369743a205369676e61747572657320636f756e74206460448201527f6f6e2774206d61746368000000000000000000000000000000000000000000006064820152608401610840565b6020861461156d576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152603660248201527f42617463684465706f7369743a205769746864726177616c2043726564656e7460448201527f69616c7320636f756e7420646f6e2774206d61746368000000000000000000006064820152608401610840565b670de0b6b3a764000073ffffffffffffffffffffffffffffffffffffffff7f0000000000000000000000000000000000000000000000000000000000000000166323b872dd33306115be86866131f5565b6040517fffffffff0000000000000000000000000000000000000000000000000000000060e086901b16815273ffffffffffffffffffffffffffffffffffffffff93841660048201529290911660248301526044820152606401602060405180830381600087803b15801561163257600080fd5b505af1158015611646573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061166a9190613103565b5060005b828110156117c85760008b8b6116858460306131f5565b90611691856001613275565b61169c9060306131f5565b926116a9939291906132da565b8080601f01602080910402602001604051908101604052809392919081815260200183838082843760009201829052509394508b92508a91506116ef90508560606131f5565b906116fb866001613275565b6117069060606131f5565b92611713939291906132da565b8080601f016020809104026020016040519081016040528093929190818152602001838380828437600081840152601f19601f8201169050808301925050505050505090506117b5828c8c8080601f0160208091040260200160405190810160405280939291908181526020018383808284376000920191909152508692508c91508b9050888181106117a8576117a861316d565b9050602002013588611842565b5050806117c19061328d565b905061166e565b5050505050505050505050565b60005460ff1615610530576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601060248201527f5061757361626c653a20706175736564000000000000000000000000000000006044820152606401610840565b61184d8160206131f5565b905084516030146118e0576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602660248201527f4465706f736974436f6e74726163743a20696e76616c6964207075626b65792060448201527f6c656e67746800000000000000000000000000000000000000000000000000006064820152608401610840565b8351602014611971576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152603660248201527f4465706f736974436f6e74726163743a20696e76616c6964207769746864726160448201527f77616c5f63726564656e7469616c73206c656e677468000000000000000000006064820152608401610840565b8251606014611a02576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602960248201527f4465706f736974436f6e74726163743a20696e76616c6964207369676e61747560448201527f7265206c656e67746800000000000000000000000000000000000000000000006064820152608401610840565b670de0b6b3a7640000811015611a9a576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602660248201527f4465706f736974436f6e74726163743a206465706f7369742076616c7565207460448201527f6f6f206c6f7700000000000000000000000000000000000000000000000000006064820152608401610840565b611aa8633b9aca00826132c6565b15611b35576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152603360248201527f4465706f736974436f6e74726163743a206465706f7369742076616c7565206e60448201527f6f74206d756c7469706c65206f662067776569000000000000000000000000006064820152608401610840565b6000611b45633b9aca0083613261565b905067ffffffffffffffff811115611bdf576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602760248201527f4465706f736974436f6e74726163743a206465706f7369742076616c7565207460448201527f6f6f2068696768000000000000000000000000000000000000000000000000006064820152608401610840565b6000611bea82612342565b90507f649bbc62d0e31342afea4e5cd82d4049e7e1ee912fc0889aa790803be39038c587878388611c1c604154612342565b604051611c2d9594939291906133b0565b60405180910390a16000600288600060801b604051602001611c5092919061341d565b604080517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe081840301815290829052611c8891613340565b602060405180830381855afa158015611ca5573d6000803e3d6000fd5b5050506040513d601f19601f82011682018060405250810190611cc89190613125565b9050600086806020019051810190611ce09190613464565b90506000600280838360200201518460016020020151604051602001611d10929190918252602082015260400190565b604080517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe081840301815290829052611d4891613340565b602060405180830381855afa158015611d65573d6000803e3d6000fd5b5050506040513d601f19601f82011682018060405250810190611d889190613125565b60408481015181516020810191909152600081830152815180820383018152606090910191829052600291611dbd9190613340565b602060405180830381855afa158015611dda573d6000803e3d6000fd5b5050506040513d601f19601f82011682018060405250810190611dfd9190613125565b604080516020810193909352820152606001604080517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe081840301815290829052611e4791613340565b602060405180830381855afa158015611e64573d6000803e3d6000fd5b5050506040513d601f19601f82011682018060405250810190611e879190613125565b90506000600280858c604051602001611ea19291906134e2565b604080517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe081840301815290829052611ed991613340565b602060405180830381855afa158015611ef6573d6000803e3d6000fd5b5050506040513d601f19601f82011682018060405250810190611f199190613125565b604051600290611f329089906000908890602001613508565b604080517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe081840301815290829052611f6a91613340565b602060405180830381855afa158015611f87573d6000803e3d6000fd5b5050506040513d601f19601f82011682018060405250810190611faa9190613125565b604080516020810193909352820152606001604080517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe081840301815290829052611ff491613340565b602060405180830381855afa158015612011573d6000803e3d6000fd5b5050506040513d601f19601f820116820180604052508101906120349190613125565b90508781146120eb576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152605460248201527f4465706f736974436f6e74726163743a207265636f6e7374727563746564204460448201527f65706f7369744461746120646f6573206e6f74206d6174636820737570706c6960648201527f6564206465706f7369745f646174615f726f6f74000000000000000000000000608482015260a401610840565b60016120f960206002613677565b6121039190613683565b60415410612193576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602160248201527f4465706f736974436f6e74726163743a206d65726b6c6520747265652066756c60448201527f6c000000000000000000000000000000000000000000000000000000000000006064820152608401610840565b6001604160008282546121a69190613275565b909155505060415460005b60208110156122ae5781600116600114156121ea5782602182602081106121da576121da61316d565b0155506104b49650505050505050565b6002602182602081106121ff576121ff61316d565b01546040805160208101929092528101859052606001604080517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe08184030181529082905261224d91613340565b602060405180830381855afa15801561226a573d6000803e3d6000fd5b5050506040513d601f19601f8201168201806040525081019061228d9190613125565b925061229a600283613261565b9150806122a68161328d565b9150506121b1565b506122b761313e565b505050505050505050505050565b6122cd6126cc565b600080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff001690557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa335b60405173ffffffffffffffffffffffffffffffffffffffff909116815260200160405180910390a1565b60408051600880825281830190925260609160208201818036833701905050905060c082901b8060071a60f81b826000815181106123825761238261316d565b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a9053508060061a60f81b826001815181106123cb576123cb61316d565b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a9053508060051a60f81b826002815181106124145761241461316d565b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a9053508060041a60f81b8260038151811061245d5761245d61316d565b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a9053508060031a60f81b826004815181106124a6576124a661316d565b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a9053508060021a60f81b826005815181106124ef576124ef61316d565b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a9053508060011a60f81b826006815181106125385761253861316d565b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a9053508060001a60f81b826007815181106125815761258161316d565b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a90535050919050565b73ffffffffffffffffffffffffffffffffffffffff82166125da5761085381612738565b610853828261277d565b6125ec6117d5565b600080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff001660011790557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a2586123183390565b6040805173ffffffffffffffffffffffffffffffffffffffff8416602482015260448082018490528251808303909101815260649091019091526020810180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167fa9059cbb000000000000000000000000000000000000000000000000000000001790526106f89084906128c9565b60005460ff16610530576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601460248201527f5061757361626c653a206e6f74207061757365640000000000000000000000006044820152606401610840565b604051479073ffffffffffffffffffffffffffffffffffffffff83169082156108fc029083906000818181858888f193505050501580156106f8573d6000803e3d6000fd5b6040517f70a0823100000000000000000000000000000000000000000000000000000000815230600482015260009073ffffffffffffffffffffffffffffffffffffffff8416906370a082319060240160206040518083038186803b1580156127e557600080fd5b505afa1580156127f9573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061281d9190613125565b6040517fa9059cbb00000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff8481166004830152602482018390529192509084169063a9059cbb90604401602060405180830381600087803b15801561289157600080fd5b505af11580156128a5573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906104c99190613103565b600061292b826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c65648152508573ffffffffffffffffffffffffffffffffffffffff166129d59092919063ffffffff16565b8051909150156106f857808060200190518101906129499190613103565b6106f8576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e60448201527f6f742073756363656564000000000000000000000000000000000000000000006064820152608401610840565b60606110088484600085856000808673ffffffffffffffffffffffffffffffffffffffff168587604051612a099190613340565b60006040518083038185875af1925050503d8060008114612a46576040519150601f19603f3d011682016040523d82523d6000602084013e612a4b565b606091505b5091509150612a5c87838387612a67565b979650505050505050565b60608315612afa578251612af35773ffffffffffffffffffffffffffffffffffffffff85163b612af3576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606401610840565b5081611008565b6110088383815115612b0f5781518083602001fd5b806040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016108409190612ec1565b600060208284031215612b5557600080fd5b81357fffffffff0000000000000000000000000000000000000000000000000000000081168114612b8557600080fd5b9392505050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b600082601f830112612bcc57600080fd5b813567ffffffffffffffff80821115612be757612be7612b8c565b604051601f83017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0908116603f01168101908282118183101715612c2d57612c2d612b8c565b81604052838152866020858801011115612c4657600080fd5b836020870160208301376000602085830101528094505050505092915050565b600080600080600060a08688031215612c7e57600080fd5b853567ffffffffffffffff80821115612c9657600080fd5b612ca289838a01612bbb565b96506020880135915080821115612cb857600080fd5b612cc489838a01612bbb565b95506040880135915080821115612cda57600080fd5b50612ce788828901612bbb565b9598949750949560608101359550608001359392505050565b600060208284031215612d1257600080fd5b813567ffffffffffffffff811115612d2957600080fd5b61100884828501612bbb565b60008083601f840112612d4757600080fd5b50813567ffffffffffffffff811115612d5f57600080fd5b6020830191508360208260051b8501011115612d7a57600080fd5b9250929050565b60008060008060408587031215612d9757600080fd5b843567ffffffffffffffff80821115612daf57600080fd5b612dbb88838901612d35565b90965094506020870135915080821115612dd457600080fd5b50612de187828801612d35565b95989497509550505050565b73ffffffffffffffffffffffffffffffffffffffff81168114612e0f57600080fd5b50565b60008060408385031215612e2557600080fd5b8235612e3081612ded565b91506020830135612e4081612ded565b809150509250929050565b60005b83811015612e66578181015183820152602001612e4e565b838111156104c95750506000910152565b60008151808452612e8f816020860160208601612e4b565b601f017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0169290920160200192915050565b602081526000612b856020830184612e77565b600080600080600060608688031215612eec57600080fd5b85359450602086013567ffffffffffffffff80821115612f0b57600080fd5b612f1789838a01612d35565b90965094506040880135915080821115612f3057600080fd5b50612f3d88828901612d35565b969995985093965092949392505050565b600060208284031215612f6057600080fd5b8135612b8581612ded565b60008083601f840112612f7d57600080fd5b50813567ffffffffffffffff811115612f9557600080fd5b602083019150836020828501011115612d7a57600080fd5b60008060008060608587031215612fc357600080fd5b8435612fce81612ded565b935060208501359250604085013567ffffffffffffffff811115612ff157600080fd5b612de187828801612f6b565b6000806020838503121561301057600080fd5b823567ffffffffffffffff81111561302757600080fd5b61303385828601612d35565b90969095509350505050565b6000806000806000806000806080898b03121561305b57600080fd5b883567ffffffffffffffff8082111561307357600080fd5b61307f8c838d01612f6b565b909a50985060208b013591508082111561309857600080fd5b6130a48c838d01612f6b565b909850965060408b01359150808211156130bd57600080fd5b6130c98c838d01612f6b565b909650945060608b01359150808211156130e257600080fd5b506130ef8b828c01612d35565b999c989b5096995094979396929594505050565b60006020828403121561311557600080fd5b81518015158114612b8557600080fd5b60006020828403121561313757600080fd5b5051919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052600160045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b6000602082840312156131ae57600080fd5b813567ffffffffffffffff81168114612b8557600080fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b6000817fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff048311821515161561322d5761322d6131c6565b500290565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601260045260246000fd5b60008261327057613270613232565b500490565b60008219821115613288576132886131c6565b500190565b60007fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8214156132bf576132bf6131c6565b5060010190565b6000826132d5576132d5613232565b500690565b600080858511156132ea57600080fd5b838611156132f757600080fd5b5050820193919092039150565b803560208310156103cc577fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff602084900360031b1b1692915050565b60008251613352818460208701612e4b565b9190910192915050565b83815260008351613374816020850160208801612e4b565b80830190507fffffffffffffffffffffffffffffffffffffffffffffffff00000000000000008416602082015260388101915050949350505050565b60a0815260006133c360a0830188612e77565b82810360208401526133d58188612e77565b905082810360408401526133e98187612e77565b905082810360608401526133fd8186612e77565b905082810360808401526134118185612e77565b98975050505050505050565b6000835161342f818460208801612e4b565b7fffffffffffffffffffffffffffffffff00000000000000000000000000000000939093169190920190815260100192915050565b60006060828403121561347657600080fd5b82601f83011261348557600080fd5b6040516060810181811067ffffffffffffffff821117156134a8576134a8612b8c565b6040528060608401858111156134bd57600080fd5b845b818110156134d75780518352602092830192016134bf565b509195945050505050565b828152600082516134fa816020850160208701612e4b565b919091016020019392505050565b6000845161351a818460208901612e4b565b7fffffffffffffffffffffffffffffffffffffffffffffffff00000000000000009490941691909301908152601881019190915260380192915050565b600181815b808511156135b057817fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff04821115613596576135966131c6565b808516156135a357918102915b93841c939080029061355c565b509250929050565b6000826135c7575060016103cc565b816135d4575060006103cc565b81600181146135ea57600281146135f457613610565b60019150506103cc565b60ff841115613605576136056131c6565b50506001821b6103cc565b5060208310610133831016604e8410600b8410161715613633575081810a6103cc565b61363d8383613557565b807fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0482111561366f5761366f6131c6565b029392505050565b6000612b8583836135b8565b600082821015613695576136956131c6565b50039056fea26469706673582212203ce20f2f56588a2b91a30cd55aa2ef0ce265594100ba89ba293e06012ab7a20a64736f6c634300080900330000000000000000000000009c58bacc331c9aa871afd802db6379a98e80cedb1ba015927e3c01349c0c7108e41632422a327c2588ce10610c39843517f5249793f7a074743d6d38f9ba320f84f46eef37ffe70567be763057e29e44c68856535bcecf"],"id":1}' \ + http://localhost:8546 \ +) +echo eth_sendRawTransaction RESPONSE $RESPONSE +TX1HASH=$(echo $RESPONSE | jq --raw-output '.result') +echo deposit contract deployed TX1HASH=$TX1HASH + +# exit if the transaction is not sent +if [ "$TX1HASH" == "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_getPayloadV3\", + \"params\":[ + \"$PAYLOAD_ID\" + ], + \"id\":1 + }" \ + http://localhost:8546 \ +) +echo engine_getPayloadV3 RESPONSE $RESPONSE + +BLOCK=$(echo $RESPONSE | jq '.result.executionPayload') +# BLOCK_NUMBER_HEX = 0x1, 0x2, etc +BLOCK_NUMBER_HEX_PREFIX=$(echo $BLOCK | jq --raw-output '.blockNumber') +echo BLOCK_NUMBER_HEX_PREFIX $BLOCK_NUMBER_HEX_PREFIX +BLOCK_NUMBER_HEX=${BLOCK_NUMBER_HEX_PREFIX#"0x"} +echo BLOCK_NUMBER_HEX $BLOCK_NUMBER_HEX +BLOCK_NUMBER=$((16#$BLOCK_NUMBER_HEX)) +echo BLOCK_NUMBER $BLOCK_NUMBER +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_newPayloadV3\", + \"params\":[ + $BLOCK, + [], + \"0x11f780a954bcba8889998e4e61deaae6388dd2391e9c810bd9c94962cc1eadc1\" + ], + \"id\":1 + }" \ + http://localhost:8546 \ +) +echo engine_newPayloadV3 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_forkchoiceUpdatedV3\", + \"params\":[ + { + \"headBlockHash\": \"$BLOCK_HASH\", + \"safeBlockHash\": \"0x0000000000000000000000000000000000000000000000000000000000000000\", + \"finalizedBlockHash\": \"0x0000000000000000000000000000000000000000000000000000000000000000\" + }, + null + ], + \"id\":1 + }" \ + http://localhost:8546 \ +) +echo engine_forkchoiceUpdatedV1 "(info: contract deployed)" set new block as head RESPONSE $RESPONSE + +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 "(info: contract receipt)" RESPONSE $TX1RECEIPT + +sleep 1 + +TIMESTAMP=$((TIMESTAMP + BLOCK_COUNTER)) + +echo "testing withdrawals for reth" + +# 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_forkchoiceUpdatedV3\", + \"params\":[ + { + \"headBlockHash\": \"$BLOCK_HASH\", + \"safeBlockHash\": \"0x0000000000000000000000000000000000000000000000000000000000000000\", + \"finalizedBlockHash\": \"0x0000000000000000000000000000000000000000000000000000000000000000\" + }, + { + \"timestamp\": $TIMESTAMP, + \"prevRandao\": \"0x0000000000000000000000000000000000000000000000000000000000000000\", + \"suggestedFeeRecipient\": \"0x0000000000000000000000000000000000000000\", + \"withdrawals\": [ + { + \"index\": \"0xf0\", + \"validatorIndex\": \"0xf0\", + \"address\": \"0x38e3E7Aca6762E296F659Fcb4E460a3A621dcD3D\", + \"amount\": \"0x10000000000\" + } + ], + \"parentBeaconBlockRoot\": \"0x11f780a954bcba8889998e4e61deaae6388dd2391e9c810bd9c94962cc1eadc1\" + } + ], + \"id\":1 + }" \ + http://localhost:8546 \ +) +echo engine_forkchoiceUpdatedV3 "(info: withdrawls sent from CL)" trigger block production RESPONSE $RESPONSE + +PAYLOAD_ID=$(echo $RESPONSE | jq --raw-output '.result.payloadId') +echo PAYLOAD_ID=$PAYLOAD_ID + +# 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_getPayloadV3\", + \"params\":[ + \"$PAYLOAD_ID\" + ], + \"id\":1 + }" \ + http://localhost:8546 \ +) +echo engine_getPayloadV3 "(info: withdrawals block)" RESPONSE $RESPONSE + +BLOCK=$(echo $RESPONSE | jq '.result.executionPayload') +# 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_newPayloadV3\", + \"params\":[ + $BLOCK, + [], + \"0x11f780a954bcba8889998e4e61deaae6388dd2391e9c810bd9c94962cc1eadc1\" + ], + \"id\":1 + }" \ + http://localhost:8546 \ +) +echo engine_newPayloadV2 "(info: withdrawals block sent as payload)" 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_forkchoiceUpdatedV3\", + \"params\":[ + { + \"headBlockHash\": \"$BLOCK_HASH\", + \"safeBlockHash\": \"0x0000000000000000000000000000000000000000000000000000000000000000\", + \"finalizedBlockHash\": \"0x0000000000000000000000000000000000000000000000000000000000000000\" + }, + null + ], + \"id\":1 + }" \ + http://localhost:8546 \ +) +echo engine_forkchoiceUpdatedV3 "(info: block with withdrawals set 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 "(info: head block retrieved)" $HEAD_BLOCK + +WITHDRAWALS_ROOT_RETH=$(echo $HEAD_BLOCK | jq --raw-output '.result.withdrawalsRoot') + +# print WITHDRAWALS_ROOT_RETH +echo "WITHDRAWALS_ROOT_RETH" $WITHDRAWALS_ROOT_RETH + +# check if withdrawals root is not null +if [ "$WITHDRAWALS_ROOT_RETH" == "null" ]; then + echo "Withdrawals root is null, exiting" + exit 1 +fi + +ps aux | grep "reth node" | grep -v grep | awk '{print $2}' | xargs kill + +sleep 2 + +echo "testing withdrawals for nethermind" + +$DIR/run_nethermind.sh & + +# 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 + +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 + +TIMESTAMP=$((1714401490 - 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_forkchoiceUpdatedV3\", + \"params\":[ + { + \"headBlockHash\": \"$HEAD_BLOCK_HASH\", + \"safeBlockHash\": \"0x0000000000000000000000000000000000000000000000000000000000000000\", + \"finalizedBlockHash\": \"0x0000000000000000000000000000000000000000000000000000000000000000\" + }, + { + \"timestamp\": $TIMESTAMP, + \"prevRandao\": \"0x0000000000000000000000000000000000000000000000000000000000000000\", + \"suggestedFeeRecipient\": \"0x0000000000000000000000000000000000000000\", + \"withdrawals\": [ + { + \"index\": \"0xf0\", + \"validatorIndex\": \"0xf0\", + \"address\": \"0x38e3E7Aca6762E296F659Fcb4E460a3A621dcD3D\", + \"amount\": \"0x10000000000\" + } + ], + \"parentBeaconBlockRoot\": \"0x11f780a954bcba8889998e4e61deaae6388dd2391e9c810bd9c94962cc1eadc1\" + } + ], + \"id\":1 + }" \ + http://localhost:8546 \ +) +echo engine_forkchoiceUpdatedV2 "(info: withdrawls sent from CL)" trigger block production RESPONSE $RESPONSE + +PAYLOAD_ID=$(echo $RESPONSE | jq --raw-output '.result.payloadId') +echo PAYLOAD_ID=$PAYLOAD_ID + +# 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_getPayloadV3\", + \"params\":[ + \"$PAYLOAD_ID\" + ], + \"id\":1 + }" \ + http://localhost:8546 \ +) +echo engine_getPayloadV2 "(info: withdrawals block)" RESPONSE $RESPONSE + +BLOCK=$(echo $RESPONSE | jq '.result.executionPayload') +# 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') + +RESPONSE=$(curl -X POST -H "Content-Type: application/json" \ + -H "Authorization: Bearer $JWT_TOKEN" \ + --data "{ + \"jsonrpc\":\"2.0\", + \"method\":\"engine_newPayloadV3\", + \"params\":[ + $BLOCK, + [], + \"0x11f780a954bcba8889998e4e61deaae6388dd2391e9c810bd9c94962cc1eadc1\" + ], + \"id\":1 + }" \ + http://localhost:8546 \ +) +echo engine_newPayloadV2 "(info: withdrawals block sent as payload)" 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_forkchoiceUpdatedV2\", + \"params\":[ + { + \"headBlockHash\": \"$BLOCK_HASH\", + \"safeBlockHash\": \"0x0000000000000000000000000000000000000000000000000000000000000000\", + \"finalizedBlockHash\": \"0x0000000000000000000000000000000000000000000000000000000000000000\" + }, + null + ], + \"id\":1 + }" \ + http://localhost:8546 \ +) +echo engine_forkchoiceUpdatedV2 "(info: block with withdrawals set 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 "(info: head block retrieved)" $HEAD_BLOCK + +WITHDRAWALS_ROOT_NETHERMIND=$(echo $HEAD_BLOCK | jq --raw-output '.result.withdrawalsRoot') + +# check if withdrawals root is not null +if [ "$WITHDRAWALS_ROOT_NETHERMIND" == "null" ]; then + echo "Withdrawals root is null, exiting" + exit 1 +fi + +if [ "$WITHDRAWALS_ROOT_RETH" != "$WITHDRAWALS_ROOT_NETHERMIND" ]; then + echo "Withdrawals root from reth and nethermind are not equal" + exit 1 +fi + +echo "Withdrawals root from reth and nethermind are equal" \ No newline at end of file From 24e0435438528fbecc14dab68d6b6a73d1c4d117 Mon Sep 17 00:00:00 2001 From: debjit Date: Mon, 11 Nov 2024 12:53:30 +0700 Subject: [PATCH 3/8] eip 4895 manual tests --- .github/workflows/post-merge-run.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/post-merge-run.yml b/.github/workflows/post-merge-run.yml index 7273eba..5270f92 100644 --- a/.github/workflows/post-merge-run.yml +++ b/.github/workflows/post-merge-run.yml @@ -49,5 +49,7 @@ jobs: # Manual sanity checks - name: Run EIP-1559 sanity checks run: bash ./scripts/test_eip1559.sh + - name: Run EIP-4895 sanity checks + run: bash ./scripts/test_withdrawals_eip4895.sh From c80c6371a3680d7fe6b2a00d16ab512a91b28690 Mon Sep 17 00:00:00 2001 From: debjit Date: Mon, 11 Nov 2024 12:56:10 +0700 Subject: [PATCH 4/8] fmt --- src/payload_builder.rs | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/src/payload_builder.rs b/src/payload_builder.rs index ce3f924..0246933 100644 --- a/src/payload_builder.rs +++ b/src/payload_builder.rs @@ -18,9 +18,8 @@ use reth::{ transaction_pool::{noop::NoopTransactionPool, BestTransactionsAttributes, TransactionPool}, }; use reth_basic_payload_builder::{ - is_better_payload, BasicPayloadJobGenerator, - BasicPayloadJobGeneratorConfig, BuildArguments, BuildOutcome, PayloadBuilder, PayloadConfig, - WithdrawalsOutcome, + is_better_payload, BasicPayloadJobGenerator, BasicPayloadJobGeneratorConfig, BuildArguments, + BuildOutcome, PayloadBuilder, PayloadConfig, WithdrawalsOutcome, }; use reth_chain_state::ExecutedBlock; use reth_chainspec::{ChainSpec, EthereumHardforks}; @@ -443,9 +442,10 @@ where let deposit_requests = parse_deposits_from_receipts(&chain_spec, receipts.iter().flatten()) .map_err(|err| PayloadBuilderError::Internal(RethError::Execution(err.into())))?; - println!("debjit debug (payload) requests (building): {:?}", Requests::new(vec![ - deposit_requests.clone(), - ])); + println!( + "debjit debug (payload) requests (building): {:?}", + Requests::new(vec![deposit_requests.clone(),]) + ); Some(Requests::new(vec![deposit_requests])) } else { @@ -456,18 +456,18 @@ where withdrawals_root, withdrawals, } = if !chain_spec.is_shanghai_active_at_timestamp(attributes.timestamp) { - WithdrawalsOutcome::pre_shanghai() - } else if attributes.withdrawals.is_empty() { - WithdrawalsOutcome::empty() - } else { - let withdrawals_root = proofs::calculate_withdrawals_root(&attributes.withdrawals); - - // calculate withdrawals root - WithdrawalsOutcome { - withdrawals: Some(attributes.withdrawals), - withdrawals_root: Some(withdrawals_root), - } - }; + WithdrawalsOutcome::pre_shanghai() + } else if attributes.withdrawals.is_empty() { + WithdrawalsOutcome::empty() + } else { + let withdrawals_root = proofs::calculate_withdrawals_root(&attributes.withdrawals); + + // calculate withdrawals root + WithdrawalsOutcome { + withdrawals: Some(attributes.withdrawals), + withdrawals_root: Some(withdrawals_root), + } + }; // merge all transitions into bundle state, this would apply the withdrawal balance changes // and 4788 contract call From 1ddb9f56a0b9f91fc6ea7974148b450f16ad044a Mon Sep 17 00:00:00 2001 From: debjit Date: Mon, 11 Nov 2024 13:02:27 +0700 Subject: [PATCH 5/8] clippy --- scripts/{withdrawals.sh => test_withdrawals_eip4895.sh} | 0 src/execute.rs | 3 +-- 2 files changed, 1 insertion(+), 2 deletions(-) rename scripts/{withdrawals.sh => test_withdrawals_eip4895.sh} (100%) diff --git a/scripts/withdrawals.sh b/scripts/test_withdrawals_eip4895.sh similarity index 100% rename from scripts/withdrawals.sh rename to scripts/test_withdrawals_eip4895.sh diff --git a/src/execute.rs b/src/execute.rs index 7fb81cc..5636f26 100644 --- a/src/execute.rs +++ b/src/execute.rs @@ -256,8 +256,7 @@ where // Collect all EIP-6110 deposits let deposit_requests = parse_deposits_from_receipts(&self.chain_spec, receipts)?; - let requests = Requests::new(vec![deposit_requests]); - requests + Requests::new(vec![deposit_requests]) } else { Requests::default() }; From e39bb19d63bf80f85bb1378b4bba7ea262f02cf3 Mon Sep 17 00:00:00 2001 From: debjit Date: Mon, 11 Nov 2024 13:12:02 +0700 Subject: [PATCH 6/8] script cleanup --- scripts/test_withdrawals_eip4895.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/test_withdrawals_eip4895.sh b/scripts/test_withdrawals_eip4895.sh index 206cd2c..fbac02a 100755 --- a/scripts/test_withdrawals_eip4895.sh +++ b/scripts/test_withdrawals_eip4895.sh @@ -12,9 +12,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 docker rm -f neth-vec-gen 2>/dev/null || true } @@ -475,4 +473,6 @@ if [ "$WITHDRAWALS_ROOT_RETH" != "$WITHDRAWALS_ROOT_NETHERMIND" ]; then exit 1 fi -echo "Withdrawals root from reth and nethermind are equal" \ No newline at end of file +echo "Withdrawals root from reth and nethermind are equal" + +docker rm -f neth-vec-gen 2>/dev/null || true \ No newline at end of file From 45d5c63b7a95669a16d4397f0b34b423c57fed31 Mon Sep 17 00:00:00 2001 From: Debjit Bhowal Date: Mon, 11 Nov 2024 13:34:27 +0700 Subject: [PATCH 7/8] Update test_withdrawals_eip4895.sh --- scripts/test_withdrawals_eip4895.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/test_withdrawals_eip4895.sh b/scripts/test_withdrawals_eip4895.sh index fbac02a..1461ddf 100755 --- a/scripts/test_withdrawals_eip4895.sh +++ b/scripts/test_withdrawals_eip4895.sh @@ -475,4 +475,5 @@ fi echo "Withdrawals root from reth and nethermind are equal" -docker rm -f neth-vec-gen 2>/dev/null || true \ No newline at end of file +docker rm -f neth-vec-gen 2>/dev/null || true +exit 0 From 8663384d309f5096da16bab68c97f8f79ab646fe Mon Sep 17 00:00:00 2001 From: debjit Date: Tue, 12 Nov 2024 00:45:38 +0700 Subject: [PATCH 8/8] CI --- scripts/test_withdrawals_eip4895.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/scripts/test_withdrawals_eip4895.sh b/scripts/test_withdrawals_eip4895.sh index 1461ddf..a3a330b 100755 --- a/scripts/test_withdrawals_eip4895.sh +++ b/scripts/test_withdrawals_eip4895.sh @@ -11,8 +11,12 @@ DIR="$(dirname "$0")" BG_PID=$! # Set the trap to call cleanup if an error occurs +# Define cleanup function cleanup() { - ps aux | grep "reth node" | grep -v grep | awk '{print $2}' | xargs kill + # Kill the reth process if it is running + pkill -f "reth node" || true + + # Remove Docker container safely if it exists docker rm -f neth-vec-gen 2>/dev/null || true }