From 71570493a53a36824bad5405aabac95e1dbaa2b2 Mon Sep 17 00:00:00 2001 From: nidhi-singh02 Date: Mon, 13 Jan 2025 15:01:39 +0530 Subject: [PATCH 01/12] kurtosis setup to get deposit contract and fill genesis file Signed-off-by: nidhi-singh02 --- Dockerfile | 2 +- kurtosis/main.star | 25 ++++-- .../network-configs/genesis.json.template | 6 +- .../src/nodes/consensus/beacond/launcher.star | 82 +++++++++++++++++-- .../scripts/modify-genesis-with-deposits.sh | 35 ++++++++ ...ts.sh => multiple-premined-deposits-cl.sh} | 1 - .../nethermind/genesis.json.template | 6 +- kurtosis/src/nodes/nodes.star | 47 ++++++++++- 8 files changed, 182 insertions(+), 22 deletions(-) create mode 100644 kurtosis/src/nodes/consensus/beacond/scripts/modify-genesis-with-deposits.sh rename kurtosis/src/nodes/consensus/beacond/scripts/{multiple-premined-deposits.sh => multiple-premined-deposits-cl.sh} (95%) diff --git a/Dockerfile b/Dockerfile index 93c438993b..f90eef86d0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -105,7 +105,7 @@ COPY --from=builder /workdir/build/bin/${APP_NAME} /usr/bin/${APP_NAME} # TODO: We should un hood this part, its very specific # to our kurtosis setup. RUN mkdir -p /root/jwt /root/kzg && \ - apk add --no-cache bash sed curl + apk add --no-cache bash sed curl jq EXPOSE 26656 EXPOSE 26657 diff --git a/kurtosis/main.star b/kurtosis/main.star index d960b84c54..194a94c76a 100644 --- a/kurtosis/main.star +++ b/kurtosis/main.star @@ -60,11 +60,22 @@ def run(plan, network_configuration = {}, node_settings = {}, eth_json_rpc_endpo # 2. Upload files jwt_file, kzg_trusted_setup = execution.upload_global_files(plan, node_modules, chain_id) - # 2 a. Create genesis files only once and pass it to the node configs - genesis_files = nodes.create_genesis_files(plan, chain_id) + # 3. Perform genesis ceremony for the CL genesis deposits. + stored_configs = beacond.perform_genesis_deposits_ceremony(plan, validators, jwt_file, chain_id, chain_spec) - # 3. Perform genesis ceremony - beacond.perform_genesis_ceremony(plan, validators, jwt_file, chain_id, chain_spec, genesis_files) + # 4 a. Create genesis files only once and pass it to the node configs + genesis_files = nodes.create_genesis_files_part1(plan, chain_id) + + # 4b. Modify the eth genesis file with the premined deposits && finalize CL genesis file. + # Get the deposit storage values stored in env variables + env_vars = beacond.modify_genesis_files_deposits(plan, validators, genesis_files, chain_id, chain_spec, stored_configs) + + # Extract values from env_vars + genesis_deposits_root = env_vars.get("GENESIS_DEPOSITS_ROOT") + genesis_deposit_count_hex = env_vars.get("GENESIS_DEPOSIT_COUNT_HEX") + + # 4c. Modify the eth genesis files(for both nethermind and default) with the ENV VARS + genesis_files = nodes.create_genesis_files_part2(plan, chain_id, genesis_deposits_root, genesis_deposit_count_hex) el_enode_addrs = [] metrics_enabled_services = metrics_enabled_services[:] @@ -90,7 +101,7 @@ def run(plan, network_configuration = {}, node_settings = {}, eth_json_rpc_endpo metrics_enabled_services = execution.add_metrics(metrics_enabled_services, seed, seed.el_service_name, seed_node_el_clients[seed.el_service_name], node_modules) seed_node_configs = {} for n, seed in enumerate(seed_nodes): - seed_node_config = beacond.create_node_config(plan, seed, consensus_node_peering_info, seed.el_service_name, chain_id, chain_spec, jwt_file, kzg_trusted_setup) + seed_node_config = beacond.create_node_config(plan, seed, consensus_node_peering_info, seed.el_service_name, chain_id, chain_spec, genesis_deposits_root, genesis_deposit_count_hex, jwt_file, kzg_trusted_setup) seed_node_configs[seed.cl_service_name] = seed_node_config seed_nodes_clients = plan.add_services( configs = seed_node_configs, @@ -121,7 +132,7 @@ def run(plan, network_configuration = {}, node_settings = {}, eth_json_rpc_endpo for n, full in enumerate(full_nodes): # 5b. Launch CL - full_node_config = beacond.create_node_config(plan, full, consensus_node_peering_info, full.el_service_name, chain_id, chain_spec, jwt_file, kzg_trusted_setup) + full_node_config = beacond.create_node_config(plan, full, consensus_node_peering_info, full.el_service_name, chain_id, chain_spec, genesis_deposits_root, genesis_deposit_count_hex, jwt_file, kzg_trusted_setup) full_node_configs[full.cl_service_name] = full_node_config if full_node_configs != {}: @@ -152,7 +163,7 @@ def run(plan, network_configuration = {}, node_settings = {}, eth_json_rpc_endpo validator_node_configs = {} for n, validator in enumerate(validators): - validator_node_config = beacond.create_node_config(plan, validator, consensus_node_peering_info, validator.el_service_name, chain_id, chain_spec, jwt_file, kzg_trusted_setup) + validator_node_config = beacond.create_node_config(plan, validator, consensus_node_peering_info, validator.el_service_name, chain_id, chain_spec, genesis_deposits_root, genesis_deposit_count_hex, jwt_file, kzg_trusted_setup) validator_node_configs[validator.cl_service_name] = validator_node_config cl_clients = plan.add_services( diff --git a/kurtosis/src/networks/kurtosis-devnet/network-configs/genesis.json.template b/kurtosis/src/networks/kurtosis-devnet/network-configs/genesis.json.template index a6178ad786..70b3fb0566 100644 --- a/kurtosis/src/networks/kurtosis-devnet/network-configs/genesis.json.template +++ b/kurtosis/src/networks/kurtosis-devnet/network-configs/genesis.json.template @@ -352,7 +352,11 @@ "0x4242424242424242424242424242424242424242": { "balance": "0x0", "nonce": "0x1", - "code": "0x608060405260043610610093575f3560e01c8063577212fe11610066578063c53925d91161004c578063c53925d914610231578063e12cf4cb14610250578063fea7ab7714610263575f80fd5b8063577212fe146101cc5780639eaffa96146101ed575f80fd5b806301ffc9a7146100975780632dfdf0b5146100cb5780633523f9bd14610103578063560036ec14610126575b5f80fd5b3480156100a2575f80fd5b506100b66100b1366004610c22565b610282565b60405190151581526020015b60405180910390f35b3480156100d6575f80fd5b505f546100ea9067ffffffffffffffff1681565b60405167ffffffffffffffff90911681526020016100c2565b34801561010e575f80fd5b5061011860015481565b6040519081526020016100c2565b348015610131575f80fd5b50610193610140366004610c95565b80516020818301810180516003825292820191909301209152546bffffffffffffffffffffffff8116906c01000000000000000000000000900473ffffffffffffffffffffffffffffffffffffffff1682565b604080516bffffffffffffffffffffffff909316835273ffffffffffffffffffffffffffffffffffffffff9091166020830152016100c2565b3480156101d7575f80fd5b506101eb6101e6366004610dca565b61031a565b005b3480156101f8575f80fd5b5061020c610207366004610dca565b6103f0565b60405173ffffffffffffffffffffffffffffffffffffffff90911681526020016100c2565b34801561023c575f80fd5b506101eb61024b366004610dca565b610431565b6101eb61025e366004610e2c565b610658565b34801561026e575f80fd5b506101eb61027d366004610edb565b6109ab565b5f7fffffffff0000000000000000000000000000000000000000000000000000000082167f01ffc9a700000000000000000000000000000000000000000000000000000000148061031457507fffffffff0000000000000000000000000000000000000000000000000000000082167f136f920d00000000000000000000000000000000000000000000000000000000145b92915050565b6002828260405161032c929190610f2b565b908152604051908190036020019020543373ffffffffffffffffffffffffffffffffffffffff9091161461038c576040517f7c214f0400000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6003828260405161039e929190610f2b565b9081526040519081900360200181205f90556103bd9083908390610f2b565b604051908190038120907f1c0a7e1bd09da292425c039309671a03de56b89a0858598aab6df6ce84b006db905f90a25050565b5f60028383604051610403929190610f2b565b9081526040519081900360200190205473ffffffffffffffffffffffffffffffffffffffff16905092915050565b5f60038383604051610444929190610f2b565b908152604051908190036020019020805490915073ffffffffffffffffffffffffffffffffffffffff6c01000000000000000000000000820416906bffffffffffffffffffffffff163382146104c6576040517f819a0d0b00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6bffffffffffffffffffffffff42166104e26201518083610f67565b6bffffffffffffffffffffffff161115610528576040517fe8966d7a00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b5f6002868660405161053b929190610f2b565b9081526040519081900360200181205473ffffffffffffffffffffffffffffffffffffffff16915083906002906105759089908990610f2b565b908152604051908190036020018120805473ffffffffffffffffffffffffffffffffffffffff939093167fffffffffffffffffffffffff0000000000000000000000000000000000000000909316929092179091556003906105da9088908890610f2b565b9081526040519081900360200181205f90556105f99087908790610f2b565b6040805191829003822073ffffffffffffffffffffffffffffffffffffffff808716845284166020840152917f0adffd98d3072c48341843974dffd7a910bb849ba6ca04163d43bb26feb17403910160405180910390a2505050505050565b60308614610692576040517f9f10647200000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b602084146106cc576040517fb39bca1600000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60608214610706576040517f4be6321b00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b5f73ffffffffffffffffffffffffffffffffffffffff166002888860405161072f929190610f2b565b9081526040519081900360200190205473ffffffffffffffffffffffffffffffffffffffff16036108765773ffffffffffffffffffffffffffffffffffffffff81166107a7576040517f51969a7a00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b80600288886040516107ba929190610f2b565b908152604051908190036020018120805473ffffffffffffffffffffffffffffffffffffffff939093167fffffffffffffffffffffffff00000000000000000000000000000000000000009093169290921790915561081c9088908890610f2b565b6040805191829003822073ffffffffffffffffffffffffffffffffffffffff841683525f6020840152917f0adffd98d3072c48341843974dffd7a910bb849ba6ca04163d43bb26feb17403910160405180910390a26108c4565b73ffffffffffffffffffffffffffffffffffffffff8116156108c4576040517fc4142b4100000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b5f6108cd610b5d565b9050633b9aca0067ffffffffffffffff82161015610917576040517f0e1eddda00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b5f80547f68af751683498a9f9be59fe8b0d52a64dd155255d85cdb29fea30b1e3f891d46918a918a918a918a9187918b918b9167ffffffffffffffff16908061095f83610f8b565b91906101000a81548167ffffffffffffffff021916908367ffffffffffffffff160217905550604051610999989796959493929190610ffe565b60405180910390a15050505050505050565b5f600284846040516109be929190610f2b565b9081526040519081900360200190205473ffffffffffffffffffffffffffffffffffffffff169050338114610a1f576040517f7c214f0400000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b73ffffffffffffffffffffffffffffffffffffffff8216610a6c576040517fd92e233d00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b5f60038585604051610a7f929190610f2b565b908152604051908190036020018120426bffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff86166c01000000000000000000000000027fffffffffffffffffffffffffffffffffffffffff000000000000000000000000161781559150610af79086908690610f2b565b6040805191829003822073ffffffffffffffffffffffffffffffffffffffff8681168452851660208401524283830152905190917f7640ec3c8c4695deadda414dd20400acf275297a7c38715f9237657e97ddba5f919081900360600190a25050505050565b5f610b6c633b9aca0034611096565b15610ba3576040517f40567b3800000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b5f610bb2633b9aca00346110a9565b905067ffffffffffffffff811115610bf6576040517f2aa6673400000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b610c005f34610c05565b919050565b5f385f3884865af1610c1e5763b12d13eb5f526004601cfd5b5050565b5f60208284031215610c32575f80fd5b81357fffffffff0000000000000000000000000000000000000000000000000000000081168114610c61575f80fd5b9392505050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52604160045260245ffd5b5f60208284031215610ca5575f80fd5b813567ffffffffffffffff811115610cbb575f80fd5b8201601f81018413610ccb575f80fd5b803567ffffffffffffffff811115610ce557610ce5610c68565b6040517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0603f7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0601f8501160116810181811067ffffffffffffffff82111715610d5157610d51610c68565b604052818152828201602001861015610d68575f80fd5b816020840160208301375f91810160200191909152949350505050565b5f8083601f840112610d95575f80fd5b50813567ffffffffffffffff811115610dac575f80fd5b602083019150836020828501011115610dc3575f80fd5b9250929050565b5f8060208385031215610ddb575f80fd5b823567ffffffffffffffff811115610df1575f80fd5b610dfd85828601610d85565b90969095509350505050565b803573ffffffffffffffffffffffffffffffffffffffff81168114610c00575f80fd5b5f805f805f805f6080888a031215610e42575f80fd5b873567ffffffffffffffff811115610e58575f80fd5b610e648a828b01610d85565b909850965050602088013567ffffffffffffffff811115610e83575f80fd5b610e8f8a828b01610d85565b909650945050604088013567ffffffffffffffff811115610eae575f80fd5b610eba8a828b01610d85565b9094509250610ecd905060608901610e09565b905092959891949750929550565b5f805f60408486031215610eed575f80fd5b833567ffffffffffffffff811115610f03575f80fd5b610f0f86828701610d85565b9094509250610f22905060208501610e09565b90509250925092565b818382375f9101908152919050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52601160045260245ffd5b6bffffffffffffffffffffffff818116838216019081111561031457610314610f3a565b5f67ffffffffffffffff821667ffffffffffffffff8103610fae57610fae610f3a565b60010192915050565b81835281816020850137505f602082840101525f60207fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0601f840116840101905092915050565b60a081525f61101160a083018a8c610fb7565b828103602084015261102481898b610fb7565b905067ffffffffffffffff871660408401528281036060840152611049818688610fb7565b91505067ffffffffffffffff831660808301529998505050505050505050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52601260045260245ffd5b5f826110a4576110a4611069565b500690565b5f826110b7576110b7611069565b50049056fea264697066735822122069227307258cbe8f29985bb4f3e283b1b03d5c0cbab8add81bf3c22e3d13729664736f6c634300081a0033" + "code": "0x608060405260043610610093575f3560e01c8063577212fe11610066578063c53925d91161004c578063c53925d914610231578063e12cf4cb14610250578063fea7ab7714610263575f80fd5b8063577212fe146101cc5780639eaffa96146101ed575f80fd5b806301ffc9a7146100975780632dfdf0b5146100cb5780633523f9bd14610103578063560036ec14610126575b5f80fd5b3480156100a2575f80fd5b506100b66100b1366004610c22565b610282565b60405190151581526020015b60405180910390f35b3480156100d6575f80fd5b505f546100ea9067ffffffffffffffff1681565b60405167ffffffffffffffff90911681526020016100c2565b34801561010e575f80fd5b5061011860015481565b6040519081526020016100c2565b348015610131575f80fd5b50610193610140366004610c95565b80516020818301810180516003825292820191909301209152546bffffffffffffffffffffffff8116906c01000000000000000000000000900473ffffffffffffffffffffffffffffffffffffffff1682565b604080516bffffffffffffffffffffffff909316835273ffffffffffffffffffffffffffffffffffffffff9091166020830152016100c2565b3480156101d7575f80fd5b506101eb6101e6366004610dca565b61031a565b005b3480156101f8575f80fd5b5061020c610207366004610dca565b6103f0565b60405173ffffffffffffffffffffffffffffffffffffffff90911681526020016100c2565b34801561023c575f80fd5b506101eb61024b366004610dca565b610431565b6101eb61025e366004610e2c565b610658565b34801561026e575f80fd5b506101eb61027d366004610edb565b6109ab565b5f7fffffffff0000000000000000000000000000000000000000000000000000000082167f01ffc9a700000000000000000000000000000000000000000000000000000000148061031457507fffffffff0000000000000000000000000000000000000000000000000000000082167f136f920d00000000000000000000000000000000000000000000000000000000145b92915050565b6002828260405161032c929190610f2b565b908152604051908190036020019020543373ffffffffffffffffffffffffffffffffffffffff9091161461038c576040517f7c214f0400000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6003828260405161039e929190610f2b565b9081526040519081900360200181205f90556103bd9083908390610f2b565b604051908190038120907f1c0a7e1bd09da292425c039309671a03de56b89a0858598aab6df6ce84b006db905f90a25050565b5f60028383604051610403929190610f2b565b9081526040519081900360200190205473ffffffffffffffffffffffffffffffffffffffff16905092915050565b5f60038383604051610444929190610f2b565b908152604051908190036020019020805490915073ffffffffffffffffffffffffffffffffffffffff6c01000000000000000000000000820416906bffffffffffffffffffffffff163382146104c6576040517f819a0d0b00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6bffffffffffffffffffffffff42166104e26201518083610f67565b6bffffffffffffffffffffffff161115610528576040517fe8966d7a00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b5f6002868660405161053b929190610f2b565b9081526040519081900360200181205473ffffffffffffffffffffffffffffffffffffffff16915083906002906105759089908990610f2b565b908152604051908190036020018120805473ffffffffffffffffffffffffffffffffffffffff939093167fffffffffffffffffffffffff0000000000000000000000000000000000000000909316929092179091556003906105da9088908890610f2b565b9081526040519081900360200181205f90556105f99087908790610f2b565b6040805191829003822073ffffffffffffffffffffffffffffffffffffffff808716845284166020840152917f0adffd98d3072c48341843974dffd7a910bb849ba6ca04163d43bb26feb17403910160405180910390a2505050505050565b60308614610692576040517f9f10647200000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b602084146106cc576040517fb39bca1600000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60608214610706576040517f4be6321b00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b5f73ffffffffffffffffffffffffffffffffffffffff166002888860405161072f929190610f2b565b9081526040519081900360200190205473ffffffffffffffffffffffffffffffffffffffff16036108765773ffffffffffffffffffffffffffffffffffffffff81166107a7576040517f51969a7a00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b80600288886040516107ba929190610f2b565b908152604051908190036020018120805473ffffffffffffffffffffffffffffffffffffffff939093167fffffffffffffffffffffffff00000000000000000000000000000000000000009093169290921790915561081c9088908890610f2b565b6040805191829003822073ffffffffffffffffffffffffffffffffffffffff841683525f6020840152917f0adffd98d3072c48341843974dffd7a910bb849ba6ca04163d43bb26feb17403910160405180910390a26108c4565b73ffffffffffffffffffffffffffffffffffffffff8116156108c4576040517fc4142b4100000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b5f6108cd610b5d565b9050633b9aca0067ffffffffffffffff82161015610917576040517f0e1eddda00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b5f80547f68af751683498a9f9be59fe8b0d52a64dd155255d85cdb29fea30b1e3f891d46918a918a918a918a9187918b918b9167ffffffffffffffff16908061095f83610f8b565b91906101000a81548167ffffffffffffffff021916908367ffffffffffffffff160217905550604051610999989796959493929190610ffe565b60405180910390a15050505050505050565b5f600284846040516109be929190610f2b565b9081526040519081900360200190205473ffffffffffffffffffffffffffffffffffffffff169050338114610a1f576040517f7c214f0400000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b73ffffffffffffffffffffffffffffffffffffffff8216610a6c576040517fd92e233d00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b5f60038585604051610a7f929190610f2b565b908152604051908190036020018120426bffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff86166c01000000000000000000000000027fffffffffffffffffffffffffffffffffffffffff000000000000000000000000161781559150610af79086908690610f2b565b6040805191829003822073ffffffffffffffffffffffffffffffffffffffff8681168452851660208401524283830152905190917f7640ec3c8c4695deadda414dd20400acf275297a7c38715f9237657e97ddba5f919081900360600190a25050505050565b5f610b6c633b9aca0034611096565b15610ba3576040517f40567b3800000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b5f610bb2633b9aca00346110a9565b905067ffffffffffffffff811115610bf6576040517f2aa6673400000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b610c005f34610c05565b919050565b5f385f3884865af1610c1e5763b12d13eb5f526004601cfd5b5050565b5f60208284031215610c32575f80fd5b81357fffffffff0000000000000000000000000000000000000000000000000000000081168114610c61575f80fd5b9392505050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52604160045260245ffd5b5f60208284031215610ca5575f80fd5b813567ffffffffffffffff811115610cbb575f80fd5b8201601f81018413610ccb575f80fd5b803567ffffffffffffffff811115610ce557610ce5610c68565b6040517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0603f7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0601f8501160116810181811067ffffffffffffffff82111715610d5157610d51610c68565b604052818152828201602001861015610d68575f80fd5b816020840160208301375f91810160200191909152949350505050565b5f8083601f840112610d95575f80fd5b50813567ffffffffffffffff811115610dac575f80fd5b602083019150836020828501011115610dc3575f80fd5b9250929050565b5f8060208385031215610ddb575f80fd5b823567ffffffffffffffff811115610df1575f80fd5b610dfd85828601610d85565b90969095509350505050565b803573ffffffffffffffffffffffffffffffffffffffff81168114610c00575f80fd5b5f805f805f805f6080888a031215610e42575f80fd5b873567ffffffffffffffff811115610e58575f80fd5b610e648a828b01610d85565b909850965050602088013567ffffffffffffffff811115610e83575f80fd5b610e8f8a828b01610d85565b909650945050604088013567ffffffffffffffff811115610eae575f80fd5b610eba8a828b01610d85565b9094509250610ecd905060608901610e09565b905092959891949750929550565b5f805f60408486031215610eed575f80fd5b833567ffffffffffffffff811115610f03575f80fd5b610f0f86828701610d85565b9094509250610f22905060208501610e09565b90509250925092565b818382375f9101908152919050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52601160045260245ffd5b6bffffffffffffffffffffffff818116838216019081111561031457610314610f3a565b5f67ffffffffffffffff821667ffffffffffffffff8103610fae57610fae610f3a565b60010192915050565b81835281816020850137505f602082840101525f60207fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0601f840116840101905092915050565b60a081525f61101160a083018a8c610fb7565b828103602084015261102481898b610fb7565b905067ffffffffffffffff871660408401528281036060840152611049818688610fb7565b91505067ffffffffffffffff831660808301529998505050505050505050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52601260045260245ffd5b5f826110a4576110a4611069565b500690565b5f826110b7576110b7611069565b50049056fea264697066735822122069227307258cbe8f29985bb4f3e283b1b03d5c0cbab8add81bf3c22e3d13729664736f6c634300081a0033", + "storage": { + "0x0000000000000000000000000000000000000000000000000000000000000000": "{{.GENESIS_DEPOSIT_COUNT_HEX}}", + "0x0000000000000000000000000000000000000000000000000000000000000001": "{{.GENESIS_DEPOSITS_ROOT}}" + } } } } diff --git a/kurtosis/src/nodes/consensus/beacond/launcher.star b/kurtosis/src/nodes/consensus/beacond/launcher.star index bc2c8b081a..c238ce33a1 100644 --- a/kurtosis/src/nodes/consensus/beacond/launcher.star +++ b/kurtosis/src/nodes/consensus/beacond/launcher.star @@ -31,7 +31,7 @@ USED_PORTS = { NODE_API_PORT_ID: shared_utils.new_port_spec(NODE_API_PORT_NUM, shared_utils.TCP_PROTOCOL), } -def get_config(node_struct, engine_dial_url, chain_id, chain_spec, entrypoint = [], cmd = [], persistent_peers = "", expose_ports = True, jwt_file = None, kzg_trusted_setup_file = None): +def get_config(node_struct, engine_dial_url, chain_id, chain_spec, genesis_deposits_root, genesis_deposit_count_hex, entrypoint = [], cmd = [], persistent_peers = "", expose_ports = True, jwt_file = None, kzg_trusted_setup_file = None): exposed_ports = {} if expose_ports: exposed_ports = USED_PORTS @@ -72,6 +72,8 @@ def get_config(node_struct, engine_dial_url, chain_id, chain_spec, entrypoint = "BEACOND_CHAIN_SPEC": chain_spec, "WITHDRAWAL_ADDRESS": "0x20f33ce90a13a4b5e7697e3544c3083b8f8a51d4", "DEPOSIT_AMOUNT": "32000000000", + "GENESIS_DEPOSIT_COUNT_HEX": genesis_deposit_count_hex, + "GENESIS_DEPOSITS_ROOT": genesis_deposits_root, }, ports = exposed_ports, labels = node_labels, @@ -80,7 +82,7 @@ def get_config(node_struct, engine_dial_url, chain_id, chain_spec, entrypoint = return config -def perform_genesis_ceremony(plan, validators, jwt_file, chain_id, chain_spec, genesis_files): +def perform_genesis_deposits_ceremony(plan, validators, jwt_file, chain_id, chain_spec): num_validators = len(validators) node_peering_info = [] @@ -94,7 +96,7 @@ def perform_genesis_ceremony(plan, validators, jwt_file, chain_id, chain_spec, g stored_configs.append(StoreSpec(src = "/tmp/config_genesis/.beacond/config/genesis.json", name = "cosmos-genesis-final")) multiple_gentx_file = plan.upload_files( - src = "./scripts/multiple-premined-deposits.sh", + src = "./scripts/multiple-premined-deposits-cl.sh", name = "multiple-premined-deposits", description = "Uploading multiple-premined-deposits script", ) @@ -105,19 +107,81 @@ def perform_genesis_ceremony(plan, validators, jwt_file, chain_id, chain_spec, g plan.print(multiple_gentx_env_vars) plan.print(stored_configs) - eth_genesis_file = genesis_files["default"] - plan.run_sh( - run = "chmod +x /app/scripts/multiple-premined-deposits.sh && /app/scripts/multiple-premined-deposits.sh", + run = "chmod +x /app/scripts/multiple-premined-deposits-cl.sh && /app/scripts/multiple-premined-deposits-cl.sh", image = validators[0].cl_image, files = { "/app/scripts": "multiple-premined-deposits", - "/root/eth_genesis": eth_genesis_file, }, env_vars = multiple_gentx_env_vars, store = stored_configs, description = "Collecting beacond genesis files", ) + return stored_configs + +def modify_genesis_files_deposits(plan, validators, genesis_files, chain_id, chain_spec, stored_configs): + num_validators = len(validators) + + modify_genesis_file = plan.upload_files( + src = "./scripts/modify-genesis-with-deposits.sh", + name = "modify-genesis-with-deposits", + description = "Uploading modify-genesis-with-deposits script", + ) + + genesis_env_vars = node.get_genesis_env_vars("cl-validator-beaconkit-0", chain_id, chain_spec) + + # First operation: Get deposit values and store to files + deposit_count_store = StoreSpec( + src = "/tmp/values/deposit_count.txt", + name = "deposit-count", + ) + deposit_root_store = StoreSpec( + src = "/tmp/values/deposit_root.txt", + name = "deposit-root", + ) + + # Run the script and store the output files + result = plan.run_sh( + run = "chmod +x /app/scripts/modify-genesis-with-deposits.sh && /app/scripts/modify-genesis-with-deposits.sh", + image = validators[0].cl_image, + files = { + "/app/scripts": "modify-genesis-with-deposits", + "/root/eth_genesis": genesis_files["default"], + "/tmp/config_genesis/.beacond/config": "cosmos-genesis-final", + }, + env_vars = genesis_env_vars, + store = [deposit_count_store, deposit_root_store, stored_configs[num_validators]], + description = "Running modify genesis with deposits", + ) + + # Second operation: Read deposit count + result_one = plan.run_sh( + run = "cat /tmp/values/deposit_count.txt", + image = validators[0].cl_image, + files = { + "/tmp/values": "deposit-count", + }, + description = "Reading deposit count", + ) + deposit_count = result_one.output.strip().rstrip("\n") + plan.print("Deposit count:", deposit_count) + + # Third operation: Read deposit root + result_two = plan.run_sh( + run = "cat /tmp/values/deposit_root.txt", + image = validators[0].cl_image, + files = { + "/tmp/values": "deposit-root", + }, + description = "Reading deposit root", + ) + deposit_root = result_two.output.strip().rstrip("\n") + plan.print("Deposit root:", deposit_root) + + # Update env vars with parsed values + genesis_env_vars["GENESIS_DEPOSIT_COUNT_HEX"] = deposit_count + genesis_env_vars["GENESIS_DEPOSITS_ROOT"] = deposit_root + return genesis_env_vars def get_persistent_peers(plan, peers): persistent_peers = peers[:] @@ -136,7 +200,7 @@ def init_consensus_nodes(): collect_gentx = "/usr/bin/beacond genesis collect-premined-deposits --home {}".format("$BEACOND_HOME") return "{} && {} && {}".format(init_node, add_validator, collect_gentx) -def create_node_config(plan, node_struct, peers, paired_el_client_name, chain_id, chain_spec, jwt_file = None, kzg_trusted_setup_file = None): +def create_node_config(plan, node_struct, peers, paired_el_client_name, chain_id, chain_spec, genesis_deposits_root, genesis_deposit_count_hex, jwt_file = None, kzg_trusted_setup_file = None): engine_dial_url = "http://{}:{}".format(paired_el_client_name, execution.ENGINE_RPC_PORT_NUM) persistent_peers = get_persistent_peers(plan, peers) @@ -155,6 +219,8 @@ def create_node_config(plan, node_struct, peers, paired_el_client_name, chain_id engine_dial_url, chain_id, chain_spec, + genesis_deposits_root, + genesis_deposit_count_hex, entrypoint = ["bash", "-c"], cmd = [cmd], persistent_peers = persistent_peers, diff --git a/kurtosis/src/nodes/consensus/beacond/scripts/modify-genesis-with-deposits.sh b/kurtosis/src/nodes/consensus/beacond/scripts/modify-genesis-with-deposits.sh new file mode 100644 index 0000000000..9338af5a9e --- /dev/null +++ b/kurtosis/src/nodes/consensus/beacond/scripts/modify-genesis-with-deposits.sh @@ -0,0 +1,35 @@ +#!/bin/bash +# SPDX-License-Identifier: BUSL-1.1 +# +# Copyright (C) 2024, Berachain Foundation. All rights reserved. +# Use of this software is governed by the Business Source License included +# in the LICENSE file of this repository and at www.mariadb.com/bsl11. +# +# ANY USE OF THE LICENSED WORK IN VIOLATION OF THIS LICENSE WILL AUTOMATICALLY +# TERMINATE YOUR RIGHTS UNDER THIS LICENSE FOR THE CURRENT AND ALL OTHER +# VERSIONS OF THE LICENSED WORK. +# +# THIS LICENSE DOES NOT GRANT YOU ANY RIGHT IN ANY TRADEMARK OR LOGO OF +# LICENSOR OR ITS AFFILIATES (PROVIDED THAT YOU MAY USE A TRADEMARK OR LOGO OF +# LICENSOR AS EXPRESSLY REQUIRED BY THIS LICENSE). +# +# TO THE EXTENT PERMITTED BY APPLICABLE LAW, THE LICENSED WORK IS PROVIDED ON +# AN “AS IS” BASIS. LICENSOR HEREBY DISCLAIMS ALL WARRANTIES AND CONDITIONS, +# EXPRESS OR IMPLIED, INCLUDING (WITHOUT LIMITATION) WARRANTIES OF +# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT, AND +# TITLE. + + +# Sets the deposit storage in the the new eth-genesis file in the home directory. +/usr/bin/beacond genesis set-deposit-storage $ETH_GENESIS --home /tmp/config_genesis/.beacond + +# Get values directly from the storage fields +DEPOSIT_COUNT=$(jq -r '.alloc["0x4242424242424242424242424242424242424242"].storage["0x0000000000000000000000000000000000000000000000000000000000000000"]' /tmp/config_genesis/.beacond/genesis.json) +DEPOSIT_ROOT=$(jq -r '.alloc["0x4242424242424242424242424242424242424242"].storage["0x0000000000000000000000000000000000000000000000000000000000000001"]' /tmp/config_genesis/.beacond/genesis.json) + +/usr/bin/beacond genesis execution-payload /tmp/config_genesis/.beacond/genesis.json --home /tmp/config_genesis/.beacond + +# Write each value to separate files for easier parsing +mkdir -p /tmp/values +printf "%s" "$DEPOSIT_COUNT" > /tmp/values/deposit_count.txt +printf "%s" "$DEPOSIT_ROOT" > /tmp/values/deposit_root.txt diff --git a/kurtosis/src/nodes/consensus/beacond/scripts/multiple-premined-deposits.sh b/kurtosis/src/nodes/consensus/beacond/scripts/multiple-premined-deposits-cl.sh similarity index 95% rename from kurtosis/src/nodes/consensus/beacond/scripts/multiple-premined-deposits.sh rename to kurtosis/src/nodes/consensus/beacond/scripts/multiple-premined-deposits-cl.sh index f3bd96765c..1c668e1724 100644 --- a/kurtosis/src/nodes/consensus/beacond/scripts/multiple-premined-deposits.sh +++ b/kurtosis/src/nodes/consensus/beacond/scripts/multiple-premined-deposits-cl.sh @@ -33,6 +33,5 @@ for ((i=1; i<$NUM_VALS; i++)); do cp -r /tmp/config${i}/.beacond/config/premined-deposits/premined-deposit* /tmp/config_genesis/.beacond/config/premined-deposits/ done -/usr/bin/beacond genesis execution-payload $ETH_GENESIS --home /tmp/config_genesis/.beacond /usr/bin/beacond genesis collect-premined-deposits --home /tmp/config_genesis/.beacond diff --git a/kurtosis/src/nodes/execution/nethermind/genesis.json.template b/kurtosis/src/nodes/execution/nethermind/genesis.json.template index b40b41e6db..4602a9ae7b 100644 --- a/kurtosis/src/nodes/execution/nethermind/genesis.json.template +++ b/kurtosis/src/nodes/execution/nethermind/genesis.json.template @@ -394,7 +394,11 @@ "0x4242424242424242424242424242424242424242": { "balance": "0x0", "nonce": "0x1", - "code": "0x608060405260043610610093575f3560e01c8063577212fe11610066578063c53925d91161004c578063c53925d914610231578063e12cf4cb14610250578063fea7ab7714610263575f80fd5b8063577212fe146101cc5780639eaffa96146101ed575f80fd5b806301ffc9a7146100975780632dfdf0b5146100cb5780633523f9bd14610103578063560036ec14610126575b5f80fd5b3480156100a2575f80fd5b506100b66100b1366004610c22565b610282565b60405190151581526020015b60405180910390f35b3480156100d6575f80fd5b505f546100ea9067ffffffffffffffff1681565b60405167ffffffffffffffff90911681526020016100c2565b34801561010e575f80fd5b5061011860015481565b6040519081526020016100c2565b348015610131575f80fd5b50610193610140366004610c95565b80516020818301810180516003825292820191909301209152546bffffffffffffffffffffffff8116906c01000000000000000000000000900473ffffffffffffffffffffffffffffffffffffffff1682565b604080516bffffffffffffffffffffffff909316835273ffffffffffffffffffffffffffffffffffffffff9091166020830152016100c2565b3480156101d7575f80fd5b506101eb6101e6366004610dca565b61031a565b005b3480156101f8575f80fd5b5061020c610207366004610dca565b6103f0565b60405173ffffffffffffffffffffffffffffffffffffffff90911681526020016100c2565b34801561023c575f80fd5b506101eb61024b366004610dca565b610431565b6101eb61025e366004610e2c565b610658565b34801561026e575f80fd5b506101eb61027d366004610edb565b6109ab565b5f7fffffffff0000000000000000000000000000000000000000000000000000000082167f01ffc9a700000000000000000000000000000000000000000000000000000000148061031457507fffffffff0000000000000000000000000000000000000000000000000000000082167f136f920d00000000000000000000000000000000000000000000000000000000145b92915050565b6002828260405161032c929190610f2b565b908152604051908190036020019020543373ffffffffffffffffffffffffffffffffffffffff9091161461038c576040517f7c214f0400000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6003828260405161039e929190610f2b565b9081526040519081900360200181205f90556103bd9083908390610f2b565b604051908190038120907f1c0a7e1bd09da292425c039309671a03de56b89a0858598aab6df6ce84b006db905f90a25050565b5f60028383604051610403929190610f2b565b9081526040519081900360200190205473ffffffffffffffffffffffffffffffffffffffff16905092915050565b5f60038383604051610444929190610f2b565b908152604051908190036020019020805490915073ffffffffffffffffffffffffffffffffffffffff6c01000000000000000000000000820416906bffffffffffffffffffffffff163382146104c6576040517f819a0d0b00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6bffffffffffffffffffffffff42166104e26201518083610f67565b6bffffffffffffffffffffffff161115610528576040517fe8966d7a00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b5f6002868660405161053b929190610f2b565b9081526040519081900360200181205473ffffffffffffffffffffffffffffffffffffffff16915083906002906105759089908990610f2b565b908152604051908190036020018120805473ffffffffffffffffffffffffffffffffffffffff939093167fffffffffffffffffffffffff0000000000000000000000000000000000000000909316929092179091556003906105da9088908890610f2b565b9081526040519081900360200181205f90556105f99087908790610f2b565b6040805191829003822073ffffffffffffffffffffffffffffffffffffffff808716845284166020840152917f0adffd98d3072c48341843974dffd7a910bb849ba6ca04163d43bb26feb17403910160405180910390a2505050505050565b60308614610692576040517f9f10647200000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b602084146106cc576040517fb39bca1600000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60608214610706576040517f4be6321b00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b5f73ffffffffffffffffffffffffffffffffffffffff166002888860405161072f929190610f2b565b9081526040519081900360200190205473ffffffffffffffffffffffffffffffffffffffff16036108765773ffffffffffffffffffffffffffffffffffffffff81166107a7576040517f51969a7a00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b80600288886040516107ba929190610f2b565b908152604051908190036020018120805473ffffffffffffffffffffffffffffffffffffffff939093167fffffffffffffffffffffffff00000000000000000000000000000000000000009093169290921790915561081c9088908890610f2b565b6040805191829003822073ffffffffffffffffffffffffffffffffffffffff841683525f6020840152917f0adffd98d3072c48341843974dffd7a910bb849ba6ca04163d43bb26feb17403910160405180910390a26108c4565b73ffffffffffffffffffffffffffffffffffffffff8116156108c4576040517fc4142b4100000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b5f6108cd610b5d565b9050633b9aca0067ffffffffffffffff82161015610917576040517f0e1eddda00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b5f80547f68af751683498a9f9be59fe8b0d52a64dd155255d85cdb29fea30b1e3f891d46918a918a918a918a9187918b918b9167ffffffffffffffff16908061095f83610f8b565b91906101000a81548167ffffffffffffffff021916908367ffffffffffffffff160217905550604051610999989796959493929190610ffe565b60405180910390a15050505050505050565b5f600284846040516109be929190610f2b565b9081526040519081900360200190205473ffffffffffffffffffffffffffffffffffffffff169050338114610a1f576040517f7c214f0400000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b73ffffffffffffffffffffffffffffffffffffffff8216610a6c576040517fd92e233d00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b5f60038585604051610a7f929190610f2b565b908152604051908190036020018120426bffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff86166c01000000000000000000000000027fffffffffffffffffffffffffffffffffffffffff000000000000000000000000161781559150610af79086908690610f2b565b6040805191829003822073ffffffffffffffffffffffffffffffffffffffff8681168452851660208401524283830152905190917f7640ec3c8c4695deadda414dd20400acf275297a7c38715f9237657e97ddba5f919081900360600190a25050505050565b5f610b6c633b9aca0034611096565b15610ba3576040517f40567b3800000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b5f610bb2633b9aca00346110a9565b905067ffffffffffffffff811115610bf6576040517f2aa6673400000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b610c005f34610c05565b919050565b5f385f3884865af1610c1e5763b12d13eb5f526004601cfd5b5050565b5f60208284031215610c32575f80fd5b81357fffffffff0000000000000000000000000000000000000000000000000000000081168114610c61575f80fd5b9392505050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52604160045260245ffd5b5f60208284031215610ca5575f80fd5b813567ffffffffffffffff811115610cbb575f80fd5b8201601f81018413610ccb575f80fd5b803567ffffffffffffffff811115610ce557610ce5610c68565b6040517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0603f7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0601f8501160116810181811067ffffffffffffffff82111715610d5157610d51610c68565b604052818152828201602001861015610d68575f80fd5b816020840160208301375f91810160200191909152949350505050565b5f8083601f840112610d95575f80fd5b50813567ffffffffffffffff811115610dac575f80fd5b602083019150836020828501011115610dc3575f80fd5b9250929050565b5f8060208385031215610ddb575f80fd5b823567ffffffffffffffff811115610df1575f80fd5b610dfd85828601610d85565b90969095509350505050565b803573ffffffffffffffffffffffffffffffffffffffff81168114610c00575f80fd5b5f805f805f805f6080888a031215610e42575f80fd5b873567ffffffffffffffff811115610e58575f80fd5b610e648a828b01610d85565b909850965050602088013567ffffffffffffffff811115610e83575f80fd5b610e8f8a828b01610d85565b909650945050604088013567ffffffffffffffff811115610eae575f80fd5b610eba8a828b01610d85565b9094509250610ecd905060608901610e09565b905092959891949750929550565b5f805f60408486031215610eed575f80fd5b833567ffffffffffffffff811115610f03575f80fd5b610f0f86828701610d85565b9094509250610f22905060208501610e09565b90509250925092565b818382375f9101908152919050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52601160045260245ffd5b6bffffffffffffffffffffffff818116838216019081111561031457610314610f3a565b5f67ffffffffffffffff821667ffffffffffffffff8103610fae57610fae610f3a565b60010192915050565b81835281816020850137505f602082840101525f60207fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0601f840116840101905092915050565b60a081525f61101160a083018a8c610fb7565b828103602084015261102481898b610fb7565b905067ffffffffffffffff871660408401528281036060840152611049818688610fb7565b91505067ffffffffffffffff831660808301529998505050505050505050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52601260045260245ffd5b5f826110a4576110a4611069565b500690565b5f826110b7576110b7611069565b50049056fea264697066735822122069227307258cbe8f29985bb4f3e283b1b03d5c0cbab8add81bf3c22e3d13729664736f6c634300081a0033" + "code": "0x608060405260043610610093575f3560e01c8063577212fe11610066578063c53925d91161004c578063c53925d914610231578063e12cf4cb14610250578063fea7ab7714610263575f80fd5b8063577212fe146101cc5780639eaffa96146101ed575f80fd5b806301ffc9a7146100975780632dfdf0b5146100cb5780633523f9bd14610103578063560036ec14610126575b5f80fd5b3480156100a2575f80fd5b506100b66100b1366004610c22565b610282565b60405190151581526020015b60405180910390f35b3480156100d6575f80fd5b505f546100ea9067ffffffffffffffff1681565b60405167ffffffffffffffff90911681526020016100c2565b34801561010e575f80fd5b5061011860015481565b6040519081526020016100c2565b348015610131575f80fd5b50610193610140366004610c95565b80516020818301810180516003825292820191909301209152546bffffffffffffffffffffffff8116906c01000000000000000000000000900473ffffffffffffffffffffffffffffffffffffffff1682565b604080516bffffffffffffffffffffffff909316835273ffffffffffffffffffffffffffffffffffffffff9091166020830152016100c2565b3480156101d7575f80fd5b506101eb6101e6366004610dca565b61031a565b005b3480156101f8575f80fd5b5061020c610207366004610dca565b6103f0565b60405173ffffffffffffffffffffffffffffffffffffffff90911681526020016100c2565b34801561023c575f80fd5b506101eb61024b366004610dca565b610431565b6101eb61025e366004610e2c565b610658565b34801561026e575f80fd5b506101eb61027d366004610edb565b6109ab565b5f7fffffffff0000000000000000000000000000000000000000000000000000000082167f01ffc9a700000000000000000000000000000000000000000000000000000000148061031457507fffffffff0000000000000000000000000000000000000000000000000000000082167f136f920d00000000000000000000000000000000000000000000000000000000145b92915050565b6002828260405161032c929190610f2b565b908152604051908190036020019020543373ffffffffffffffffffffffffffffffffffffffff9091161461038c576040517f7c214f0400000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6003828260405161039e929190610f2b565b9081526040519081900360200181205f90556103bd9083908390610f2b565b604051908190038120907f1c0a7e1bd09da292425c039309671a03de56b89a0858598aab6df6ce84b006db905f90a25050565b5f60028383604051610403929190610f2b565b9081526040519081900360200190205473ffffffffffffffffffffffffffffffffffffffff16905092915050565b5f60038383604051610444929190610f2b565b908152604051908190036020019020805490915073ffffffffffffffffffffffffffffffffffffffff6c01000000000000000000000000820416906bffffffffffffffffffffffff163382146104c6576040517f819a0d0b00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6bffffffffffffffffffffffff42166104e26201518083610f67565b6bffffffffffffffffffffffff161115610528576040517fe8966d7a00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b5f6002868660405161053b929190610f2b565b9081526040519081900360200181205473ffffffffffffffffffffffffffffffffffffffff16915083906002906105759089908990610f2b565b908152604051908190036020018120805473ffffffffffffffffffffffffffffffffffffffff939093167fffffffffffffffffffffffff0000000000000000000000000000000000000000909316929092179091556003906105da9088908890610f2b565b9081526040519081900360200181205f90556105f99087908790610f2b565b6040805191829003822073ffffffffffffffffffffffffffffffffffffffff808716845284166020840152917f0adffd98d3072c48341843974dffd7a910bb849ba6ca04163d43bb26feb17403910160405180910390a2505050505050565b60308614610692576040517f9f10647200000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b602084146106cc576040517fb39bca1600000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60608214610706576040517f4be6321b00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b5f73ffffffffffffffffffffffffffffffffffffffff166002888860405161072f929190610f2b565b9081526040519081900360200190205473ffffffffffffffffffffffffffffffffffffffff16036108765773ffffffffffffffffffffffffffffffffffffffff81166107a7576040517f51969a7a00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b80600288886040516107ba929190610f2b565b908152604051908190036020018120805473ffffffffffffffffffffffffffffffffffffffff939093167fffffffffffffffffffffffff00000000000000000000000000000000000000009093169290921790915561081c9088908890610f2b565b6040805191829003822073ffffffffffffffffffffffffffffffffffffffff841683525f6020840152917f0adffd98d3072c48341843974dffd7a910bb849ba6ca04163d43bb26feb17403910160405180910390a26108c4565b73ffffffffffffffffffffffffffffffffffffffff8116156108c4576040517fc4142b4100000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b5f6108cd610b5d565b9050633b9aca0067ffffffffffffffff82161015610917576040517f0e1eddda00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b5f80547f68af751683498a9f9be59fe8b0d52a64dd155255d85cdb29fea30b1e3f891d46918a918a918a918a9187918b918b9167ffffffffffffffff16908061095f83610f8b565b91906101000a81548167ffffffffffffffff021916908367ffffffffffffffff160217905550604051610999989796959493929190610ffe565b60405180910390a15050505050505050565b5f600284846040516109be929190610f2b565b9081526040519081900360200190205473ffffffffffffffffffffffffffffffffffffffff169050338114610a1f576040517f7c214f0400000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b73ffffffffffffffffffffffffffffffffffffffff8216610a6c576040517fd92e233d00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b5f60038585604051610a7f929190610f2b565b908152604051908190036020018120426bffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff86166c01000000000000000000000000027fffffffffffffffffffffffffffffffffffffffff000000000000000000000000161781559150610af79086908690610f2b565b6040805191829003822073ffffffffffffffffffffffffffffffffffffffff8681168452851660208401524283830152905190917f7640ec3c8c4695deadda414dd20400acf275297a7c38715f9237657e97ddba5f919081900360600190a25050505050565b5f610b6c633b9aca0034611096565b15610ba3576040517f40567b3800000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b5f610bb2633b9aca00346110a9565b905067ffffffffffffffff811115610bf6576040517f2aa6673400000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b610c005f34610c05565b919050565b5f385f3884865af1610c1e5763b12d13eb5f526004601cfd5b5050565b5f60208284031215610c32575f80fd5b81357fffffffff0000000000000000000000000000000000000000000000000000000081168114610c61575f80fd5b9392505050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52604160045260245ffd5b5f60208284031215610ca5575f80fd5b813567ffffffffffffffff811115610cbb575f80fd5b8201601f81018413610ccb575f80fd5b803567ffffffffffffffff811115610ce557610ce5610c68565b6040517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0603f7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0601f8501160116810181811067ffffffffffffffff82111715610d5157610d51610c68565b604052818152828201602001861015610d68575f80fd5b816020840160208301375f91810160200191909152949350505050565b5f8083601f840112610d95575f80fd5b50813567ffffffffffffffff811115610dac575f80fd5b602083019150836020828501011115610dc3575f80fd5b9250929050565b5f8060208385031215610ddb575f80fd5b823567ffffffffffffffff811115610df1575f80fd5b610dfd85828601610d85565b90969095509350505050565b803573ffffffffffffffffffffffffffffffffffffffff81168114610c00575f80fd5b5f805f805f805f6080888a031215610e42575f80fd5b873567ffffffffffffffff811115610e58575f80fd5b610e648a828b01610d85565b909850965050602088013567ffffffffffffffff811115610e83575f80fd5b610e8f8a828b01610d85565b909650945050604088013567ffffffffffffffff811115610eae575f80fd5b610eba8a828b01610d85565b9094509250610ecd905060608901610e09565b905092959891949750929550565b5f805f60408486031215610eed575f80fd5b833567ffffffffffffffff811115610f03575f80fd5b610f0f86828701610d85565b9094509250610f22905060208501610e09565b90509250925092565b818382375f9101908152919050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52601160045260245ffd5b6bffffffffffffffffffffffff818116838216019081111561031457610314610f3a565b5f67ffffffffffffffff821667ffffffffffffffff8103610fae57610fae610f3a565b60010192915050565b81835281816020850137505f602082840101525f60207fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0601f840116840101905092915050565b60a081525f61101160a083018a8c610fb7565b828103602084015261102481898b610fb7565b905067ffffffffffffffff871660408401528281036060840152611049818688610fb7565b91505067ffffffffffffffff831660808301529998505050505050505050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52601260045260245ffd5b5f826110a4576110a4611069565b500690565b5f826110b7576110b7611069565b50049056fea264697066735822122069227307258cbe8f29985bb4f3e283b1b03d5c0cbab8add81bf3c22e3d13729664736f6c634300081a0033", + "storage": { + "0x0000000000000000000000000000000000000000000000000000000000000000": "{{.GENESIS_DEPOSIT_COUNT_HEX}}", + "0x0000000000000000000000000000000000000000000000000000000000000001": "{{.GENESIS_DEPOSITS_ROOT}}" + } } } } diff --git a/kurtosis/src/nodes/nodes.star b/kurtosis/src/nodes/nodes.star index 895d11d2b7..919ff1bf52 100644 --- a/kurtosis/src/nodes/nodes.star +++ b/kurtosis/src/nodes/nodes.star @@ -206,7 +206,7 @@ def int_to_hex(plan, n): ) return str(result.output.strip()) -def render_genesis_template(plan, template_path, chain_id, chain_id_hex): +def render_genesis_template(plan, template_path, chain_id, chain_id_hex, genesis_deposits_root, genesis_deposit_count_hex): """Helper function to render a specific genesis template""" genesis_template = read_file(src = template_path) @@ -217,15 +217,18 @@ def render_genesis_template(plan, template_path, chain_id, chain_id_hex): data = { "CHAIN_ID": chain_id, "CHAIN_ID_HEX": chain_id_hex, + "GENESIS_DEPOSIT_COUNT_HEX": genesis_deposit_count_hex, + "GENESIS_DEPOSITS_ROOT": genesis_deposits_root, }, ), }, - name = template_path, + # As we are rendering the template twice, add GENESIS_DEPOSITS_ROOT to the name + name = template_path + "_" + genesis_deposits_root, description = "Rendering genesis.json template", ) return artifact -def create_genesis_files(plan, chain_id): +def create_genesis_files_part1(plan, chain_id): """Creates genesis files for all client types and returns them as a dict""" # Convert chain_id to hexadecimal string @@ -239,6 +242,8 @@ def create_genesis_files(plan, chain_id): "execution/nethermind/genesis.json.template", chain_id, chain_id_hex, + "0x0000000000000000000000000000000000000000000000000000000000000000", + "0x0000000000000000000000000000000000000000000000000000000000000000", ) genesis_files["nethermind"] = nethermind_artifact @@ -249,6 +254,42 @@ def create_genesis_files(plan, chain_id): "../networks/kurtosis-devnet/network-configs/genesis.json.template", chain_id, chain_id_hex, + "0x0000000000000000000000000000000000000000000000000000000000000000", + "0x0000000000000000000000000000000000000000000000000000000000000000", + ) + genesis_files["default"] = default_artifact + + return genesis_files + +# This has the deposit contract storage slots and we need to modify the eth genesis files with them. +def create_genesis_files_part2(plan, chain_id, genesis_deposits_root, genesis_deposit_count_hex): + """Creates genesis files for all client types and returns them as a dict""" + + # Convert chain_id to hexadecimal string + chain_id_hex = int_to_hex(plan, int(chain_id)) + + genesis_files = {} + + # Render Nethermind genesis + nethermind_artifact = render_genesis_template( + plan, + "execution/nethermind/genesis.json.template", + chain_id, + chain_id_hex, + genesis_deposits_root, + genesis_deposit_count_hex, + ) + + genesis_files["nethermind"] = nethermind_artifact + + # Render default genesis for other clients + default_artifact = render_genesis_template( + plan, + "../networks/kurtosis-devnet/network-configs/genesis.json.template", + chain_id, + chain_id_hex, + genesis_deposits_root, + genesis_deposit_count_hex, ) genesis_files["default"] = default_artifact From 0a2bbe2344002fca07553c239dea89eebf3d2c3a Mon Sep 17 00:00:00 2001 From: nidhi-singh02 Date: Wed, 22 Jan 2025 15:49:31 +0530 Subject: [PATCH 02/12] e2e test added for deposit check Signed-off-by: nidhi-singh02 --- testing/e2e/e2e_staking_test.go | 63 +++++++++++++++++++++------------ 1 file changed, 40 insertions(+), 23 deletions(-) diff --git a/testing/e2e/e2e_staking_test.go b/testing/e2e/e2e_staking_test.go index cb3fcbffcf..25a29581ad 100644 --- a/testing/e2e/e2e_staking_test.go +++ b/testing/e2e/e2e_staking_test.go @@ -56,18 +56,6 @@ func (s *BeaconKitE2ESuite) TestDepositRobustness() { "every validator must get an equal amount of deposits", ) - // Get the consensus clients. - client0 := s.ConsensusClients()[config.ClientValidator0] - s.Require().NotNil(client0) - client1 := s.ConsensusClients()[config.ClientValidator1] - s.Require().NotNil(client1) - client2 := s.ConsensusClients()[config.ClientValidator2] - s.Require().NotNil(client2) - client3 := s.ConsensusClients()[config.ClientValidator3] - s.Require().NotNil(client3) - client4 := s.ConsensusClients()[config.ClientValidator4] - s.Require().NotNil(client4) - // // Check the validators' current voting power. // power0, err := client0.GetConsensusPower(s.Ctx()) // s.Require().NoError(err) @@ -80,6 +68,46 @@ func (s *BeaconKitE2ESuite) TestDepositRobustness() { // power4, err := client4.GetConsensusPower(s.Ctx()) // s.Require().NoError(err) + // Get the chain ID. + chainID, err := s.JSONRPCBalancer().ChainID(s.Ctx()) + s.Require().NoError(err) + + // Bind the deposit contract. + depositContractAddress := gethcommon.HexToAddress(spec.DefaultDepositContractAddress) + + dc, err := deposit.NewDepositContract(depositContractAddress, s.JSONRPCBalancer()) + s.Require().NoError(err) + + // Check deposit count at genesis + depositCount, err := dc.DepositCount(&bind.CallOpts{ + BlockNumber: big.NewInt(0), + }) + s.Require().NoError(err) + + s.Require().Equal(uint64(config.NumValidators), depositCount, + "initial deposit count should match number of validators") + + // Check genesis deposits root + genesisRoot, err := dc.GenesisDepositsRoot(&bind.CallOpts{ + BlockNumber: big.NewInt(0), + }) + s.Require().NoError(err) + s.Require().Len(genesisRoot[:], 32, "deposits root should be 32 bytes") + + // TODO: Compare with HashTreeRoot of genesis deposits + + // Get the consensus clients. + client0 := s.ConsensusClients()[config.ClientValidator0] + s.Require().NotNil(client0) + client1 := s.ConsensusClients()[config.ClientValidator1] + s.Require().NotNil(client1) + client2 := s.ConsensusClients()[config.ClientValidator2] + s.Require().NotNil(client2) + client3 := s.ConsensusClients()[config.ClientValidator3] + s.Require().NotNil(client3) + client4 := s.ConsensusClients()[config.ClientValidator4] + s.Require().NotNil(client4) + // Sender account sender := s.TestAccounts()[0] @@ -87,22 +115,11 @@ func (s *BeaconKitE2ESuite) TestDepositRobustness() { blkNum, err := s.JSONRPCBalancer().BlockNumber(s.Ctx()) s.Require().NoError(err) - // Get the chain ID. - chainID, err := s.JSONRPCBalancer().ChainID(s.Ctx()) - s.Require().NoError(err) - // Get original evm balance balance, err := s.JSONRPCBalancer().BalanceAt( s.Ctx(), sender.Address(), new(big.Int).SetUint64(blkNum), ) s.Require().NoError(err) - - // Bind the deposit contract. - depositContractAddress := gethcommon.HexToAddress(spec.DefaultDepositContractAddress) - - dc, err := deposit.NewDepositContract(depositContractAddress, s.JSONRPCBalancer()) - s.Require().NoError(err) - // Get the nonce. nonce, err := s.JSONRPCBalancer().NonceAt( From eed2954a0381c8d037b10ef2ca2e21a060912829 Mon Sep 17 00:00:00 2001 From: nidhi-singh02 Date: Wed, 22 Jan 2025 15:50:26 +0530 Subject: [PATCH 03/12] remove commented code Signed-off-by: nidhi-singh02 --- testing/e2e/e2e_staking_test.go | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/testing/e2e/e2e_staking_test.go b/testing/e2e/e2e_staking_test.go index 25a29581ad..ceb89dc359 100644 --- a/testing/e2e/e2e_staking_test.go +++ b/testing/e2e/e2e_staking_test.go @@ -56,18 +56,6 @@ func (s *BeaconKitE2ESuite) TestDepositRobustness() { "every validator must get an equal amount of deposits", ) - // // Check the validators' current voting power. - // power0, err := client0.GetConsensusPower(s.Ctx()) - // s.Require().NoError(err) - // power1, err := client1.GetConsensusPower(s.Ctx()) - // s.Require().NoError(err) - // power2, err := client2.GetConsensusPower(s.Ctx()) - // s.Require().NoError(err) - // power3, err := client3.GetConsensusPower(s.Ctx()) - // s.Require().NoError(err) - // power4, err := client4.GetConsensusPower(s.Ctx()) - // s.Require().NoError(err) - // Get the chain ID. chainID, err := s.JSONRPCBalancer().ChainID(s.Ctx()) s.Require().NoError(err) From e3da8224ae31372ab260fca9d430f06c3a2ad8ff Mon Sep 17 00:00:00 2001 From: shotes Date: Tue, 7 Jan 2025 13:10:53 +0900 Subject: [PATCH 04/12] Add code to grab withdrawals --- scripts/build/testing.mk | 8 +++- testing/e2e/e2e_staking_test.go | 76 ++++++++++++++++++++++++++++++--- 2 files changed, 76 insertions(+), 8 deletions(-) diff --git a/scripts/build/testing.mk b/scripts/build/testing.mk index 5e4a0879f8..90e8ce359d 100644 --- a/scripts/build/testing.mk +++ b/scripts/build/testing.mk @@ -289,4 +289,10 @@ test-e2e-4844: ## run e2e tests @$(MAKE) build-docker VERSION=kurtosis-local test-e2e-4844-no-build test-e2e-4844-no-build: - go test -timeout 0 -tags e2e,bls12381 ./testing/e2e/. -v -testify.m Test4844Live \ No newline at end of file + go test -timeout 0 -tags e2e,bls12381 ./testing/e2e/. -v -testify.m Test4844Live + +test-e2e-deposits: ## run e2e tests + @$(MAKE) build-docker VERSION=kurtosis-local test-e2e-deposits-no-build + +test-e2e-deposits-no-build: + go test -timeout 0 -tags e2e,bls12381 ./testing/e2e/. -v -testify.m TestDepositRobustness diff --git a/testing/e2e/e2e_staking_test.go b/testing/e2e/e2e_staking_test.go index ceb89dc359..5aa5399dec 100644 --- a/testing/e2e/e2e_staking_test.go +++ b/testing/e2e/e2e_staking_test.go @@ -21,6 +21,8 @@ package e2e_test import ( + "fmt" + "github.com/ethereum/go-ethereum/params" "math/big" "github.com/berachain/beacon-kit/config/spec" @@ -96,6 +98,44 @@ func (s *BeaconKitE2ESuite) TestDepositRobustness() { client4 := s.ConsensusClients()[config.ClientValidator4] s.Require().NotNil(client4) + // // Check the validators' current voting power. + // power0, err := client0.GetConsensusPower(s.Ctx()) + // s.Require().NoError(err) + // power1, err := client1.GetConsensusPower(s.Ctx()) + // s.Require().NoError(err) + // power2, err := client2.GetConsensusPower(s.Ctx()) + // s.Require().NoError(err) + // power3, err := client3.GetConsensusPower(s.Ctx()) + // s.Require().NoError(err) + // power4, err := client4.GetConsensusPower(s.Ctx()) + // s.Require().NoError(err) + + credentials0 := [32]byte{1, 0} + withdrawalAddress0 := gethcommon.Address(credentials0[12:]) + withdrawalBalance0Before, err := s.JSONRPCBalancer().BalanceAt(s.Ctx(), withdrawalAddress0, nil) + s.Require().NoError(err) + fmt.Println(withdrawalBalance0Before) + credentials1 := [32]byte{1, 1} + withdrawalAddress1 := gethcommon.Address(credentials1[12:]) + withdrawalBalance1Before, err := s.JSONRPCBalancer().BalanceAt(s.Ctx(), withdrawalAddress1, nil) + s.Require().NoError(err) + fmt.Println(withdrawalBalance1Before) + credentials2 := [32]byte{1, 2} + withdrawalAddress2 := gethcommon.Address(credentials2[12:]) + withdrawalBalance2Before, err := s.JSONRPCBalancer().BalanceAt(s.Ctx(), withdrawalAddress2, nil) + s.Require().NoError(err) + fmt.Println(withdrawalBalance2Before) + credentials3 := [32]byte{1, 3} + withdrawalAddress3 := gethcommon.Address(credentials3[12:]) + withdrawalBalance3Before, err := s.JSONRPCBalancer().BalanceAt(s.Ctx(), withdrawalAddress3, nil) + s.Require().NoError(err) + fmt.Println(withdrawalBalance3Before) + credentials4 := [32]byte{1, 4} + withdrawalAddress4 := gethcommon.Address(credentials4[12:]) + withdrawalBalance4Before, err := s.JSONRPCBalancer().BalanceAt(s.Ctx(), withdrawalAddress4, nil) + s.Require().NoError(err) + fmt.Println(withdrawalBalance4Before) + // Sender account sender := s.TestAccounts()[0] @@ -130,14 +170,19 @@ func (s *BeaconKitE2ESuite) TestDepositRobustness() { switch i % config.NumValidators { case 0: clientPubkey, err = client0.GetPubKey(s.Ctx()) + credentials = credentials0 case 1: clientPubkey, err = client1.GetPubKey(s.Ctx()) + credentials = credentials1 case 2: clientPubkey, err = client2.GetPubKey(s.Ctx()) + credentials = credentials2 case 3: clientPubkey, err = client3.GetPubKey(s.Ctx()) + credentials = credentials3 case 4: clientPubkey, err = client4.GetPubKey(s.Ctx()) + credentials = credentials4 } s.Require().NoError(err) pk, err = bls12381.NewPublicKeyFromBytes(clientPubkey) @@ -197,12 +242,12 @@ func (s *BeaconKitE2ESuite) TestDepositRobustness() { s.Require().Equal(-1, amtSpent.Cmp(upperBound), "amount spent is greater than upper bound") // TODO: determine why voting power is not increasing above 32e9. - // // Check that all validators' voting power have increased by - // // (NumDepositsLoad / NumValidators) * DepositAmount - // // after the end of the epoch (next multiple of 32 after receipt.BlockNumber). - // nextEpochBlockNum := (receipt.BlockNumber.Uint64()/32 + 1) * 32 - // err = s.WaitForFinalizedBlockNumber(nextEpochBlockNum + 1) - // s.Require().NoError(err) + // Check that all validators' voting power have increased by + // (NumDepositsLoad / NumValidators) * DepositAmount + // after the end of the epoch (next multiple of 32 after receipt.BlockNumber). + nextEpochBlockNum := (receipt.BlockNumber.Uint64()/32 + 1) * 32 + err = s.WaitForFinalizedBlockNumber(nextEpochBlockNum + 1) + s.Require().NoError(err) // power0After, err := client0.GetConsensusPower(s.Ctx()) // s.Require().NoError(err) @@ -215,10 +260,27 @@ func (s *BeaconKitE2ESuite) TestDepositRobustness() { // power4After, err := client4.GetConsensusPower(s.Ctx()) // s.Require().NoError(err) - // increaseAmt := NumDepositsLoad / config.NumValidators * uint64(DepositAmount/params.GWei) + increaseAmt := (NumDepositsLoad / config.NumValidators) * uint64(DepositAmount/params.GWei) // s.Require().Equal(power0+increaseAmt, power0After) // s.Require().Equal(power1+increaseAmt, power1After) // s.Require().Equal(power2+increaseAmt, power2After) // s.Require().Equal(power3+increaseAmt, power3After) // s.Require().Equal(power4+increaseAmt, power4After) + fmt.Println("Increase: ", increaseAmt) + + withdrawalBalance0After, err := s.JSONRPCBalancer().BalanceAt(s.Ctx(), withdrawalAddress0, nil) + s.Require().NoError(err) + fmt.Println(withdrawalBalance0After) + withdrawalBalance1After, err := s.JSONRPCBalancer().BalanceAt(s.Ctx(), withdrawalAddress1, nil) + s.Require().NoError(err) + fmt.Println(withdrawalBalance1After) + withdrawalBalance2After, err := s.JSONRPCBalancer().BalanceAt(s.Ctx(), withdrawalAddress2, nil) + s.Require().NoError(err) + fmt.Println(withdrawalBalance2After) + withdrawalBalance3After, err := s.JSONRPCBalancer().BalanceAt(s.Ctx(), withdrawalAddress3, nil) + s.Require().NoError(err) + fmt.Println(withdrawalBalance3After) + withdrawalBalance4After, err := s.JSONRPCBalancer().BalanceAt(s.Ctx(), withdrawalAddress4, nil) + s.Require().NoError(err) + fmt.Println(withdrawalBalance4After) } From 5aeccb15d4d5cfa00f7f8dbc3110a1b667f78eb1 Mon Sep 17 00:00:00 2001 From: shotes Date: Fri, 10 Jan 2025 12:51:29 +0900 Subject: [PATCH 05/12] more debugging --- testing/e2e/e2e_staking_test.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/testing/e2e/e2e_staking_test.go b/testing/e2e/e2e_staking_test.go index 5aa5399dec..c753ffb9c4 100644 --- a/testing/e2e/e2e_staking_test.go +++ b/testing/e2e/e2e_staking_test.go @@ -22,7 +22,6 @@ package e2e_test import ( "fmt" - "github.com/ethereum/go-ethereum/params" "math/big" "github.com/berachain/beacon-kit/config/spec" @@ -41,6 +40,8 @@ const ( // DepositAmount is the amount of BERA to deposit. DepositAmount = 32e18 + MaxEffectiveBalance = 32e9 + // BlocksToWait is the number of blocks to wait for the nodes to catch up. BlocksToWait = 10 ) @@ -260,13 +261,13 @@ func (s *BeaconKitE2ESuite) TestDepositRobustness() { // power4After, err := client4.GetConsensusPower(s.Ctx()) // s.Require().NoError(err) - increaseAmt := (NumDepositsLoad / config.NumValidators) * uint64(DepositAmount/params.GWei) + increaseAmt := float64(NumDepositsLoad/config.NumValidators) * DepositAmount // s.Require().Equal(power0+increaseAmt, power0After) // s.Require().Equal(power1+increaseAmt, power1After) // s.Require().Equal(power2+increaseAmt, power2After) // s.Require().Equal(power3+increaseAmt, power3After) // s.Require().Equal(power4+increaseAmt, power4After) - fmt.Println("Increase: ", increaseAmt) + fmt.Println(increaseAmt) withdrawalBalance0After, err := s.JSONRPCBalancer().BalanceAt(s.Ctx(), withdrawalAddress0, nil) s.Require().NoError(err) From 18fc9b0ecae91f9bbd7bc78f2e4fb619bb88697e Mon Sep 17 00:00:00 2001 From: shotes Date: Wed, 22 Jan 2025 21:41:40 +0900 Subject: [PATCH 06/12] Modifying deposit e2e testing --- config/spec/devnet.go | 3 + contracts/src/staking/DepositContract.sol | 4 +- node-api/backend/validator.go | 5 +- node-api/handlers/beacon/types/conversions.go | 13 ++ node-api/handlers/beacon/types/response.go | 23 +- state-transition/core/state/statedb.go | 4 +- state-transition/core/state_processor.go | 1 + .../core/state_processor_staking.go | 15 +- .../core/state_processor_withdrawals.go | 4 + testing/e2e/e2e_staking_test.go | 212 ++++++++---------- testing/e2e/suite/setup.go | 2 +- 11 files changed, 162 insertions(+), 124 deletions(-) diff --git a/config/spec/devnet.go b/config/spec/devnet.go index 333acaff78..45e7a3bdbd 100644 --- a/config/spec/devnet.go +++ b/config/spec/devnet.go @@ -42,6 +42,9 @@ const ( // in the kurtosis network. func DevnetChainSpec() (chain.Spec, error) { devnetSpec := BaseSpec() + devnetSpec.EffectiveBalanceIncrement = 10_000e9 + devnetSpec.MaxEffectiveBalance = 10_000_000e9 + devnetSpec.EjectionBalance = 250_000*1e9 - devnetSpec.EffectiveBalanceIncrement devnetSpec.DepositEth1ChainID = DevnetEth1ChainID devnetSpec.EVMInflationAddress = common.NewExecutionAddressFromHex( DevnetEVMInflationAddress, diff --git a/contracts/src/staking/DepositContract.sol b/contracts/src/staking/DepositContract.sol index 2673f6a0f7..e4ffdcf9a7 100644 --- a/contracts/src/staking/DepositContract.sol +++ b/contracts/src/staking/DepositContract.sol @@ -17,8 +17,8 @@ contract DepositContract is IDepositContract, ERC165 { /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev The minimum amount of `BERA` to deposit. - /// @dev This is 1 ether in Gwei since our deposit contract denominates in Gwei. 1e9 * 1e9 = 1e18. - uint64 internal constant MIN_DEPOSIT_AMOUNT_IN_GWEI = 1e9; + /// @dev This is 10000 Gwei since our deposit contract denominates in Gwei. 10000 * 1e9 = 1e13. + uint64 internal constant MIN_DEPOSIT_AMOUNT_IN_GWEI = 10000; /// @dev The length of the public key, PUBLIC_KEY_LENGTH bytes. uint8 internal constant PUBLIC_KEY_LENGTH = 48; diff --git a/node-api/backend/validator.go b/node-api/backend/validator.go index 330a2ed99a..0c94452226 100644 --- a/node-api/backend/validator.go +++ b/node-api/backend/validator.go @@ -21,6 +21,7 @@ package backend import ( + "fmt" "github.com/berachain/beacon-kit/node-api/backend/utils" beacontypes "github.com/berachain/beacon-kit/node-api/handlers/beacon/types" "github.com/berachain/beacon-kit/primitives/math" @@ -54,7 +55,7 @@ func (b Backend) ValidatorByID( Balance: balance.Unwrap(), }, Status: "active_ongoing", // TODO: fix - Validator: validator, + Validator: beacontypes.ValidatorFromConsensus(validator), }, nil } @@ -68,6 +69,8 @@ func (b Backend) ValidatorsByIDs( // query and then filtering but blocked by the fact that IDs // can be indices and the hard type only holds its own pubkey. validatorData, err := b.ValidatorByID(slot, id) + fmt.Println("DEBUG: Grabbing validator for id", id, validatorData) + fmt.Println("DEBUG: validator:", validatorData.Validator) if err != nil { return nil, err } diff --git a/node-api/handlers/beacon/types/conversions.go b/node-api/handlers/beacon/types/conversions.go index 5fcca4d431..68cf33aa94 100644 --- a/node-api/handlers/beacon/types/conversions.go +++ b/node-api/handlers/beacon/types/conversions.go @@ -60,3 +60,16 @@ func SidecarFromConsensus(sc *datypes.BlobSidecar) *Sidecar { KZGCommitmentInclusionProof: proofs, } } + +func ValidatorFromConsensus(v *ctypes.Validator) *Validator { + return &Validator{ + PublicKey: v.GetPubkey().String(), + WithdrawalCredentials: v.GetWithdrawalCredentials().String(), + EffectiveBalance: v.GetEffectiveBalance().Base10(), + Slashed: v.IsSlashed(), + ActivationEligibilityEpoch: v.GetActivationEligibilityEpoch().Base10(), + ActivationEpoch: v.GetActivationEpoch().Base10(), + ExitEpoch: v.GetExitEpoch().Base10(), + WithdrawableEpoch: v.GetWithdrawableEpoch().Base10(), + } +} diff --git a/node-api/handlers/beacon/types/response.go b/node-api/handlers/beacon/types/response.go index 6801b59faf..c11976396b 100644 --- a/node-api/handlers/beacon/types/response.go +++ b/node-api/handlers/beacon/types/response.go @@ -21,10 +21,15 @@ package types import ( - ctypes "github.com/berachain/beacon-kit/consensus-types/types" "github.com/berachain/beacon-kit/primitives/common" ) +type GenericResponse struct { + ExecutionOptimistic bool `json:"execution_optimistic"` + Finalized bool `json:"finalized"` + Data any `json:"data"` +} + type ValidatorResponse struct { ExecutionOptimistic bool `json:"execution_optimistic"` Finalized bool `json:"finalized"` @@ -74,8 +79,8 @@ type RootData struct { type ValidatorData struct { ValidatorBalanceData - Status string `json:"status"` - Validator *ctypes.Validator `json:"validator"` + Status string `json:"status"` + Validator *Validator `json:"validator"` } type ValidatorBalanceData struct { @@ -83,6 +88,18 @@ type ValidatorBalanceData struct { Balance uint64 `json:"balance,string"` } +// Validator is the spec representation of the struct. +type Validator struct { + PublicKey string `json:"pubkey"` + WithdrawalCredentials string `json:"withdrawal_credentials"` + EffectiveBalance string `json:"effective_balance"` + Slashed bool `json:"slashed"` + ActivationEligibilityEpoch string `json:"activation_eligibility_epoch"` + ActivationEpoch string `json:"activation_epoch"` + ExitEpoch string `json:"exit_epoch"` + WithdrawableEpoch string `json:"withdrawable_epoch"` +} + //nolint:staticcheck // todo: figure this out. type CommitteeData struct { Index uint64 `json:"index,string"` diff --git a/state-transition/core/state/statedb.go b/state-transition/core/state/statedb.go index caf04f28da..268ce696d1 100644 --- a/state-transition/core/state/statedb.go +++ b/state-transition/core/state/statedb.go @@ -22,7 +22,7 @@ package state import ( "context" - + "fmt" "github.com/berachain/beacon-kit/chain" ctypes "github.com/berachain/beacon-kit/consensus-types/types" engineprimitives "github.com/berachain/beacon-kit/engine-primitives/engine-primitives" @@ -148,7 +148,6 @@ func (s *StateDB) ExpectedWithdrawals() (engineprimitives.Withdrawals, error) { if err != nil { return nil, err } - // Set the amount of the withdrawal depending on the balance of the validator. if validator.IsFullyWithdrawable(balance, epoch) { withdrawalAddress, err = validator.GetWithdrawalCredentials().ToExecutionAddress() @@ -168,6 +167,7 @@ func (s *StateDB) ExpectedWithdrawals() (engineprimitives.Withdrawals, error) { } else if validator.IsPartiallyWithdrawable( balance, math.Gwei(s.cs.MaxEffectiveBalance()), ) { + fmt.Println("DEBUG: validator is withdrawable!", validator.WithdrawalCredentials, balance) withdrawalAddress, err = validator.GetWithdrawalCredentials().ToExecutionAddress() if err != nil { return nil, err diff --git a/state-transition/core/state_processor.go b/state-transition/core/state_processor.go index a0cf092a4f..9db9b8afd5 100644 --- a/state-transition/core/state_processor.go +++ b/state-transition/core/state_processor.go @@ -390,6 +390,7 @@ func (sp *StateProcessor[_]) processEffectiveBalanceUpdates(st *state.StateDB) e math.U64(sp.cs.EffectiveBalanceIncrement()), math.U64(sp.cs.MaxEffectiveBalance()), ) + sp.logger.Info("DEBUG: setting effective balance", "idx", idx, "beforeBalance", val.GetEffectiveBalance(), "afterBalance", updatedBalance) val.SetEffectiveBalance(updatedBalance) if err = st.UpdateValidatorAtIndex(idx, val); err != nil { return err diff --git a/state-transition/core/state_processor_staking.go b/state-transition/core/state_processor_staking.go index ac0883ced3..700a278802 100644 --- a/state-transition/core/state_processor_staking.go +++ b/state-transition/core/state_processor_staking.go @@ -80,6 +80,7 @@ func (sp *StateProcessor[_]) processDeposit(st *state.StateDB, dep *ctypes.Depos "Processed deposit to set Eth 1 deposit index", "previous", eth1DepositIndex, "new", eth1DepositIndex+1, ) + sp.logger.Info("Processed deposit with creds", "creds", dep.Credentials) if err = sp.applyDeposit(st, dep); err != nil { return fmt.Errorf("failed to apply deposit: %w", err) } @@ -89,6 +90,7 @@ func (sp *StateProcessor[_]) processDeposit(st *state.StateDB, dep *ctypes.Depos // applyDeposit processes the deposit and ensures it matches the local state. func (sp *StateProcessor[_]) applyDeposit(st *state.StateDB, dep *ctypes.Deposit) error { idx, err := st.ValidatorIndexByPubkey(dep.GetPubkey()) + sp.logger.Info("Processing deposit", "pubkey", dep.GetPubkey(), "index", idx, "depIdx", dep.GetIndex()) if err != nil { sp.logger.Info("Validator does not exist so creating", "pubkey", dep.GetPubkey(), "index", dep.GetIndex(), "deposit_amount", dep.GetAmount()) @@ -97,16 +99,27 @@ func (sp *StateProcessor[_]) applyDeposit(st *state.StateDB, dep *ctypes.Deposit // ErrNotFound from other kind of errors return sp.createValidator(st, dep) } + preBalance, err := st.GetBalance(idx) + if err != nil { + fmt.Println("DEBUG: FAILED TO GET PRE BALANCE") + } // if validator exist, just update its balance if err = st.IncreaseBalance(idx, dep.GetAmount()); err != nil { return err } + newBalance, err := st.GetBalance(idx) + if err != nil { + fmt.Println("DEBUG: FAILED TO GET BALANCE") + } + sp.logger.Info( "Processed deposit to increase balance", - "deposit_amount", float64(dep.GetAmount().Unwrap())/math.GweiPerWei, + "deposit_amount", dep.GetAmount().Unwrap(), "validator_index", idx, + "pre_balance", preBalance.Base10(), + "new_balance", newBalance.Base10(), ) return nil } diff --git a/state-transition/core/state_processor_withdrawals.go b/state-transition/core/state_processor_withdrawals.go index 1579e69852..242bfc775e 100644 --- a/state-transition/core/state_processor_withdrawals.go +++ b/state-transition/core/state_processor_withdrawals.go @@ -83,6 +83,10 @@ func (sp *StateProcessor[_]) processWithdrawals( spew.Sdump(payloadWithdrawals[i]), ) } + sp.logger.Info("Processing withdrawal", + "address", expectedWithdrawals[i].Address, + "amount", expectedWithdrawals[i].Amount, + ) if err = st.DecreaseBalance( expectedWithdrawals[i].GetValidatorIndex(), expectedWithdrawals[i].GetAmount(), diff --git a/testing/e2e/e2e_staking_test.go b/testing/e2e/e2e_staking_test.go index c753ffb9c4..e88abba462 100644 --- a/testing/e2e/e2e_staking_test.go +++ b/testing/e2e/e2e_staking_test.go @@ -22,6 +22,9 @@ package e2e_test import ( "fmt" + "github.com/attestantio/go-eth2-client/api" + "github.com/attestantio/go-eth2-client/spec/phase0" + "github.com/berachain/beacon-kit/testing/e2e/suite/types" "math/big" "github.com/berachain/beacon-kit/config/spec" @@ -35,17 +38,22 @@ import ( const ( // NumDepositsLoad is the number of deposits to load in the Deposit Robustness e2e test. - NumDepositsLoad uint64 = 500 - - // DepositAmount is the amount of BERA to deposit. - DepositAmount = 32e18 - - MaxEffectiveBalance = 32e9 + NumDepositsLoad uint64 = 20 // BlocksToWait is the number of blocks to wait for the nodes to catch up. BlocksToWait = 10 ) +// Contains pre-test state for validator info to facilitate validation of the post-state. +type ValidatorTestStruct struct { + Index uint64 + Power *big.Int + WithdrawalBalance *big.Int + WithdrawalCredentials [32]byte + Name string + Client *types.ConsensusClient +} + // TestDepositRobustness tests sending a large number of deposits txs to the Deposit Contract. // Then it checks whether all the validators' voting power have increased by the correct amount. // @@ -54,6 +62,20 @@ const ( // 2) Add staking tests for adding a new validator to the network. // 3) Add staking tests for hitting the validator set cap and eviction. func (s *BeaconKitE2ESuite) TestDepositRobustness() { + chainspec, err := spec.DevnetChainSpec() + s.Require().NoError(err) + WeiPerGwei := big.NewInt(1e9) + + // TODO Figure out how to change this value to the expected MAINNET chainspec value during testing. + // This value is determined by the MIN_DEPOSIT_AMOUNT_IN_GWEI variable from the deposit contract. + ContractMinDepositAmountWei := big.NewInt(1e9 * 1e9) + DepositAmountWei := new(big.Int).Mul(ContractMinDepositAmountWei, big.NewInt(2)) + DepositAmountGwei := new(big.Int).Div(DepositAmountWei, WeiPerGwei) + MaxEffectiveBalanceGwei := new(big.Int).SetUint64(chainspec.MaxEffectiveBalance()) + + // Our deposits should be greater than the min deposit amount. + s.Require().Equal(1, DepositAmountWei.Cmp(ContractMinDepositAmountWei)) + s.Require().Equal( 0, int(NumDepositsLoad%config.NumValidators), "every validator must get an equal amount of deposits", @@ -87,55 +109,43 @@ func (s *BeaconKitE2ESuite) TestDepositRobustness() { // TODO: Compare with HashTreeRoot of genesis deposits - // Get the consensus clients. - client0 := s.ConsensusClients()[config.ClientValidator0] - s.Require().NotNil(client0) - client1 := s.ConsensusClients()[config.ClientValidator1] - s.Require().NotNil(client1) - client2 := s.ConsensusClients()[config.ClientValidator2] - s.Require().NotNil(client2) - client3 := s.ConsensusClients()[config.ClientValidator3] - s.Require().NotNil(client3) - client4 := s.ConsensusClients()[config.ClientValidator4] - s.Require().NotNil(client4) - - // // Check the validators' current voting power. - // power0, err := client0.GetConsensusPower(s.Ctx()) - // s.Require().NoError(err) - // power1, err := client1.GetConsensusPower(s.Ctx()) - // s.Require().NoError(err) - // power2, err := client2.GetConsensusPower(s.Ctx()) - // s.Require().NoError(err) - // power3, err := client3.GetConsensusPower(s.Ctx()) - // s.Require().NoError(err) - // power4, err := client4.GetConsensusPower(s.Ctx()) - // s.Require().NoError(err) - - credentials0 := [32]byte{1, 0} - withdrawalAddress0 := gethcommon.Address(credentials0[12:]) - withdrawalBalance0Before, err := s.JSONRPCBalancer().BalanceAt(s.Ctx(), withdrawalAddress0, nil) - s.Require().NoError(err) - fmt.Println(withdrawalBalance0Before) - credentials1 := [32]byte{1, 1} - withdrawalAddress1 := gethcommon.Address(credentials1[12:]) - withdrawalBalance1Before, err := s.JSONRPCBalancer().BalanceAt(s.Ctx(), withdrawalAddress1, nil) - s.Require().NoError(err) - fmt.Println(withdrawalBalance1Before) - credentials2 := [32]byte{1, 2} - withdrawalAddress2 := gethcommon.Address(credentials2[12:]) - withdrawalBalance2Before, err := s.JSONRPCBalancer().BalanceAt(s.Ctx(), withdrawalAddress2, nil) - s.Require().NoError(err) - fmt.Println(withdrawalBalance2Before) - credentials3 := [32]byte{1, 3} - withdrawalAddress3 := gethcommon.Address(credentials3[12:]) - withdrawalBalance3Before, err := s.JSONRPCBalancer().BalanceAt(s.Ctx(), withdrawalAddress3, nil) - s.Require().NoError(err) - fmt.Println(withdrawalBalance3Before) - credentials4 := [32]byte{1, 4} - withdrawalAddress4 := gethcommon.Address(credentials4[12:]) - withdrawalBalance4Before, err := s.JSONRPCBalancer().BalanceAt(s.Ctx(), withdrawalAddress4, nil) + apiClient := s.ConsensusClients()[config.ClientValidator0] + + // Grab genesis validators to get withdrawal creds. + s.Require().NoError(apiClient.Connect(s.Ctx())) + response, err := apiClient.BeaconKitNodeClient.Validators(s.Ctx(), &api.ValidatorsOpts{ + State: "genesis", + Indices: []phase0.ValidatorIndex{0, 1, 2, 3, 4}, + }) s.Require().NoError(err) - fmt.Println(withdrawalBalance4Before) + vals := response.Data + s.Require().Len(vals, config.NumValidators) + s.Require().Len(s.ConsensusClients(), config.NumValidators) + + // Grab pre-state data for each validator. + validators := make([]*ValidatorTestStruct, config.NumValidators) + var idx uint64 = 0 + for name, client := range s.ConsensusClients() { + power, err := client.GetConsensusPower(s.Ctx()) + s.Require().NoError(err) + + creds := [32]byte(vals[phase0.ValidatorIndex(idx)].Validator.WithdrawalCredentials) + withdrawalAddress := gethcommon.Address(creds[12:]) + withdrawalBalance, err := s.JSONRPCBalancer().BalanceAt(s.Ctx(), withdrawalAddress, nil) + s.Require().NoError(err) + fmt.Println(withdrawalBalance) + + // Populate the validators testing struct so we can keep track of the pre-state. + validators[idx] = &ValidatorTestStruct{ + Index: idx, + Power: new(big.Int).SetUint64(power), + WithdrawalBalance: withdrawalBalance, + WithdrawalCredentials: creds, + Name: name, + Client: client, + } + idx++ + } // Sender account sender := s.TestAccounts()[0] @@ -149,8 +159,8 @@ func (s *BeaconKitE2ESuite) TestDepositRobustness() { s.Ctx(), sender.Address(), new(big.Int).SetUint64(blkNum), ) s.Require().NoError(err) - // Get the nonce. + // Get the nonce. nonce, err := s.JSONRPCBalancer().NonceAt( s.Ctx(), sender.Address(), new(big.Int).SetUint64(blkNum), ) @@ -160,31 +170,15 @@ func (s *BeaconKitE2ESuite) TestDepositRobustness() { tx *coretypes.Transaction clientPubkey []byte pk *bls12381.PubKey - credentials [32]byte signature [96]byte - value, _ = big.NewFloat(DepositAmount).Int(nil) + value = DepositAmountWei signer = sender.SignerFunc(chainID) from = sender.Address() ) for i := range NumDepositsLoad { // Create a deposit transaction using the default validators' pubkeys. - switch i % config.NumValidators { - case 0: - clientPubkey, err = client0.GetPubKey(s.Ctx()) - credentials = credentials0 - case 1: - clientPubkey, err = client1.GetPubKey(s.Ctx()) - credentials = credentials1 - case 2: - clientPubkey, err = client2.GetPubKey(s.Ctx()) - credentials = credentials2 - case 3: - clientPubkey, err = client3.GetPubKey(s.Ctx()) - credentials = credentials3 - case 4: - clientPubkey, err = client4.GetPubKey(s.Ctx()) - credentials = credentials4 - } + curVal := validators[i%config.NumValidators] + clientPubkey, err = curVal.Client.GetPubKey(s.Ctx()) s.Require().NoError(err) pk, err = bls12381.NewPublicKeyFromBytes(clientPubkey) s.Require().NoError(err) @@ -203,9 +197,9 @@ func (s *BeaconKitE2ESuite) TestDepositRobustness() { Nonce: new(big.Int).SetUint64(nonce + i), GasLimit: 1000000, Context: s.Ctx(), - }, pubkey, credentials[:], signature[:], operator) + }, pubkey, curVal.WithdrawalCredentials[:], signature[:], operator) s.Require().NoError(err) - s.Logger().Info("Deposit tx created", "num", i+1, "hash", tx.Hash().Hex()) + s.Logger().Info("Deposit tx created", "num", i+1, "hash", tx.Hash().Hex(), "value", value) } // Wait for the final deposit tx to be mined. @@ -223,9 +217,9 @@ func (s *BeaconKitE2ESuite) TestDepositRobustness() { s.Require().NoError(err) // Compare height of nodes 0 and 1 - height, err := client0.ABCIInfo(s.Ctx()) + height, err := validators[0].Client.ABCIInfo(s.Ctx()) s.Require().NoError(err) - height2, err := client1.ABCIInfo(s.Ctx()) + height2, err := validators[1].Client.ABCIInfo(s.Ctx()) s.Require().NoError(err) s.Require().InDelta(height.Response.LastBlockHeight, height2.Response.LastBlockHeight, 1) @@ -234,7 +228,7 @@ func (s *BeaconKitE2ESuite) TestDepositRobustness() { s.Require().NoError(err) // Check that the eth spent is somewhere~ (gas) between - // (DepositAmount * NumDepositsLoad, DepositAmount * NumDepositsLoad + 2ether) + // (DepositAmountWei * NumDepositsLoad, DepositAmountWei * NumDepositsLoad + 2ether) lowerBound := new(big.Int).Mul(value, new(big.Int).SetUint64(NumDepositsLoad)) upperBound := new(big.Int).Add(lowerBound, big.NewInt(2e18)) amtSpent := new(big.Int).Sub(balance, postDepositBalance) @@ -244,44 +238,34 @@ func (s *BeaconKitE2ESuite) TestDepositRobustness() { // TODO: determine why voting power is not increasing above 32e9. // Check that all validators' voting power have increased by - // (NumDepositsLoad / NumValidators) * DepositAmount + // (NumDepositsLoad / NumValidators) * DepositAmountWei // after the end of the epoch (next multiple of 32 after receipt.BlockNumber). nextEpochBlockNum := (receipt.BlockNumber.Uint64()/32 + 1) * 32 err = s.WaitForFinalizedBlockNumber(nextEpochBlockNum + 1) s.Require().NoError(err) - // power0After, err := client0.GetConsensusPower(s.Ctx()) - // s.Require().NoError(err) - // power1After, err := client1.GetConsensusPower(s.Ctx()) - // s.Require().NoError(err) - // power2After, err := client2.GetConsensusPower(s.Ctx()) - // s.Require().NoError(err) - // power3After, err := client3.GetConsensusPower(s.Ctx()) - // s.Require().NoError(err) - // power4After, err := client4.GetConsensusPower(s.Ctx()) - // s.Require().NoError(err) - - increaseAmt := float64(NumDepositsLoad/config.NumValidators) * DepositAmount - // s.Require().Equal(power0+increaseAmt, power0After) - // s.Require().Equal(power1+increaseAmt, power1After) - // s.Require().Equal(power2+increaseAmt, power2After) - // s.Require().Equal(power3+increaseAmt, power3After) - // s.Require().Equal(power4+increaseAmt, power4After) - fmt.Println(increaseAmt) - - withdrawalBalance0After, err := s.JSONRPCBalancer().BalanceAt(s.Ctx(), withdrawalAddress0, nil) - s.Require().NoError(err) - fmt.Println(withdrawalBalance0After) - withdrawalBalance1After, err := s.JSONRPCBalancer().BalanceAt(s.Ctx(), withdrawalAddress1, nil) - s.Require().NoError(err) - fmt.Println(withdrawalBalance1After) - withdrawalBalance2After, err := s.JSONRPCBalancer().BalanceAt(s.Ctx(), withdrawalAddress2, nil) - s.Require().NoError(err) - fmt.Println(withdrawalBalance2After) - withdrawalBalance3After, err := s.JSONRPCBalancer().BalanceAt(s.Ctx(), withdrawalAddress3, nil) - s.Require().NoError(err) - fmt.Println(withdrawalBalance3After) - withdrawalBalance4After, err := s.JSONRPCBalancer().BalanceAt(s.Ctx(), withdrawalAddress4, nil) - s.Require().NoError(err) - fmt.Println(withdrawalBalance4After) + // TODO: Substracting the first NumValidators deposits because those are getting + // overwritten due to deposit contract not being initialized during genesis. + depositsPerValidator := (NumDepositsLoad - config.NumValidators) / config.NumValidators + increaseAmt := new(big.Int).Mul(DepositAmountGwei, big.NewInt(int64(depositsPerValidator))) + + fmt.Println("Max:", MaxEffectiveBalanceGwei.String()) + for _, val := range validators { + // TODO: Make this go over the MaxEffectiveBalance + // Get the validator powers for each validator and check that they increased by the expected amount. + // Consensus Power is in Gwei. + powerAfterRaw, err := val.Client.GetConsensusPower(s.Ctx()) + s.Require().NoError(err) + powerAfter := new(big.Int).SetUint64(powerAfterRaw) + fmt.Println("PowAft:", powerAfter.String()) + fmt.Println("PowBef:", val.Power.String()) + powerDiff := new(big.Int).Sub(powerAfter, val.Power) + s.Require().Equal(0, powerDiff.Cmp(increaseAmt)) + + // Grab the validator withdrawal balances and check that they increased by the expected amount. + withdrawalAddress := gethcommon.Address(val.WithdrawalCredentials[12:]) + withdrawalBalanceAfter, err := s.JSONRPCBalancer().BalanceAt(s.Ctx(), withdrawalAddress, nil) + s.Require().NoError(err) + fmt.Println(withdrawalBalanceAfter) + } } diff --git a/testing/e2e/suite/setup.go b/testing/e2e/suite/setup.go index 4d672a17b5..782d1241ca 100644 --- a/testing/e2e/suite/setup.go +++ b/testing/e2e/suite/setup.go @@ -389,7 +389,7 @@ func (s *KurtosisE2ESuite) TearDownSuite() { s.Require().Nil(res.ExecutionError, "Error stopping consensus client") s.Require().Empty(res.ValidationErrors, "Error stopping consensus client") } - s.Require().NoError(s.kCtx.DestroyEnclave(s.ctx, "e2e-test-enclave")) + //s.Require().NoError(s.kCtx.DestroyEnclave(s.ctx, "e2e-test-enclave")) } // CheckForSuccessfulTx returns true if the transaction was successful. From 858e3ade0031a6884b3b5d8d38a2f63aa898ed45 Mon Sep 17 00:00:00 2001 From: shotes Date: Wed, 22 Jan 2025 22:19:10 +0900 Subject: [PATCH 07/12] Undo chainspec changes --- config/spec/devnet.go | 3 --- 1 file changed, 3 deletions(-) diff --git a/config/spec/devnet.go b/config/spec/devnet.go index 45e7a3bdbd..333acaff78 100644 --- a/config/spec/devnet.go +++ b/config/spec/devnet.go @@ -42,9 +42,6 @@ const ( // in the kurtosis network. func DevnetChainSpec() (chain.Spec, error) { devnetSpec := BaseSpec() - devnetSpec.EffectiveBalanceIncrement = 10_000e9 - devnetSpec.MaxEffectiveBalance = 10_000_000e9 - devnetSpec.EjectionBalance = 250_000*1e9 - devnetSpec.EffectiveBalanceIncrement devnetSpec.DepositEth1ChainID = DevnetEth1ChainID devnetSpec.EVMInflationAddress = common.NewExecutionAddressFromHex( DevnetEVMInflationAddress, From 493c9d203ad4a5bf3993fcfd87be1895edef7706 Mon Sep 17 00:00:00 2001 From: shotes Date: Thu, 23 Jan 2025 00:22:15 +0900 Subject: [PATCH 08/12] Make test case work and remove debug --- config/spec/devnet.go | 2 +- node-api/backend/validator.go | 3 -- state-transition/core/state/statedb.go | 2 +- state-transition/core/state_processor.go | 1 - .../core/state_processor_staking.go | 11 ----- testing/e2e/e2e_staking_test.go | 42 +++++++++---------- 6 files changed, 23 insertions(+), 38 deletions(-) diff --git a/config/spec/devnet.go b/config/spec/devnet.go index 333acaff78..213b77e610 100644 --- a/config/spec/devnet.go +++ b/config/spec/devnet.go @@ -35,7 +35,7 @@ const ( // MaxStakeAmount is the maximum amount of native EVM balance (in units // of Gwei) that can be staked. - MaxStakeAmount = 4000e9 + MaxStakeAmount = 400e9 ) // DevnetChainSpec is the ChainSpec for the localnet. Also used for e2e tests diff --git a/node-api/backend/validator.go b/node-api/backend/validator.go index 0c94452226..a339912318 100644 --- a/node-api/backend/validator.go +++ b/node-api/backend/validator.go @@ -21,7 +21,6 @@ package backend import ( - "fmt" "github.com/berachain/beacon-kit/node-api/backend/utils" beacontypes "github.com/berachain/beacon-kit/node-api/handlers/beacon/types" "github.com/berachain/beacon-kit/primitives/math" @@ -69,8 +68,6 @@ func (b Backend) ValidatorsByIDs( // query and then filtering but blocked by the fact that IDs // can be indices and the hard type only holds its own pubkey. validatorData, err := b.ValidatorByID(slot, id) - fmt.Println("DEBUG: Grabbing validator for id", id, validatorData) - fmt.Println("DEBUG: validator:", validatorData.Validator) if err != nil { return nil, err } diff --git a/state-transition/core/state/statedb.go b/state-transition/core/state/statedb.go index 268ce696d1..695a5cc426 100644 --- a/state-transition/core/state/statedb.go +++ b/state-transition/core/state/statedb.go @@ -140,6 +140,7 @@ func (s *StateDB) ExpectedWithdrawals() (engineprimitives.Withdrawals, error) { // Iterate through indices to find the next validators to withdraw. for range bound { validator, err = s.ValidatorByIndex(validatorIndex) + fmt.Println("withdrawal check:", validatorIndex) if err != nil { return nil, err } @@ -167,7 +168,6 @@ func (s *StateDB) ExpectedWithdrawals() (engineprimitives.Withdrawals, error) { } else if validator.IsPartiallyWithdrawable( balance, math.Gwei(s.cs.MaxEffectiveBalance()), ) { - fmt.Println("DEBUG: validator is withdrawable!", validator.WithdrawalCredentials, balance) withdrawalAddress, err = validator.GetWithdrawalCredentials().ToExecutionAddress() if err != nil { return nil, err diff --git a/state-transition/core/state_processor.go b/state-transition/core/state_processor.go index 9db9b8afd5..a0cf092a4f 100644 --- a/state-transition/core/state_processor.go +++ b/state-transition/core/state_processor.go @@ -390,7 +390,6 @@ func (sp *StateProcessor[_]) processEffectiveBalanceUpdates(st *state.StateDB) e math.U64(sp.cs.EffectiveBalanceIncrement()), math.U64(sp.cs.MaxEffectiveBalance()), ) - sp.logger.Info("DEBUG: setting effective balance", "idx", idx, "beforeBalance", val.GetEffectiveBalance(), "afterBalance", updatedBalance) val.SetEffectiveBalance(updatedBalance) if err = st.UpdateValidatorAtIndex(idx, val); err != nil { return err diff --git a/state-transition/core/state_processor_staking.go b/state-transition/core/state_processor_staking.go index 700a278802..349fd94274 100644 --- a/state-transition/core/state_processor_staking.go +++ b/state-transition/core/state_processor_staking.go @@ -99,27 +99,16 @@ func (sp *StateProcessor[_]) applyDeposit(st *state.StateDB, dep *ctypes.Deposit // ErrNotFound from other kind of errors return sp.createValidator(st, dep) } - preBalance, err := st.GetBalance(idx) - if err != nil { - fmt.Println("DEBUG: FAILED TO GET PRE BALANCE") - } // if validator exist, just update its balance if err = st.IncreaseBalance(idx, dep.GetAmount()); err != nil { return err } - newBalance, err := st.GetBalance(idx) - if err != nil { - fmt.Println("DEBUG: FAILED TO GET BALANCE") - } - sp.logger.Info( "Processed deposit to increase balance", "deposit_amount", dep.GetAmount().Unwrap(), "validator_index", idx, - "pre_balance", preBalance.Base10(), - "new_balance", newBalance.Base10(), ) return nil } diff --git a/testing/e2e/e2e_staking_test.go b/testing/e2e/e2e_staking_test.go index e88abba462..43579f8855 100644 --- a/testing/e2e/e2e_staking_test.go +++ b/testing/e2e/e2e_staking_test.go @@ -21,7 +21,6 @@ package e2e_test import ( - "fmt" "github.com/attestantio/go-eth2-client/api" "github.com/attestantio/go-eth2-client/spec/phase0" "github.com/berachain/beacon-kit/testing/e2e/suite/types" @@ -38,10 +37,7 @@ import ( const ( // NumDepositsLoad is the number of deposits to load in the Deposit Robustness e2e test. - NumDepositsLoad uint64 = 20 - - // BlocksToWait is the number of blocks to wait for the nodes to catch up. - BlocksToWait = 10 + NumDepositsLoad uint64 = 500 ) // Contains pre-test state for validator info to facilitate validation of the post-state. @@ -69,9 +65,8 @@ func (s *BeaconKitE2ESuite) TestDepositRobustness() { // TODO Figure out how to change this value to the expected MAINNET chainspec value during testing. // This value is determined by the MIN_DEPOSIT_AMOUNT_IN_GWEI variable from the deposit contract. ContractMinDepositAmountWei := big.NewInt(1e9 * 1e9) - DepositAmountWei := new(big.Int).Mul(ContractMinDepositAmountWei, big.NewInt(2)) + DepositAmountWei := new(big.Int).Mul(ContractMinDepositAmountWei, big.NewInt(10)) DepositAmountGwei := new(big.Int).Div(DepositAmountWei, WeiPerGwei) - MaxEffectiveBalanceGwei := new(big.Int).SetUint64(chainspec.MaxEffectiveBalance()) // Our deposits should be greater than the min deposit amount. s.Require().Equal(1, DepositAmountWei.Cmp(ContractMinDepositAmountWei)) @@ -133,7 +128,6 @@ func (s *BeaconKitE2ESuite) TestDepositRobustness() { withdrawalAddress := gethcommon.Address(creds[12:]) withdrawalBalance, err := s.JSONRPCBalancer().BalanceAt(s.Ctx(), withdrawalAddress, nil) s.Require().NoError(err) - fmt.Println(withdrawalBalance) // Populate the validators testing struct so we can keep track of the pre-state. validators[idx] = &ValidatorTestStruct{ @@ -213,7 +207,7 @@ func (s *BeaconKitE2ESuite) TestDepositRobustness() { s.Logger().Info("Final deposit tx mined successfully", "hash", receipt.TxHash.Hex()) // Give time for the nodes to catch up. - err = s.WaitForNBlockNumbers(BlocksToWait) + err = s.WaitForNBlockNumbers(NumDepositsLoad / chainspec.MaxDepositsPerBlock()) s.Require().NoError(err) // Compare height of nodes 0 and 1 @@ -236,20 +230,17 @@ func (s *BeaconKitE2ESuite) TestDepositRobustness() { s.Require().Equal(1, amtSpent.Cmp(lowerBound), "amount spent is less than lower bound") s.Require().Equal(-1, amtSpent.Cmp(upperBound), "amount spent is greater than upper bound") - // TODO: determine why voting power is not increasing above 32e9. // Check that all validators' voting power have increased by // (NumDepositsLoad / NumValidators) * DepositAmountWei - // after the end of the epoch (next multiple of 32 after receipt.BlockNumber). - nextEpochBlockNum := (receipt.BlockNumber.Uint64()/32 + 1) * 32 + // after the end of the epoch (next multiple of SlotsPerEpoch after receipt.BlockNumber). + blkNum, err = s.JSONRPCBalancer().BlockNumber(s.Ctx()) + s.Require().NoError(err) + nextEpochBlockNum := (blkNum/chainspec.SlotsPerEpoch() + 1) * chainspec.SlotsPerEpoch() err = s.WaitForFinalizedBlockNumber(nextEpochBlockNum + 1) s.Require().NoError(err) - // TODO: Substracting the first NumValidators deposits because those are getting - // overwritten due to deposit contract not being initialized during genesis. - depositsPerValidator := (NumDepositsLoad - config.NumValidators) / config.NumValidators - increaseAmt := new(big.Int).Mul(DepositAmountGwei, big.NewInt(int64(depositsPerValidator))) + increaseAmt := new(big.Int).Mul(DepositAmountGwei, big.NewInt(int64(NumDepositsLoad/config.NumValidators))) - fmt.Println("Max:", MaxEffectiveBalanceGwei.String()) for _, val := range validators { // TODO: Make this go over the MaxEffectiveBalance // Get the validator powers for each validator and check that they increased by the expected amount. @@ -257,15 +248,24 @@ func (s *BeaconKitE2ESuite) TestDepositRobustness() { powerAfterRaw, err := val.Client.GetConsensusPower(s.Ctx()) s.Require().NoError(err) powerAfter := new(big.Int).SetUint64(powerAfterRaw) - fmt.Println("PowAft:", powerAfter.String()) - fmt.Println("PowBef:", val.Power.String()) powerDiff := new(big.Int).Sub(powerAfter, val.Power) - s.Require().Equal(0, powerDiff.Cmp(increaseAmt)) // Grab the validator withdrawal balances and check that they increased by the expected amount. + // withdrawal balance is in Wei, so we'll convert it to Gwei. withdrawalAddress := gethcommon.Address(val.WithdrawalCredentials[12:]) + + // Make sure the total withdrawal and power adds up to the amount deposited. withdrawalBalanceAfter, err := s.JSONRPCBalancer().BalanceAt(s.Ctx(), withdrawalAddress, nil) s.Require().NoError(err) - fmt.Println(withdrawalBalanceAfter) + + withdrawalDiff := new(big.Int).Sub(withdrawalBalanceAfter, val.WithdrawalBalance) + withdrawalDiff.Div(withdrawalDiff, WeiPerGwei) + + // TODO: currently the kurtosis devnet sets the withdrawal address the same for all NumValidators validators. + // For the validator that contains this address, we validate that the balance is NumValidators times larger than + // we expect it to be. For all other validators, they should simply be capped at the max effective balance. + withdrawalDiff.Div(withdrawalDiff, new(big.Int).SetUint64(config.NumValidators)) + + s.Require().Equal(increaseAmt, new(big.Int).Add(powerDiff, withdrawalDiff)) } } From 824b6ac61663610395680f5c9f740c193f26c823 Mon Sep 17 00:00:00 2001 From: shotes Date: Thu, 23 Jan 2025 00:32:38 +0900 Subject: [PATCH 09/12] Cleanup --- contracts/src/staking/DepositContract.sol | 4 +- state-transition/core/state/statedb.go | 3 +- .../core/state_processor_staking.go | 2 - .../core/state_processor_withdrawals.go | 4 -- testing/e2e/e2e_staking_test.go | 51 +++++++++---------- testing/e2e/suite/setup.go | 2 +- 6 files changed, 29 insertions(+), 37 deletions(-) diff --git a/contracts/src/staking/DepositContract.sol b/contracts/src/staking/DepositContract.sol index e4ffdcf9a7..2673f6a0f7 100644 --- a/contracts/src/staking/DepositContract.sol +++ b/contracts/src/staking/DepositContract.sol @@ -17,8 +17,8 @@ contract DepositContract is IDepositContract, ERC165 { /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev The minimum amount of `BERA` to deposit. - /// @dev This is 10000 Gwei since our deposit contract denominates in Gwei. 10000 * 1e9 = 1e13. - uint64 internal constant MIN_DEPOSIT_AMOUNT_IN_GWEI = 10000; + /// @dev This is 1 ether in Gwei since our deposit contract denominates in Gwei. 1e9 * 1e9 = 1e18. + uint64 internal constant MIN_DEPOSIT_AMOUNT_IN_GWEI = 1e9; /// @dev The length of the public key, PUBLIC_KEY_LENGTH bytes. uint8 internal constant PUBLIC_KEY_LENGTH = 48; diff --git a/state-transition/core/state/statedb.go b/state-transition/core/state/statedb.go index 695a5cc426..10745a2c7e 100644 --- a/state-transition/core/state/statedb.go +++ b/state-transition/core/state/statedb.go @@ -22,7 +22,7 @@ package state import ( "context" - "fmt" + "github.com/berachain/beacon-kit/chain" ctypes "github.com/berachain/beacon-kit/consensus-types/types" engineprimitives "github.com/berachain/beacon-kit/engine-primitives/engine-primitives" @@ -140,7 +140,6 @@ func (s *StateDB) ExpectedWithdrawals() (engineprimitives.Withdrawals, error) { // Iterate through indices to find the next validators to withdraw. for range bound { validator, err = s.ValidatorByIndex(validatorIndex) - fmt.Println("withdrawal check:", validatorIndex) if err != nil { return nil, err } diff --git a/state-transition/core/state_processor_staking.go b/state-transition/core/state_processor_staking.go index 349fd94274..fc92b29370 100644 --- a/state-transition/core/state_processor_staking.go +++ b/state-transition/core/state_processor_staking.go @@ -80,7 +80,6 @@ func (sp *StateProcessor[_]) processDeposit(st *state.StateDB, dep *ctypes.Depos "Processed deposit to set Eth 1 deposit index", "previous", eth1DepositIndex, "new", eth1DepositIndex+1, ) - sp.logger.Info("Processed deposit with creds", "creds", dep.Credentials) if err = sp.applyDeposit(st, dep); err != nil { return fmt.Errorf("failed to apply deposit: %w", err) } @@ -90,7 +89,6 @@ func (sp *StateProcessor[_]) processDeposit(st *state.StateDB, dep *ctypes.Depos // applyDeposit processes the deposit and ensures it matches the local state. func (sp *StateProcessor[_]) applyDeposit(st *state.StateDB, dep *ctypes.Deposit) error { idx, err := st.ValidatorIndexByPubkey(dep.GetPubkey()) - sp.logger.Info("Processing deposit", "pubkey", dep.GetPubkey(), "index", idx, "depIdx", dep.GetIndex()) if err != nil { sp.logger.Info("Validator does not exist so creating", "pubkey", dep.GetPubkey(), "index", dep.GetIndex(), "deposit_amount", dep.GetAmount()) diff --git a/state-transition/core/state_processor_withdrawals.go b/state-transition/core/state_processor_withdrawals.go index 242bfc775e..1579e69852 100644 --- a/state-transition/core/state_processor_withdrawals.go +++ b/state-transition/core/state_processor_withdrawals.go @@ -83,10 +83,6 @@ func (sp *StateProcessor[_]) processWithdrawals( spew.Sdump(payloadWithdrawals[i]), ) } - sp.logger.Info("Processing withdrawal", - "address", expectedWithdrawals[i].Address, - "amount", expectedWithdrawals[i].Amount, - ) if err = st.DecreaseBalance( expectedWithdrawals[i].GetValidatorIndex(), expectedWithdrawals[i].GetAmount(), diff --git a/testing/e2e/e2e_staking_test.go b/testing/e2e/e2e_staking_test.go index 43579f8855..1300003b69 100644 --- a/testing/e2e/e2e_staking_test.go +++ b/testing/e2e/e2e_staking_test.go @@ -21,14 +21,14 @@ package e2e_test import ( - "github.com/attestantio/go-eth2-client/api" - "github.com/attestantio/go-eth2-client/spec/phase0" - "github.com/berachain/beacon-kit/testing/e2e/suite/types" "math/big" + "github.com/attestantio/go-eth2-client/api" + "github.com/attestantio/go-eth2-client/spec/phase0" "github.com/berachain/beacon-kit/config/spec" "github.com/berachain/beacon-kit/geth-primitives/deposit" "github.com/berachain/beacon-kit/testing/e2e/config" + "github.com/berachain/beacon-kit/testing/e2e/suite/types" "github.com/cometbft/cometbft/crypto/bls12381" "github.com/ethereum/go-ethereum/accounts/abi/bind" gethcommon "github.com/ethereum/go-ethereum/common" @@ -54,22 +54,21 @@ type ValidatorTestStruct struct { // Then it checks whether all the validators' voting power have increased by the correct amount. // // TODO: -// 1) Add staking tests for exceeding the max stake. -// 2) Add staking tests for adding a new validator to the network. -// 3) Add staking tests for hitting the validator set cap and eviction. +// 1) Add staking tests for adding a new validator to the network. +// 2) Add staking tests for hitting the validator set cap and eviction. func (s *BeaconKitE2ESuite) TestDepositRobustness() { chainspec, err := spec.DevnetChainSpec() s.Require().NoError(err) - WeiPerGwei := big.NewInt(1e9) - // TODO Figure out how to change this value to the expected MAINNET chainspec value during testing. + weiPerGwei := big.NewInt(1e9) + // This value is determined by the MIN_DEPOSIT_AMOUNT_IN_GWEI variable from the deposit contract. - ContractMinDepositAmountWei := big.NewInt(1e9 * 1e9) - DepositAmountWei := new(big.Int).Mul(ContractMinDepositAmountWei, big.NewInt(10)) - DepositAmountGwei := new(big.Int).Div(DepositAmountWei, WeiPerGwei) + contractMinDepositAmountWei := big.NewInt(1e9 * 1e9) + depositAmountWei := new(big.Int).Mul(contractMinDepositAmountWei, big.NewInt(10)) + depositAmountGwei := new(big.Int).Div(depositAmountWei, weiPerGwei) // Our deposits should be greater than the min deposit amount. - s.Require().Equal(1, DepositAmountWei.Cmp(ContractMinDepositAmountWei)) + s.Require().Equal(1, depositAmountWei.Cmp(contractMinDepositAmountWei)) s.Require().Equal( 0, int(NumDepositsLoad%config.NumValidators), @@ -119,15 +118,15 @@ func (s *BeaconKitE2ESuite) TestDepositRobustness() { // Grab pre-state data for each validator. validators := make([]*ValidatorTestStruct, config.NumValidators) - var idx uint64 = 0 + var idx uint64 for name, client := range s.ConsensusClients() { - power, err := client.GetConsensusPower(s.Ctx()) - s.Require().NoError(err) + power, cErr := client.GetConsensusPower(s.Ctx()) + s.Require().NoError(cErr) creds := [32]byte(vals[phase0.ValidatorIndex(idx)].Validator.WithdrawalCredentials) withdrawalAddress := gethcommon.Address(creds[12:]) - withdrawalBalance, err := s.JSONRPCBalancer().BalanceAt(s.Ctx(), withdrawalAddress, nil) - s.Require().NoError(err) + withdrawalBalance, jErr := s.JSONRPCBalancer().BalanceAt(s.Ctx(), withdrawalAddress, nil) + s.Require().NoError(jErr) // Populate the validators testing struct so we can keep track of the pre-state. validators[idx] = &ValidatorTestStruct{ @@ -165,7 +164,7 @@ func (s *BeaconKitE2ESuite) TestDepositRobustness() { clientPubkey []byte pk *bls12381.PubKey signature [96]byte - value = DepositAmountWei + value = depositAmountWei signer = sender.SignerFunc(chainID) from = sender.Address() ) @@ -222,7 +221,7 @@ func (s *BeaconKitE2ESuite) TestDepositRobustness() { s.Require().NoError(err) // Check that the eth spent is somewhere~ (gas) between - // (DepositAmountWei * NumDepositsLoad, DepositAmountWei * NumDepositsLoad + 2ether) + // (depositAmountWei * NumDepositsLoad, depositAmountWei * NumDepositsLoad + 2ether) lowerBound := new(big.Int).Mul(value, new(big.Int).SetUint64(NumDepositsLoad)) upperBound := new(big.Int).Add(lowerBound, big.NewInt(2e18)) amtSpent := new(big.Int).Sub(balance, postDepositBalance) @@ -231,7 +230,7 @@ func (s *BeaconKitE2ESuite) TestDepositRobustness() { s.Require().Equal(-1, amtSpent.Cmp(upperBound), "amount spent is greater than upper bound") // Check that all validators' voting power have increased by - // (NumDepositsLoad / NumValidators) * DepositAmountWei + // (NumDepositsLoad / NumValidators) * depositAmountWei // after the end of the epoch (next multiple of SlotsPerEpoch after receipt.BlockNumber). blkNum, err = s.JSONRPCBalancer().BlockNumber(s.Ctx()) s.Require().NoError(err) @@ -239,14 +238,14 @@ func (s *BeaconKitE2ESuite) TestDepositRobustness() { err = s.WaitForFinalizedBlockNumber(nextEpochBlockNum + 1) s.Require().NoError(err) - increaseAmt := new(big.Int).Mul(DepositAmountGwei, big.NewInt(int64(NumDepositsLoad/config.NumValidators))) + increaseAmt := new(big.Int).Mul(depositAmountGwei, big.NewInt(int64(NumDepositsLoad/config.NumValidators))) for _, val := range validators { // TODO: Make this go over the MaxEffectiveBalance // Get the validator powers for each validator and check that they increased by the expected amount. // Consensus Power is in Gwei. - powerAfterRaw, err := val.Client.GetConsensusPower(s.Ctx()) - s.Require().NoError(err) + powerAfterRaw, cErr := val.Client.GetConsensusPower(s.Ctx()) + s.Require().NoError(cErr) powerAfter := new(big.Int).SetUint64(powerAfterRaw) powerDiff := new(big.Int).Sub(powerAfter, val.Power) @@ -255,11 +254,11 @@ func (s *BeaconKitE2ESuite) TestDepositRobustness() { withdrawalAddress := gethcommon.Address(val.WithdrawalCredentials[12:]) // Make sure the total withdrawal and power adds up to the amount deposited. - withdrawalBalanceAfter, err := s.JSONRPCBalancer().BalanceAt(s.Ctx(), withdrawalAddress, nil) - s.Require().NoError(err) + withdrawalBalanceAfter, jErr := s.JSONRPCBalancer().BalanceAt(s.Ctx(), withdrawalAddress, nil) + s.Require().NoError(jErr) withdrawalDiff := new(big.Int).Sub(withdrawalBalanceAfter, val.WithdrawalBalance) - withdrawalDiff.Div(withdrawalDiff, WeiPerGwei) + withdrawalDiff.Div(withdrawalDiff, weiPerGwei) // TODO: currently the kurtosis devnet sets the withdrawal address the same for all NumValidators validators. // For the validator that contains this address, we validate that the balance is NumValidators times larger than diff --git a/testing/e2e/suite/setup.go b/testing/e2e/suite/setup.go index 782d1241ca..4d672a17b5 100644 --- a/testing/e2e/suite/setup.go +++ b/testing/e2e/suite/setup.go @@ -389,7 +389,7 @@ func (s *KurtosisE2ESuite) TearDownSuite() { s.Require().Nil(res.ExecutionError, "Error stopping consensus client") s.Require().Empty(res.ValidationErrors, "Error stopping consensus client") } - //s.Require().NoError(s.kCtx.DestroyEnclave(s.ctx, "e2e-test-enclave")) + s.Require().NoError(s.kCtx.DestroyEnclave(s.ctx, "e2e-test-enclave")) } // CheckForSuccessfulTx returns true if the transaction was successful. From e5083021e387f8be6188b5ca8947ae8fddc12ad6 Mon Sep 17 00:00:00 2001 From: shotes Date: Thu, 23 Jan 2025 00:36:12 +0900 Subject: [PATCH 10/12] fix comment --- testing/e2e/e2e_staking_test.go | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/testing/e2e/e2e_staking_test.go b/testing/e2e/e2e_staking_test.go index 1300003b69..8653576d2d 100644 --- a/testing/e2e/e2e_staking_test.go +++ b/testing/e2e/e2e_staking_test.go @@ -241,7 +241,6 @@ func (s *BeaconKitE2ESuite) TestDepositRobustness() { increaseAmt := new(big.Int).Mul(depositAmountGwei, big.NewInt(int64(NumDepositsLoad/config.NumValidators))) for _, val := range validators { - // TODO: Make this go over the MaxEffectiveBalance // Get the validator powers for each validator and check that they increased by the expected amount. // Consensus Power is in Gwei. powerAfterRaw, cErr := val.Client.GetConsensusPower(s.Ctx()) @@ -260,9 +259,8 @@ func (s *BeaconKitE2ESuite) TestDepositRobustness() { withdrawalDiff := new(big.Int).Sub(withdrawalBalanceAfter, val.WithdrawalBalance) withdrawalDiff.Div(withdrawalDiff, weiPerGwei) - // TODO: currently the kurtosis devnet sets the withdrawal address the same for all NumValidators validators. - // For the validator that contains this address, we validate that the balance is NumValidators times larger than - // we expect it to be. For all other validators, they should simply be capped at the max effective balance. + // TODO: currently the kurtosis devnet sets the withdrawal address the same for all validators. + // We simply validate that the balance is NumValidators times larger than we expect it to be. withdrawalDiff.Div(withdrawalDiff, new(big.Int).SetUint64(config.NumValidators)) s.Require().Equal(increaseAmt, new(big.Int).Add(powerDiff, withdrawalDiff)) From d99ea2488c0e4fbf9c0ee60b1fe150e2a062c577 Mon Sep 17 00:00:00 2001 From: shotes Date: Thu, 23 Jan 2025 11:58:38 +0900 Subject: [PATCH 11/12] Fix spec and appease nilaway --- config/spec/devnet.go | 2 +- testing/e2e/e2e_staking_test.go | 11 +++++++++-- testing/e2e/suite/setup.go | 2 +- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/config/spec/devnet.go b/config/spec/devnet.go index 213b77e610..333acaff78 100644 --- a/config/spec/devnet.go +++ b/config/spec/devnet.go @@ -35,7 +35,7 @@ const ( // MaxStakeAmount is the maximum amount of native EVM balance (in units // of Gwei) that can be staked. - MaxStakeAmount = 400e9 + MaxStakeAmount = 4000e9 ) // DevnetChainSpec is the ChainSpec for the localnet. Also used for e2e tests diff --git a/testing/e2e/e2e_staking_test.go b/testing/e2e/e2e_staking_test.go index 8653576d2d..ac0ecbd28d 100644 --- a/testing/e2e/e2e_staking_test.go +++ b/testing/e2e/e2e_staking_test.go @@ -64,7 +64,7 @@ func (s *BeaconKitE2ESuite) TestDepositRobustness() { // This value is determined by the MIN_DEPOSIT_AMOUNT_IN_GWEI variable from the deposit contract. contractMinDepositAmountWei := big.NewInt(1e9 * 1e9) - depositAmountWei := new(big.Int).Mul(contractMinDepositAmountWei, big.NewInt(10)) + depositAmountWei := new(big.Int).Mul(contractMinDepositAmountWei, big.NewInt(100)) depositAmountGwei := new(big.Int).Div(depositAmountWei, weiPerGwei) // Our deposits should be greater than the min deposit amount. @@ -104,15 +104,18 @@ func (s *BeaconKitE2ESuite) TestDepositRobustness() { // TODO: Compare with HashTreeRoot of genesis deposits apiClient := s.ConsensusClients()[config.ClientValidator0] + s.Require().NotNil(apiClient) // Grab genesis validators to get withdrawal creds. s.Require().NoError(apiClient.Connect(s.Ctx())) + s.Require().NotNil(apiClient.BeaconKitNodeClient) response, err := apiClient.BeaconKitNodeClient.Validators(s.Ctx(), &api.ValidatorsOpts{ State: "genesis", Indices: []phase0.ValidatorIndex{0, 1, 2, 3, 4}, }) s.Require().NoError(err) vals := response.Data + s.Require().NotNil(vals) s.Require().Len(vals, config.NumValidators) s.Require().Len(s.ConsensusClients(), config.NumValidators) @@ -123,7 +126,11 @@ func (s *BeaconKitE2ESuite) TestDepositRobustness() { power, cErr := client.GetConsensusPower(s.Ctx()) s.Require().NoError(cErr) - creds := [32]byte(vals[phase0.ValidatorIndex(idx)].Validator.WithdrawalCredentials) + s.Require().Contains(vals, phase0.ValidatorIndex(idx)) + val := vals[phase0.ValidatorIndex(idx)] + s.Require().NotNil(val) + s.Require().NotNil(val.Validator) + creds := [32]byte(val.Validator.WithdrawalCredentials) withdrawalAddress := gethcommon.Address(creds[12:]) withdrawalBalance, jErr := s.JSONRPCBalancer().BalanceAt(s.Ctx(), withdrawalAddress, nil) s.Require().NoError(jErr) diff --git a/testing/e2e/suite/setup.go b/testing/e2e/suite/setup.go index 4d672a17b5..9d66965004 100644 --- a/testing/e2e/suite/setup.go +++ b/testing/e2e/suite/setup.go @@ -243,7 +243,7 @@ func (s *KurtosisE2ESuite) FundAccounts() { gasTipCap, big.NewInt(0).SetUint64(TenGwei)) nonceToSubmit := nonce.Add(1) - 1 //nolint:mnd // 20000 Ether - value := new(big.Int).Mul(big.NewInt(20000), big.NewInt(Ether)) + value := new(big.Int).Mul(big.NewInt(200000), big.NewInt(Ether)) dest := account.Address() var signedTx *ethtypes.Transaction if signedTx, err = s.genesisAccount.SignTx( From b1c31180a7e55d56c1e367ce13901e6207b5f769 Mon Sep 17 00:00:00 2001 From: shotes Date: Thu, 23 Jan 2025 12:15:46 +0900 Subject: [PATCH 12/12] nits --- state-transition/core/state/statedb.go | 1 + state-transition/core/state_processor_staking.go | 2 +- testing/e2e/e2e_staking_test.go | 11 ++--------- 3 files changed, 4 insertions(+), 10 deletions(-) diff --git a/state-transition/core/state/statedb.go b/state-transition/core/state/statedb.go index 10745a2c7e..caf04f28da 100644 --- a/state-transition/core/state/statedb.go +++ b/state-transition/core/state/statedb.go @@ -148,6 +148,7 @@ func (s *StateDB) ExpectedWithdrawals() (engineprimitives.Withdrawals, error) { if err != nil { return nil, err } + // Set the amount of the withdrawal depending on the balance of the validator. if validator.IsFullyWithdrawable(balance, epoch) { withdrawalAddress, err = validator.GetWithdrawalCredentials().ToExecutionAddress() diff --git a/state-transition/core/state_processor_staking.go b/state-transition/core/state_processor_staking.go index fc92b29370..ac0883ced3 100644 --- a/state-transition/core/state_processor_staking.go +++ b/state-transition/core/state_processor_staking.go @@ -105,7 +105,7 @@ func (sp *StateProcessor[_]) applyDeposit(st *state.StateDB, dep *ctypes.Deposit sp.logger.Info( "Processed deposit to increase balance", - "deposit_amount", dep.GetAmount().Unwrap(), + "deposit_amount", float64(dep.GetAmount().Unwrap())/math.GweiPerWei, "validator_index", idx, ) return nil diff --git a/testing/e2e/e2e_staking_test.go b/testing/e2e/e2e_staking_test.go index 28577077b6..b6eeb0dcd0 100644 --- a/testing/e2e/e2e_staking_test.go +++ b/testing/e2e/e2e_staking_test.go @@ -81,17 +81,14 @@ func (s *BeaconKitE2ESuite) TestDepositRobustness() { // Bind the deposit contract. depositContractAddress := gethcommon.HexToAddress(spec.DefaultDepositContractAddress) - dc, err := deposit.NewDepositContract(depositContractAddress, s.JSONRPCBalancer()) s.Require().NoError(err) - // Check deposit count at genesis + // Enforce the deposit count at genesis is equal to the number of validators. depositCount, err := dc.DepositCount(&bind.CallOpts{ BlockNumber: big.NewInt(0), }) s.Require().NoError(err) - - // Enforce the deposit count at genesis is equal to the number of validators. s.Require().Equal(uint64(config.NumValidators), depositCount, "initial deposit count should match number of validators") @@ -249,21 +246,16 @@ func (s *BeaconKitE2ESuite) TestDepositRobustness() { increaseAmt := new(big.Int).Mul(depositAmountGwei, big.NewInt(int64(NumDepositsLoad/config.NumValidators))) for _, val := range validators { - // Get the validator powers for each validator and check that they increased by the expected amount. // Consensus Power is in Gwei. powerAfterRaw, cErr := val.Client.GetConsensusPower(s.Ctx()) s.Require().NoError(cErr) powerAfter := new(big.Int).SetUint64(powerAfterRaw) powerDiff := new(big.Int).Sub(powerAfter, val.Power) - // Grab the validator withdrawal balances and check that they increased by the expected amount. // withdrawal balance is in Wei, so we'll convert it to Gwei. withdrawalAddress := gethcommon.Address(val.WithdrawalCredentials[12:]) - - // Make sure the total withdrawal and power adds up to the amount deposited. withdrawalBalanceAfter, jErr := s.JSONRPCBalancer().BalanceAt(s.Ctx(), withdrawalAddress, nil) s.Require().NoError(jErr) - withdrawalDiff := new(big.Int).Sub(withdrawalBalanceAfter, val.WithdrawalBalance) withdrawalDiff.Div(withdrawalDiff, weiPerGwei) @@ -271,6 +263,7 @@ func (s *BeaconKitE2ESuite) TestDepositRobustness() { // We simply validate that the balance is NumValidators times larger than we expect it to be. withdrawalDiff.Div(withdrawalDiff, new(big.Int).SetUint64(config.NumValidators)) + // Verify input balance is equal to the power + withdrawal balances. s.Require().Equal(increaseAmt, new(big.Int).Add(powerDiff, withdrawalDiff)) } }