-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
1,461 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
USER_PRIVATE_KEY=private_key | ||
ALCHEMY_API_KEY=api_key | ||
REDIS_HOST=localhost | ||
REDIS_PORT=6379 | ||
PROVER_SERVER_HOST=http://127.0.0.1 | ||
PROVER_SERVER_PORT=5000 | ||
INITIAL_SLOT=5860953 | ||
SLOTS_JUMP=32 | ||
PRATTER=TRUE | ||
MAINNET=FALSE | ||
LC_GOERLI=0xf65B59bc947865490eF92D8461e8B5D0eA87c343 | ||
LC_OPTIMISTIC_GOERLI= | ||
LC_BASE_GOERLI= | ||
LC_ARBITRUM_GOERLI= | ||
LC_SEPOLIA= | ||
LC_MUMBAI= | ||
LC_FUJI= | ||
LC_FANTOM= | ||
LC_ALFAJORES= | ||
LC_BSC= | ||
LC_AURORA= | ||
LC_GNOSIS= | ||
LC_CHIADO= | ||
LC_EVMOS= | ||
LC_MALAGA= | ||
GOERLI_HASHI=0x4169ea397fe83F55e732E11390807b3722374f78 | ||
OPTIMISTIC_HASHI='' | ||
BASE_HASHI='' | ||
ARBITRUM_HASHI='' | ||
SEPOLIA_HASHI='' | ||
MUMBAI_HASHI='' | ||
FANTOM_HASHI='' | ||
ALFAJORES_HASHI='' | ||
CHIADO_HASHI='' | ||
EVMOS_HASHI='' | ||
MALAGA_HASHI='' | ||
AURORA_HASHI='' | ||
GNOSIS_HASHI='' | ||
FUJI_HASHI='' | ||
BSC_HASHI='' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
138 changes: 138 additions & 0 deletions
138
...t-client/circom/scripts/validator_balances/validator_accumulator_description.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
`validatorsAccumulator` is a Merkle tree accumulator that contains the public keys of validators and their corresponding Eth1 deposit indexes. | ||
The purpose of storing the Eth1 deposit index is to ascertain whether a particular validator is already a participant in the beacon chain. | ||
|
||
A Merkle tree accumulator is a binary tree of hashes, which is used for efficiently proving membership of an element in a set. In this context, the set comprises of validators. | ||
|
||
This is a sample solidity implementation of the `validatorsAccumulator` | ||
|
||
``` | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity 0.8.18; | ||
// This interface is designed to be compatible with the Vyper version. | ||
/// @notice This is the Ethereum 2.0 deposit contract interface. | ||
/// For more information see the Phase 0 specification under https://github.com/ethereum/eth2.0-specs | ||
interface IDepositContract { | ||
/// @notice A processed deposit event. | ||
event DepositEvent( | ||
bytes pubkey, | ||
bytes withdrawal_credentials, | ||
bytes amount, | ||
bytes signature, | ||
bytes index | ||
); | ||
/// @notice Submit a Phase 0 DepositData object. | ||
/// @param pubkey A BLS12-381 public key. | ||
/// @param withdrawal_credentials Commitment to a public key for withdrawals. | ||
/// @param signature A BLS12-381 signature. | ||
/// @param deposit_data_root The SHA-256 hash of the SSZ-encoded DepositData object. | ||
/// Used as a protection against malformed input. | ||
function deposit( | ||
bytes calldata pubkey, | ||
bytes calldata withdrawal_credentials, | ||
bytes calldata signature, | ||
bytes32 deposit_data_root | ||
) external payable; | ||
/// @notice Query the current deposit root hash. | ||
/// @return The deposit root hash. | ||
function get_deposit_root() external view returns (bytes32); | ||
/// @notice Query the current deposit count. | ||
/// @return The deposit count encoded as a little endian 64-bit number. | ||
function get_deposit_count() external view returns (bytes memory); | ||
} | ||
contract ValidatorsAccumulator { | ||
address depositAddress; | ||
// The depth of the validator accumulator tree | ||
uint constant VALIDATOR_ACCUMULATOR_TREE_DEPTH = 32; | ||
// An array to hold the branch hashes for the Merkle tree | ||
bytes32[VALIDATOR_ACCUMULATOR_TREE_DEPTH] branch; | ||
bytes32[VALIDATOR_ACCUMULATOR_TREE_DEPTH] zero_hashes; | ||
// A counter for the total number of validators | ||
uint validators_count; | ||
constructor(address _depositAddress) { | ||
depositAddress = _depositAddress; | ||
// Compute hashes in empty Merkle tree | ||
for ( | ||
uint height = 0; | ||
height < VALIDATOR_ACCUMULATOR_TREE_DEPTH - 1; | ||
height++ | ||
) | ||
zero_hashes[height + 1] = sha256( | ||
abi.encodePacked(zero_hashes[height], zero_hashes[height]) | ||
); | ||
} | ||
// Function to calculate and return the Merkle accumulator root of the validators | ||
function get_validators_accumulator() external view returns (bytes32) { | ||
bytes32 node; | ||
uint size = validators_count; | ||
// Calculate the Merkle accumulator root | ||
for (uint height = 0; height < VALIDATOR_ACCUMULATOR_TREE_DEPTH; height++) { | ||
// This if-else structure supports tree balancing | ||
// If size is odd, the new node will be hashed with the previous node on this level | ||
// If size is even, the new node will be hashed with a predefined zero hash | ||
if ((size & 1) == 1) | ||
node = sha256(abi.encodePacked(branch[height], node)); | ||
else node = sha256(abi.encodePacked(node, zero_hashes[height])); | ||
size /= 2; | ||
} | ||
return node; | ||
} | ||
// Function to handle deposits from validators | ||
function deposit( | ||
bytes calldata pubkey, | ||
bytes calldata withdrawal_credentials, | ||
bytes calldata signature, | ||
bytes32 deposit_data_root | ||
) public payable { | ||
// Perform the deposit using the DepositContract | ||
IDepositContract(depositAddress).deposit{value: msg.value}( | ||
pubkey, | ||
withdrawal_credentials, | ||
signature, | ||
deposit_data_root | ||
); | ||
// Get the deposit count and increase the validator count | ||
bytes memory deposit_index = IDepositContract(depositAddress) | ||
.get_deposit_count(); | ||
validators_count += 1; | ||
// Create a node for the validator | ||
bytes32 node = sha256(abi.encodePacked(pubkey, deposit_index)); | ||
// Insert the node into the Merkle accumulator tree | ||
uint size = validators_count; | ||
for (uint height = 0; height < VALIDATOR_ACCUMULATOR_TREE_DEPTH; height++) { | ||
if ((size & 1) == 1) { | ||
branch[height] = node; | ||
return; | ||
} | ||
node = sha256(abi.encodePacked(branch[height], node)); | ||
size /= 2; | ||
} | ||
} | ||
} | ||
``` | ||
|
||
In the deposit function, each validator's public key and their Eth1 deposit index are packed together and hashed to form a node. This node represents the validator in the Merkle tree. | ||
|
||
The node is then inserted into the Merkle tree at the appropriate level, based on the current number of validators. The path to insert the node is determined using the binary representation of the total validator count. The leftmost branch is taken for every 0, and the rightmost branch for every 1. | ||
|
||
The get_validators_accumulator function calculates and returns the Merkle root of the validatorsAccumulator. This root is a single hash that effectively represents all the validators in the accumulator. |
Oops, something went wrong.