-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Stake funds with confirmations for front-running protection of Beacon…
… Deposits (#2074) * contract changes and tests for gated protection against front running * Update off-chain validator registration process to also consider stake threshold * front run protection changes (#2076) * Added Holesky deploy script * Fixed OUSD metapool fork test * Generated latest NativeStakingSSVStrategy contract diagrams * Deployed new NativeStakingSSVStrategy to Holesky --------- Co-authored-by: Nicholas Addison <nick@addisonbrown.com.au>
- Loading branch information
1 parent
e853081
commit 12bba64
Showing
19 changed files
with
906 additions
and
299 deletions.
There are no files selected for viewing
53 changes: 0 additions & 53 deletions
53
contracts/contracts/mocks/BeaconChainDepositContractMock.sol
This file was deleted.
Oops, something went wrong.
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,80 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.0; | ||
|
||
import { IDepositContract } from "./../interfaces/IDepositContract.sol"; | ||
|
||
contract MockDepositContract is IDepositContract { | ||
uint256 deposit_count; | ||
|
||
function deposit( | ||
bytes calldata pubkey, | ||
bytes calldata withdrawal_credentials, | ||
bytes calldata signature, | ||
bytes32 deposit_data_root | ||
) external payable override { | ||
require(pubkey.length == 48, "DepositContract: invalid pubkey length"); | ||
require( | ||
withdrawal_credentials.length == 32, | ||
"DepositContract: invalid withdrawal_credentials length" | ||
); | ||
require( | ||
signature.length == 96, | ||
"DepositContract: invalid signature length" | ||
); | ||
|
||
// Check deposit amount | ||
require(msg.value >= 1 ether, "DepositContract: deposit value too low"); | ||
require( | ||
msg.value % 1 gwei == 0, | ||
"DepositContract: deposit value not multiple of gwei" | ||
); | ||
uint256 deposit_amount = msg.value / 1 gwei; | ||
require( | ||
deposit_amount <= type(uint64).max, | ||
"DepositContract: deposit value too high" | ||
); | ||
|
||
// Emit `DepositEvent` log | ||
bytes memory amount = to_little_endian_64(uint64(deposit_amount)); | ||
emit DepositEvent( | ||
pubkey, | ||
withdrawal_credentials, | ||
amount, | ||
signature, | ||
to_little_endian_64(uint64(deposit_count)) | ||
); | ||
require( | ||
deposit_data_root != 0, | ||
"DepositContract: invalid deposit_data_root" | ||
); | ||
} | ||
|
||
function get_deposit_root() external view override returns (bytes32) { | ||
// just return some bytes32 | ||
return sha256(abi.encodePacked(deposit_count, bytes16(0))); | ||
} | ||
|
||
/// @notice Query the current deposit count. | ||
/// @return The deposit count encoded as a little endian 64-bit number. | ||
function get_deposit_count() external view override returns (bytes memory) { | ||
return to_little_endian_64(uint64(deposit_count)); | ||
} | ||
|
||
function to_little_endian_64(uint64 value) | ||
internal | ||
pure | ||
returns (bytes memory ret) | ||
{ | ||
ret = new bytes(8); | ||
bytes8 bytesValue = bytes8(value); | ||
// Byteswapping during copying to bytes. | ||
ret[0] = bytesValue[7]; | ||
ret[1] = bytesValue[6]; | ||
ret[2] = bytesValue[5]; | ||
ret[3] = bytesValue[4]; | ||
ret[4] = bytesValue[3]; | ||
ret[5] = bytesValue[2]; | ||
ret[6] = bytesValue[1]; | ||
ret[7] = bytesValue[0]; | ||
} | ||
} |
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 |
---|---|---|
@@ -1,6 +1,32 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.0; | ||
|
||
import { Cluster } from "./../interfaces/ISSVNetwork.sol"; | ||
|
||
contract MockSSVNetwork { | ||
constructor() {} | ||
function registerValidator( | ||
bytes calldata publicKey, | ||
uint64[] calldata operatorIds, | ||
bytes calldata sharesData, | ||
uint256 amount, | ||
Cluster memory cluster | ||
) external {} | ||
|
||
function exitValidator( | ||
bytes calldata publicKey, | ||
uint64[] calldata operatorIds | ||
) external {} | ||
|
||
function removeValidator( | ||
bytes calldata publicKey, | ||
uint64[] calldata operatorIds, | ||
Cluster memory cluster | ||
) external {} | ||
|
||
function deposit( | ||
address clusterOwner, | ||
uint64[] calldata operatorIds, | ||
uint256 amount, | ||
Cluster memory cluster | ||
) external {} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
const { upgradeNativeStakingSSVStrategy } = require("../deployActions"); | ||
const { withConfirmation } = require("../../utils/deploy"); | ||
const { resolveContract } = require("../../utils/resolvers"); | ||
const addresses = require("../../utils/addresses"); | ||
const { parseEther } = require("ethers/lib/utils"); | ||
// const { impersonateAndFund } = require("../../utils/signers.js"); | ||
|
||
const mainExport = async () => { | ||
console.log("Running 010 deployment on Holesky..."); | ||
|
||
console.log("Upgrading native staking strategy"); | ||
await upgradeNativeStakingSSVStrategy(); | ||
|
||
const cNativeStakingStrategy = await resolveContract( | ||
"NativeStakingSSVStrategyProxy", | ||
"NativeStakingSSVStrategy" | ||
); | ||
|
||
const { governorAddr } = await getNamedAccounts(); | ||
const sGovernor = await ethers.provider.getSigner(governorAddr); | ||
|
||
await withConfirmation( | ||
cNativeStakingStrategy | ||
.connect(sGovernor) | ||
// Holesky defender relayer | ||
.setStakingMonitor(addresses.holesky.Guardian) | ||
); | ||
|
||
await withConfirmation( | ||
cNativeStakingStrategy | ||
.connect(sGovernor) | ||
.setStakeETHThreshold(parseEther("64")) | ||
); | ||
|
||
console.log( | ||
`Set the staking monitor to ${addresses.holesky.Guardian} and stake ETH threshold to 32 ETH` | ||
); | ||
|
||
console.log("Running 010 deployment done"); | ||
return true; | ||
}; | ||
|
||
mainExport.id = "010_upgrade_strategy"; | ||
mainExport.tags = []; | ||
mainExport.dependencies = []; | ||
mainExport.skip = () => false; | ||
|
||
module.exports = mainExport; |
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
Oops, something went wrong.