Skip to content

Commit ab1fe9a

Browse files
naddison36clement-uxsparrowDom
authored
New Compounding Staking Strategy post Pectra upgrade (#2559)
* add proof for validator * add deposit proofs * add balance proof for all validators * Mock Beacon Roots (#2596) * add MockBeaconRoots on hoodi to reflect the state on meinnet * add support to verify Slot on hoodi * Added requestValidatorWithdraw Hardhat task * Updated validator proofs * add more validators data * add a last validator * Add balance proof for 20 validators * add a new validators * add nex balance proof for 21 validators * add support for hoodie when calling registerValidator * add check that validator ids are in ascending order * add a task for the initial 1 ETH deposit * Fix bug in verifyBalances when an active validator is exited * Prettier * sort the operator ids instead of throwing an error * prettier * Changed requestConsolidation on the old staking strategy to only be called by governor * Added getValidator Hardhat task * Remove log output * snapBalances changed to be external from public * Added onlyRegistrator to snapBalances to prevent denial of calling verifyBalances * Removed onlyRegistrator from verifyBalances as its on snapBalances * Added extra checks on the number of balance leaves and proofs in verifyBalances * Made Endian library MIT as its used by BeaconOracle which is also MIT * Changed the initial validator deposit to be 32 ETH * Formatted the output of getValidator Hardhat task * Added more data to getValidator hardhat task * Updated validatorWithdrawal Natspec with new understanding of how full withdrawals work * Added Hoodi upgrade script for the staking strategy * Removed reverts from BeaconRoots contract as the underlying beacon roots contract will revert Removed the old deploy of MockBeaconRoots to mainnet * Deployed new MockBeaconRoots * Upgraded the CompoundingStakingSSVStrategyProxy on Hoodi * Fixes to Hardhat tasks * add deployment files * Changed the WETH contract for Hoodi * Changed the Hoodi strategist and governor to be the Relayer * Governor spelling * Upgraded the OETH Vault on Hoodi * Upgrade the compounding staking strategy to use new WETH token * Added tenderlyUpload to verify a single contract * beacon proof generators to handle Hoodi * Deployed new BeaconProofs and CompoundingStakingSSVStrategy * Add 1 wei of value to validatorWithdrawal call * verifySlot can now be done from a block Added snapStakingStrat HH task * Renamed validatorContainerProof to balancesContainerProof * Upgraded the native staking contract on Hoodi * Renamed the ETH/WETH conversion functions * P2P API support for Hoodi Iterate over validator balances in snapStakingStrat * Updated verifySlot options * Prettier * Fix storage checker * Fix old Native Staking fork tests * bulk exit and remove validator (#2185) * Added setFeeRecipient to the Native Staking Strategy Added SSV approve and setFeeRecipientAddress to the Native Staking Strategy's initialize function Correct the Natspec on how tx fees are handled. * Updated OETH process diagrams * Added deploy script to upgrade Native Staking Strategies Added fork tests to set MEV fee recipient Removed old native staking fork test file that is no longer being used * Deployed new Native Staking Strategy to Holesky * Updated value flows * Generated new NativeStakingStrategy diagram * Changed exit and remove validators to be bulk functions * Prettier * Fix storage checker * Prettier * Changed verifyBalances so a slot before the first pending deposit can be mapped in BeaconOracle Deployed new staking contracts to Hoodi * Fixed check in verifyBalances * Preparing HH tasks to be run as Actions * Defender Action to verify slots * Deployed latest compounding staking strategy * Added getPendingDeposits view function Added pending deposits to snapStakingStrategy * Updated snapStakingStrat HH task * Improved error message when generating verifyBalances proof * Remove BeaconOracle from new staking strategy (#2608) * Improved error message when generating verifyBalances proof * WIP remove BeaconOracle * Prettier * Fixed unit tests * Updated the process diagrams * Updated verifyBalancesContainer param names * add comment * Nicka/pectra remove consolidation (#2609) * Improved error message when generating verifyBalances proof * Removed the consolidation logic * Removed TargetStrategyAdded * Simplified verifyValidatorBalance * Cleaned up defender actions * Deployed to Hoodi * Add setRegistrator HH task * add an in depth explanation of the accounting behaviour (#2610) * Updates to Hardhat tasks * Natspec cleanup * Prettier * Changed validatorWithdrawal to be payable so the 1 wei fee can be paid * Added deposit root to the getPendingDeposits output Deployed new version to Hoodi Improve snapStakingStrategy HH task * Fix verifyDeposit when the deposit queue is empty * Updated OETH contracts diagram and staking transitions diagram * improved getValidator * Added more logging * Validator task upgrades (#2614) * add the ability to register a validator using UUID * add the ability to stake to the validator using uuid * add support for getting validator info by validator public key * Changed verifyFirstPendingDepositSlot to return of the deposit queue is empty or not Updated Natspec * Prettier js * Check if slot of the pending deposit is zero * Deployed new contracts to Hoodi * Added off-chain checks for zero value slots * Added more logging to HH tasks Fixed full exit logic in validatorWithdrawal * Fix linter * Fix full exit logic in HH task * Fixed partial withdrawal in HH task * Improved snapStakingStrat HH task * Added more checks to proof verifications * DEployed the latest contracts to Hoodi * Make sure the beacon chain data matches the block used in snapStakingStrat * adjust comment * Add pending beacon chain deposits info to snapStakingStrat * added more validator info to snapStakingStrat * Updated Natspec * Call safeApproveAllTokens from initialize function * Added comment on use of min in _transferWeth * Added check of validator public key length to registerSsvValidator * Fixed Natspec on validatorWithdrawal * Fixed removeSsvValidator Natspec * Read depositsRoots.length into memory in getPendingDeposits * Fixed Slither * Upgraded the contracts on Hoodi * Minor changes to request validator HH tasks * Add test coverage of getPendingDeposits * Add test that collectRewardTokens is unsupported * Fix off-chain verifyBalances when deposit queue is empty * Moved check of public key length into `_hashPubKey` * Update HOODI API key * Removed beaconOracle ABI as its no longer used * Removed .out file * No longer need the optional provider in getSigner factory * Prettier * Removed _asset from internal _withdraw function * Simplified setting of the lastVerifiedEthBalance in _convertEthToWeth Also updated the comments when lastSnapTimestamp is reset to zero in _convertEthToWeth and _convertWethToEth * Override setPTokenAddress and removePToken so they revert with "Unsupported function" * add comment * OZ C-01 - Postponed Pending Deposit Breaks verifyDeposit and verifyBalances (#2622) * Changed verifyBalances so it reverts if pending deposits Added verifyBalancesWithDeposits that can only be called by the staking monitor * Renamed verifyValidatorPubkey to verifyValidator * Renamed verifyFirstPendingDepositSlot to verifyFirstPendingDeposit * Added verifyValidatorWithdrawableEpoch and verifyValidatorPubKeySubTree proofs verifyDeposit now checks the first pending deposit is not to an exiting validator * Added verification of deposits back to the verifyBalances Updated Natspec with maths on calculating the gen indexes Removed the staking monitor * Linter * More Natspec updates * More Natspec changes * Remove deposit after validator has exited * Tidy up the removal of a deposit * Added DepositValidatorExited event Added amountWei to the DepositValidatorExiting event * Changed DepositValidatorExiting to DepositToValidatorExiting * Fixed stack too deep * Refactor names in verifyDeposit and verifyBalances * Renamed param structs in verifyDeposit and verifyBalances * Updated comment on why a validator with a pending deposit can be exiting * Fixed logic in verifyBalances checking is an exiting validator is not withdrawable * verifyValidator can now handle front-run deposits * Renamed params in verifyDeposit * Refactored validator storage data * Removed wethBalance from BalancesVerified event * Fix verification of slot in verifyFirstPendingDeposit Added more beacon proof unit tests * Changed some of the storage variables so they are public * Fix and improved the beacon proofs fork tests * WIP fixing strategy unit tests * More fixing the unit tests * Renamed block root in verifyBalances to make it clear its for the snapBalances root * Generated new unit test data * Fixed verifyBalance Hardhat task * Add more unit testing data * Got unit tests working again * Updated comment on exiting validator * Added nextDepositID to be a unique identifier of a deposit to a validator (#2624) * Break from iterating over the deposits once the deposit has been found in verifyValidator for an invalid validator * Added Compounding Validator State Diagram * Improved Beacon Proof constants for readability (#2625) * Removed the unused SourceStrategyAdded event (#2626) * Added EXITING validator state to help prevent deposits to exiting validators (#2627) * set validator status to exiting if such transition detected (#2629) * M-02 registrator protections (#2630) * Split out the view functions from CompoundingValidatorManager Added MAX_DEPOSITS and MAX_VALIDATORS * Limit to only one deposit to an unverified validator at a time * Removed onlyRegistrator from snapBalances and used a 2 epoch time delay instead to prevent DoS of verifying balances * Moved MAX_VERIFIED_VALIDATORS check into stakeEth * Moved MAX_VERIFIED_VALIDATORS check into when REGISTERED block Renamed setFirstDeposit to resetFirstDeposit * Updated Natspec * Fixed unit tests * Updated validator state diagram after merge * Fixed check of deposit being processed in verifyBalances * N-07 Code Simplifications (#2631) * move index division outside of if/else * Refactor _snapBalances function to optimize timestamp handling * Simplify totalValidatorBalance calculation by removing redundant type conversion * Rename VALIDATOR_STATE enum to ValidatorState for consistency and clarity * Refactor import statements and update VALIDATOR_STATE to ValidatorState for consistency * Prettier * Moved div 2 out of assembly block in Merkle contract * Removed timestamp from BalancesSnapped event * Removed timestamp from snapBalances log --------- Co-authored-by: Nicholas Addison <nick@addisonbrown.com.au> * N-08 Missing, Incorrect, or Misleading Documentation (#2632) * Fix parameter description in withdrawSSV function to clarify SSV token withdrawal * Add description * Enhance documentation for request and fee functions in PartialWithdrawal library * Changed SNAP_BALANCES_DELAY to 1 epoch * Set zero governor on implementation contract * Deployed latest contracts on Hoodi * Moved new deposit storage variables for backward compatibility with Hoodi * Redeployed CompoundingStakingSSVStrategy to Hoodi * Moved new deposit storage variables back up as now deploying a new staking contract * Deployed a new compounding staking contract to Hoodi * Fixed snapStakingStrat * Fixed verifyBalances when a deposit is done to an exiting validator * Skip failing unit test for now * Deployed latest staking contract to Hoodi * FIxed verifyBalances when there are no pending deposits * Updated OETH contracts diagram * Updated verifyDeposit process flow * simplify snapping balances (#2633) * simplify snapping balances * type simplification * OZ N-03 Checks Effects Interactions (CEI) Pattern (#2634) * Updated Natspec of verifyDeposit * Moved 3rd party contract interactions to after storage variables are updated * various minor changes to SSV staking (#2635) * improve comments * add CEI pattern * add comment * 70b contract size optimisation * add comment * prettier * Redeployed latest staking contract to Hoodi * Fixed snapStakingStrat Hardhat task * Removed root from VerifyBalances Hardhat task * Added removeValidator Hardhat task * Fixed registration of new compounding validator * Fixed verifyBalances Hardhat task * verifyBalance to default validator slot for verification to the same as the first pending deposit if the deposit queue is empty * Fixed verifyDeposit Hardhat task * Improve verifyBalances hardhat task when the deposit queue is empty * Fixed validator status in snapStakingStrat HH task * change snap balances delay to 35 slots (#2637) * add comment (#2638) * Added dryrun to stakeValidator HH task * Fixed logging of the deposit ID from stakeValidator HH task * add the support to verify BLS signature before depositing to validator (#2639) * add the support to verify BLS signature before depositing to validator * prettier * Removed withdrawable check from verifyDeposit (#2640) * verifyDeposit removed check if the validator of the first deposit was exiting * Fixed the verifyDeposit unit test data * allow for multiple full/partial validator exits even if full exit request has already been made (#2641) (cherry picked from commit 4febfad) * change validator index from uint64 to uint40 (#2642) * account as early as possible for the loss because of the front run deposit (#2643) * [SP - 4] Verify validator type (#2644) * verify that validator type is the consolidating one * add test * Deployed latest to Hoodi * Fix verifyDeposit Hardhat task * Redeployed both BeaconProofs and CompoundingStakingSSVStrategy to Hoodi * Deployed new strategy to Hoodi * Restrict initial deposit to 1 ETH (#2646) * Changed DEPOSIT_AMOUNT_WEI to 1 ETH * Adjusted unit tests for 1 ETH deposits * Deployed strategy contract with initial 1 ETH deposit * Changed stakeValidator so sig, withdrawalCredentials and forkVersion are optional Only verify the sig for 1 ETH deposits * Fixed validator public key proof unit test * verifyDeposit slot default to 33 slots ago * fix slither * Validator deposit and withdrawal amounts can have decimals * Format snapStakingStrat * Do not allow exiting a validator with a pending deposit (#2647) * Validator deposit and withdrawal amounts can have decimals * Format snapStakingStrat * Revert exiting a validator if there is a pending deposit * prettier * add check for zero padding in withdrawal credentials (#2645) * add check for zero padding in withdrawal credentials * more efficient withdrawal credentials check * ORGN-01 Array Element Skipping During Deposit Removal in verifyBalances (#2650) * Fix for: Deposit Balance Undercount Due To Missing Timestamp Validation In verifyDeposit() (#2651) * add verifyDeposit check to confirm there is no conflicting timestamp * shorten error * Fixed unit test of verifyValidator proof * Deposits to withdrawn validator (#2652) * add basic files for mocking beacon roots * add tests for multiple deposits to exiting validator. Also fix bug not storing the deposit data * add a test where deposit is removed in verifyBalances * more test checks * Post merge fix * Disable linter in MockBeaconProofs * Fixed unit tests * Added unit test for a front-run initial deposit * Added more unit tests for front-run deposit * Alternative fix to setting the withdrawable epoch (#2654) * fix tests * More unit tests (#2655) * Alternative fix to setting the withdrawable epoch * Added more unit tests * Fix inconsistent test failure * add check that the deposits have been removed * add comment --------- Co-authored-by: Nicholas Addison <nick@addisonbrown.com.au> * SP-12 Miscellaneous General Comments (#2657) * Changed CompoundingValidatorManager storage gap to 40 * Fixed Natspec of BALANCES_CONTAINER_GENERALIZED_INDEX * verifyDeposit has early exit if slot of first pending deposit is zero Default first pending deposit slot to 1 if the beacon deposit queue is empty * Fixed verificationEpoch calc to use the slot of the parent root (#2656) * Added more unit tests for verifyBalances * Fixed the unit tests * Added unit test for removing an invalid validator * Deploy to latest to Hoodi * remove deposit count subtraction as it is no longer needed (#2660) * simplify withdrawal credential comparison (#2659) * correct the comment (#2663) * Refactor verifyBalances to use inclusion proofs of pending deposits (#2658) * Refactor verifyBalances to use inclusion proofs of pending deposits * Refactor stakeEth to use the pending deposit root as the deposit identifier. Ensure the pending deposit root is unique. * WIP fixing unit tests * Logical state diagram for the staking strategy * Fix verifyBalances to not verify pending deposits of exited validators * More unit test fixes * Fixes the last of the failing unit tests * verify deposits to exiting validators (#2664) * add the support to handle verifying deposits to exited validators * verifyBalances no longer removes deposits * remove event * remove deposit when done to an exiting validator * Removed setting the validator as EXISTING from verifyDeposit * Updated staking state diagram * Can now use a normal for loop of the deposits in verifyBalances * Moved firstPendingDepositEpoch to just before it is used * change error message * add pausable ability to the validator --------- Co-authored-by: Nicholas Addison <nick@addisonbrown.com.au> * Exiting validator (#2665) * do not exit a validator as long as it has pending deposits * Fixed verifyBalances - deposit loop inside the validator loop using different iterator * Prettier --------- Co-authored-by: Nicholas Addison <nick@addisonbrown.com.au> --------- Co-authored-by: Domen Grabec <grabec@gmail.com> * Restrict full withdrawals for non activateable validators (#2662) * make it mandatory for validator to have active balance before allowing full withdrawals * minor update * fix bugs * add test * prettier * Updated the validator state diagram * make some variables internal to save contract space * simplification * Added ACTIVE validator state (#2666) * Added ACTIVE validator state * Fixed ACTIVE change Updated unit tests * Updated state diagram * Deploy new strategy to Hoodi --------- Co-authored-by: Nicholas Addison <nick@addisonbrown.com.au> * Logging and linter * Fix to allow multiple full validator exits (#2667) * Allow a validator full exit when it is already exiting * Updated validator state diagram * Increased the min balance to be active to over 32.25 ETH (#2668) Co-authored-by: Domen Grabec <grabec@gmail.com> * Gas optimization in verifyBalances to only iterate over the deposits if the validator has a zero balance (#2671) * restrict pending deposit index to uint32 (#2670) * Restricted the pending deposit index to uint32 as the pending deposits container height is only 28 * Added check that pendingDepositIndex is < 2**27 in verifyPendingDeposit * Can verify a deposit if the validator is exiting and the pending deposit queue is empty (#2669) * Can verify a deposit if the validator is exiting and the pending deposit queue is empty * add comment --------- Co-authored-by: Domen Grabec <grabec@gmail.com> * Deployed the latest staking strategy to Hoodi * Fixed verifyDeposit Hardhat task * Fixed verifyBalances Hardhat task when there is a pending deposit * Added negative unit tests * Added more unit tests * ORGN-02 can make a validator INVALID with an incorrect validator type (#2673) * Allow verification of a non 0x02 validator so it can be marked as INVALID * Added unit test for verifying an invalid validator type * pass withdrawal credentials when verifying validator (#2674) * Fixed verifyValidator Hardhat task * Fixed beacon proof fork test --------- Co-authored-by: Domen Grabec <grabec@gmail.com> * Deployed the latest contracts to Hoodi * Fixed the validator states in Hardhat task snapStakingStrat * typo * typo * Improve getValidator Hardhat task output * remove comment * remove StakingMonitorChanged event from CompoundingValidatorManager (#2682) * MAX_VERIFIED_VALIDATORS off by one (#2683) * Fix comments (#2684) * automated withdrawals from the staking strategy and validators (#2685) * Allow withdraws from the staking strategy by the Registrator for automation * Added signMessage HH task for Etherscan ownership verification * Deployed latest strategy contract to Hoodi * Added autoValidatorWithdrawals Hardhat task * Fixed unit tests * Changed execute option to dryrun * Created reusable totalPartialWithdrawals function Fixed summing of partial withdrawal amount as its in Gwei * Remove upgrade of old native staking strategies (#2686) * Revert upgrading the old native staking strategies * Restored old Hardhat tasks to bulk exit and remove validators from the old native staking strategies * Added lodestar packages to lock file * Bumped deploy script numbers * auto deposits to validators (#2688) * Added autoValidatorDeposits Hardhat task * Set the new staking strategy as the default for the OETH Vault * Refactor auto deposit * Fix auto deposits (#2689) * Fix auto deposits to include pending deposits * Increased MAX_DEPOSITS from 12 to 32 Deployed latest strategy contract to Hoodi * fix the problem where prettier isn't able to load the plugin automatically using pnpm * fix small bug * Added queue position to pending deposits in snapStakingStrat (#2691) * Improve formatting of snapStakingStrat * Added unit tests address for CompoundingStakingStrategyProxy * Deployed the new staking strategy contracts to mainnet (#2692) * Deployed the new staking strategy contracts to mainnet * Added 154_upgrade_native_staking to .migrations file * Add governance proposal id * Fix spelling in README * Added BEACON_PROVIDER_URL to CI for mainnet fork tests --------- Co-authored-by: Clément <clemmoller@gmail.com> Co-authored-by: Domen Grabec <grabec@gmail.com> Co-authored-by: Clément <55331875+clement-ux@users.noreply.github.com>
1 parent 68065ea commit ab1fe9a

189 files changed

Lines changed: 52551 additions & 572 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/defi.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ jobs:
180180
env:
181181
HARDHAT_CACHE_DIR: ./cache
182182
PROVIDER_URL: ${{ secrets.PROVIDER_URL }}
183+
BEACON_PROVIDER_URL: ${{ secrets.BEACON_PROVIDER_URL }}
183184
ONEINCH_API_KEY: ${{ secrets.ONEINCH_API_KEY }}
184185
CHUNK_ID: "${{matrix.chunk_id}}"
185186
MAX_CHUNKS: "4"

contracts/.prettierrc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
2+
"plugins": ["prettier-plugin-solidity"],
23
"overrides": [
34
{
45
"files": "*.sol",
@@ -7,8 +8,7 @@
78
"tabWidth": 4,
89
"useTabs": false,
910
"singleQuote": false,
10-
"bracketSpacing": true,
11-
"explicitTypes": "always"
11+
"bracketSpacing": true
1212
}
1313
},
1414
{

contracts/README.md

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -341,9 +341,7 @@ export DEFENDER_TEAM_SECRET=
341341
# set -o allexport && source ../../.env && set +o allexport
342342

343343
# Set the DEBUG environment variable to oeth* for the Defender Action
344-
npx hardhat setActionVars --id 38e44420-f38b-4d4a-86b0-6012a8897ad9
345344
npx hardhat setActionVars --id f4b5b8d4-82ff-483f-bfae-9fef015790ca
346-
npx hardhat setActionVars --id 191d9631-70b9-43c5-9db4-1dd985fde05c
347345
npx hardhat setActionVars --id e2929f53-db56-49b2-b054-35f7df7fc4fb
348346
npx hardhat setActionVars --id 12c153c8-c5ca-420b-9696-e80c827996d1
349347
npx hardhat setActionVars --id 6e4f764d-4126-45a5-b7d9-1ab90cd3ffd6
@@ -354,9 +352,6 @@ npx hardhat setActionVars --id b1d831f1-29d4-4943-bb2e-8e625b76e82c
354352
# The Defender autotask client uses generic env var names so we'll set them first from the values in the .env file
355353
export API_KEY=${DEFENDER_TEAM_KEY}
356354
export API_SECRET=${DEFENDER_TEAM_SECRET}
357-
# Holesky
358-
npx defender-autotask update-code 38e44420-f38b-4d4a-86b0-6012a8897ad9 ./dist/registerValidators
359-
npx defender-autotask update-code 191d9631-70b9-43c5-9db4-1dd985fde05c ./dist/doAccounting
360355
# Mainnet
361356
npx defender-autotask update-code f4b5b8d4-82ff-483f-bfae-9fef015790ca ./dist/registerValidators
362357
npx defender-autotask update-code 12c153c8-c5ca-420b-9696-e80c827996d1 ./dist/stakeValidators
@@ -446,8 +441,7 @@ npx hardhat --network mainnet verify --contract contracts/strategies/FluxStrateg
446441
```
447442

448443

449-
450-
`hardhat-deploy` package offers a secondary way to verify contracts, where contructor parameters don't need to be passed into the verification call. Since Etherscan has migrated to V2 api this approach is no longer working. `etherscan-verify` call uses `hardhat verify` under the hood.
444+
`hardhat-deploy` package offers a secondary way to verify contracts, where constructor parameters don't need to be passed into the verification call. Since Etherscan has migrated to V2 api this approach is no longer working. `etherscan-verify` call uses `hardhat verify` under the hood.
451445
```
452446
yarn hardhat etherscan-verify --network mainnet --api-url https://api.etherscan.io
453447
```
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// SPDX-License-Identifier: BUSL-1.1
2+
pragma solidity ^0.8.0;
3+
4+
/**
5+
* @title Library to request validator consolidation on the beacon chain.
6+
* @author Origin Protocol Inc
7+
*/
8+
library BeaconConsolidation {
9+
/// @notice The address the validator consolidation requests are sent
10+
/// See https://eips.ethereum.org/EIPS/eip-7251
11+
address internal constant CONSOLIDATION_REQUEST_ADDRESS =
12+
0x0000BBdDc7CE488642fb579F8B00f3a590007251;
13+
14+
function request(bytes calldata source, bytes calldata target)
15+
internal
16+
returns (uint256 fee_)
17+
{
18+
require(source.length == 48, "Invalid source byte length");
19+
require(target.length == 48, "Invalid target byte length");
20+
21+
fee_ = fee();
22+
23+
// Call the Consolidation Request contract with the public keys of the source and target
24+
// validators packed together.
25+
// This does not have a function signature, so we use a call
26+
(bool success, ) = CONSOLIDATION_REQUEST_ADDRESS.call{ value: fee_ }(
27+
abi.encodePacked(source, target)
28+
);
29+
30+
require(success, "Consolidation request failed");
31+
}
32+
33+
function fee() internal view returns (uint256) {
34+
// Get fee from the consolidation request contract
35+
(bool success, bytes memory result) = CONSOLIDATION_REQUEST_ADDRESS
36+
.staticcall("");
37+
38+
require(success && result.length > 0, "Failed to get fee");
39+
return abi.decode(result, (uint256));
40+
}
41+
}
Lines changed: 187 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,187 @@
1+
// SPDX-License-Identifier: BUSL-1.1
2+
pragma solidity ^0.8.0;
3+
4+
import { BeaconProofsLib } from "./BeaconProofsLib.sol";
5+
import { IBeaconProofs } from "../interfaces/IBeaconProofs.sol";
6+
7+
/**
8+
* @title Verifies merkle proofs of beacon chain data.
9+
* @author Origin Protocol Inc
10+
*/
11+
contract BeaconProofs is IBeaconProofs {
12+
/// @notice Verifies the validator index is for the given validator public key.
13+
/// Also verify the validator's withdrawal credential points to the withdrawal address.
14+
/// BeaconBlock.state.validators[validatorIndex].pubkey
15+
/// @param beaconBlockRoot The root of the beacon block
16+
/// @param pubKeyHash Hash of validator's public key using the Beacon Chain's format
17+
/// @param proof The merkle proof for the validator public key to the beacon block root.
18+
/// This is 53 witness hashes of 32 bytes each concatenated together starting from the leaf node.
19+
/// @param validatorIndex The validator index
20+
/// @param withdrawalCredentials a value containing the validator type and withdrawal address.
21+
function verifyValidator(
22+
bytes32 beaconBlockRoot,
23+
bytes32 pubKeyHash,
24+
bytes calldata proof,
25+
uint40 validatorIndex,
26+
bytes32 withdrawalCredentials
27+
) external view {
28+
BeaconProofsLib.verifyValidator(
29+
beaconBlockRoot,
30+
pubKeyHash,
31+
proof,
32+
validatorIndex,
33+
withdrawalCredentials
34+
);
35+
}
36+
37+
function verifyValidatorWithdrawable(
38+
bytes32 beaconBlockRoot,
39+
uint40 validatorIndex,
40+
uint64 withdrawableEpoch,
41+
bytes calldata withdrawableEpochProof
42+
) external view {
43+
BeaconProofsLib.verifyValidatorWithdrawableEpoch(
44+
beaconBlockRoot,
45+
validatorIndex,
46+
withdrawableEpoch,
47+
withdrawableEpochProof
48+
);
49+
}
50+
51+
/// @notice Verifies the balances container to the beacon block root
52+
/// BeaconBlock.state.balances
53+
/// @param beaconBlockRoot The root of the beacon block
54+
/// @param balancesContainerRoot The merkle root of the the balances container
55+
/// @param balancesContainerProof The merkle proof for the balances container to the beacon block root.
56+
/// This is 9 witness hashes of 32 bytes each concatenated together starting from the leaf node.
57+
function verifyBalancesContainer(
58+
bytes32 beaconBlockRoot,
59+
bytes32 balancesContainerRoot,
60+
bytes calldata balancesContainerProof
61+
) external view {
62+
BeaconProofsLib.verifyBalancesContainer(
63+
beaconBlockRoot,
64+
balancesContainerRoot,
65+
balancesContainerProof
66+
);
67+
}
68+
69+
/// @notice Verifies the validator balance to the root of the Balances container.
70+
/// @param balancesContainerRoot The merkle root of the Balances container.
71+
/// @param validatorBalanceLeaf The leaf node containing the validator balance with three other balances.
72+
/// @param balanceProof The merkle proof for the validator balance to the Balances container root.
73+
/// This is 39 witness hashes of 32 bytes each concatenated together starting from the leaf node.
74+
/// @param validatorIndex The validator index to verify the balance for
75+
/// @return validatorBalanceGwei The balance in Gwei of the validator at the given index
76+
function verifyValidatorBalance(
77+
bytes32 balancesContainerRoot,
78+
bytes32 validatorBalanceLeaf,
79+
bytes calldata balanceProof,
80+
uint40 validatorIndex
81+
) external view returns (uint256 validatorBalanceGwei) {
82+
validatorBalanceGwei = BeaconProofsLib.verifyValidatorBalance(
83+
balancesContainerRoot,
84+
validatorBalanceLeaf,
85+
balanceProof,
86+
validatorIndex
87+
);
88+
}
89+
90+
/// @notice Verifies the pending deposits container to the beacon block root.
91+
/// BeaconBlock.state.pendingDeposits
92+
/// @param beaconBlockRoot The root of the beacon block.
93+
/// @param pendingDepositsContainerRoot The merkle root of the the pending deposits container.
94+
/// @param proof The merkle proof for the pending deposits container to the beacon block root.
95+
/// This is 9 witness hashes of 32 bytes each concatenated together starting from the leaf node.
96+
function verifyPendingDepositsContainer(
97+
bytes32 beaconBlockRoot,
98+
bytes32 pendingDepositsContainerRoot,
99+
bytes calldata proof
100+
) external view {
101+
BeaconProofsLib.verifyPendingDepositsContainer(
102+
beaconBlockRoot,
103+
pendingDepositsContainerRoot,
104+
proof
105+
);
106+
}
107+
108+
/// @notice Verified a pending deposit to the root of the Pending Deposits container.
109+
/// @param pendingDepositsContainerRoot The merkle root of the Pending Deposits container.
110+
/// @param pendingDepositRoot The leaf node containing the validator balance with three other balances.
111+
/// @param proof The merkle proof for the pending deposit root to the Pending Deposits container root.
112+
/// This is 28 witness hashes of 32 bytes each concatenated together starting from the leaf node.
113+
/// @param pendingDepositIndex The pending deposit index in the Pending Deposits container
114+
function verifyPendingDeposit(
115+
bytes32 pendingDepositsContainerRoot,
116+
bytes32 pendingDepositRoot,
117+
bytes calldata proof,
118+
uint32 pendingDepositIndex
119+
) external view {
120+
BeaconProofsLib.verifyPendingDeposit(
121+
pendingDepositsContainerRoot,
122+
pendingDepositRoot,
123+
proof,
124+
pendingDepositIndex
125+
);
126+
}
127+
128+
/// @notice If the deposit queue is not empty,
129+
/// verify the slot of the first pending deposit to the beacon block root.
130+
/// BeaconBlock.state.pendingDeposits[0].slot
131+
/// If the deposit queue is empty, verify the root of the first pending deposit is empty
132+
/// BeaconBlock.state.PendingDeposits[0]
133+
/// @param beaconBlockRoot The root of the beacon block.
134+
/// @param slot The beacon chain slot of the first deposit in the beacon chain's deposit queue.
135+
/// Can be anything if the deposit queue is empty.
136+
/// @param firstPendingDepositSlotProof The merkle proof to the beacon block root. Can be either:
137+
/// - 40 witness hashes for BeaconBlock.state.PendingDeposits[0].slot when the deposit queue is not empty.
138+
/// - 37 witness hashes for BeaconBlock.state.PendingDeposits[0] when the deposit queue is empty.
139+
/// The 32 byte witness hashes are concatenated together starting from the leaf node.
140+
/// @return isEmptyDepositQueue True if the deposit queue is empty, false otherwise.
141+
function verifyFirstPendingDeposit(
142+
bytes32 beaconBlockRoot,
143+
uint64 slot,
144+
bytes calldata firstPendingDepositSlotProof
145+
) external view returns (bool isEmptyDepositQueue) {
146+
isEmptyDepositQueue = BeaconProofsLib.verifyFirstPendingDeposit(
147+
beaconBlockRoot,
148+
slot,
149+
firstPendingDepositSlotProof
150+
);
151+
}
152+
153+
/// @notice Merkleizes a beacon chain pending deposit.
154+
/// @param pubKeyHash Hash of validator's public key using the Beacon Chain's format
155+
/// @param withdrawalCredentials The 32 byte withdrawal credentials.
156+
/// @param amountGwei The amount of the deposit in Gwei.
157+
/// @param signature The 96 byte BLS signature.
158+
/// @param slot The beacon chain slot the deposit was made in.
159+
/// @return root The merkle root of the pending deposit.
160+
function merkleizePendingDeposit(
161+
bytes32 pubKeyHash,
162+
bytes calldata withdrawalCredentials,
163+
uint64 amountGwei,
164+
bytes calldata signature,
165+
uint64 slot
166+
) external pure returns (bytes32) {
167+
return
168+
BeaconProofsLib.merkleizePendingDeposit(
169+
pubKeyHash,
170+
withdrawalCredentials,
171+
amountGwei,
172+
signature,
173+
slot
174+
);
175+
}
176+
177+
/// @notice Merkleizes a BLS signature used for validator deposits.
178+
/// @param signature The 96 byte BLS signature.
179+
/// @return root The merkle root of the signature.
180+
function merkleizeSignature(bytes calldata signature)
181+
external
182+
pure
183+
returns (bytes32 root)
184+
{
185+
return BeaconProofsLib.merkleizeSignature(signature);
186+
}
187+
}

0 commit comments

Comments
 (0)