From 4141203963a8f081c5553125e48f4713d16967bf Mon Sep 17 00:00:00 2001 From: adu Date: Tue, 21 Jan 2025 14:52:00 +0800 Subject: [PATCH 1/4] feat: remove reward vault deployment in initialization --- src/core/ClientChainGateway.sol | 4 +--- test/foundry/BootstrapDepositNST.t.sol | 1 + test/foundry/ExocoreDeployer.t.sol | 5 ++++- test/foundry/unit/Bootstrap.t.sol | 1 + test/foundry/unit/ExoCapsule.t.sol | 3 +++ 5 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/core/ClientChainGateway.sol b/src/core/ClientChainGateway.sol index 3858462b..66edaecb 100644 --- a/src/core/ClientChainGateway.sol +++ b/src/core/ClientChainGateway.sol @@ -68,8 +68,6 @@ contract ClientChainGateway is bootstrapped = true; - _deployRewardVault(); - _transferOwnership(owner_); __OAppCore_init_unchained(owner_); __Pausable_init_unchained(); @@ -148,7 +146,7 @@ contract ClientChainGateway is // The bytecode returned by the BEACON_PROXY_BYTECODE contract is static, so there is no risk of collision. // slither-disable-next-line encode-packed-collision - function _deployRewardVault() internal { + function deployRewardVault() external onlyOwner whenNotPaused { rewardVault = IRewardVault( Create2.deploy( 0, diff --git a/test/foundry/BootstrapDepositNST.t.sol b/test/foundry/BootstrapDepositNST.t.sol index 9bbc2e00..44d54547 100644 --- a/test/foundry/BootstrapDepositNST.t.sol +++ b/test/foundry/BootstrapDepositNST.t.sol @@ -71,6 +71,7 @@ contract BootstrapDepositNSTTest is Test { event StakedWithCapsule(address indexed staker, address indexed capsule); function setUp() public { + vm.chainId(1); // set chainid to 1 so that capsule implementation can use default network constants vm.startPrank(deployer); whitelistTokens.push(VIRTUAL_STAKED_ETH_ADDRESS); diff --git a/test/foundry/ExocoreDeployer.t.sol b/test/foundry/ExocoreDeployer.t.sol index 86784adc..0525a95f 100644 --- a/test/foundry/ExocoreDeployer.t.sol +++ b/test/foundry/ExocoreDeployer.t.sol @@ -383,7 +383,10 @@ contract ExocoreDeployer is Test { // get the reward vault address since it would be deployed during initialization rewardVault = clientGateway.rewardVault(); - require(address(rewardVault) != address(0), "reward vault should not be empty"); + require( + address(rewardVault) == address(0), + "reward vault should be empty since it is not deployed in initialization" + ); // deploy Exocore network contracts exocoreGatewayLogic = new ExocoreGateway(address(exocoreLzEndpoint)); diff --git a/test/foundry/unit/Bootstrap.t.sol b/test/foundry/unit/Bootstrap.t.sol index 9c7d1ddf..c3bdb69b 100644 --- a/test/foundry/unit/Bootstrap.t.sol +++ b/test/foundry/unit/Bootstrap.t.sol @@ -85,6 +85,7 @@ contract BootstrapTest is Test { hex"608060405260405161090e38038061090e83398101604081905261002291610460565b61002e82826000610035565b505061058a565b61003e83610100565b6040516001600160a01b038416907f1cf3b03a6cf19fa2baba4df148e9dcabedea7f8a5c07840e207e5c089be95d3e90600090a260008251118061007f5750805b156100fb576100f9836001600160a01b0316635c60da1b6040518163ffffffff1660e01b8152600401602060405180830381865afa1580156100c5573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906100e99190610520565b836102a360201b6100291760201c565b505b505050565b610113816102cf60201b6100551760201c565b6101725760405162461bcd60e51b815260206004820152602560248201527f455243313936373a206e657720626561636f6e206973206e6f74206120636f6e6044820152641d1c9858dd60da1b60648201526084015b60405180910390fd5b6101e6816001600160a01b0316635c60da1b6040518163ffffffff1660e01b8152600401602060405180830381865afa1580156101b3573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906101d79190610520565b6102cf60201b6100551760201c565b61024b5760405162461bcd60e51b815260206004820152603060248201527f455243313936373a20626561636f6e20696d706c656d656e746174696f6e206960448201526f1cc81b9bdd08184818dbdb9d1c9858dd60821b6064820152608401610169565b806102827fa3f0ad74e5423aebfd80d3ef4346578335a9a72aeaee59ff6cb3582b35133d5060001b6102de60201b6100641760201c565b80546001600160a01b0319166001600160a01b039290921691909117905550565b60606102c883836040518060600160405280602781526020016108e7602791396102e1565b9392505050565b6001600160a01b03163b151590565b90565b6060600080856001600160a01b0316856040516102fe919061053b565b600060405180830381855af49150503d8060008114610339576040519150601f19603f3d011682016040523d82523d6000602084013e61033e565b606091505b5090925090506103508683838761035a565b9695505050505050565b606083156103c65782516103bf576001600160a01b0385163b6103bf5760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606401610169565b50816103d0565b6103d083836103d8565b949350505050565b8151156103e85781518083602001fd5b8060405162461bcd60e51b81526004016101699190610557565b80516001600160a01b038116811461041957600080fd5b919050565b634e487b7160e01b600052604160045260246000fd5b60005b8381101561044f578181015183820152602001610437565b838111156100f95750506000910152565b6000806040838503121561047357600080fd5b61047c83610402565b60208401519092506001600160401b038082111561049957600080fd5b818501915085601f8301126104ad57600080fd5b8151818111156104bf576104bf61041e565b604051601f8201601f19908116603f011681019083821181831017156104e7576104e761041e565b8160405282815288602084870101111561050057600080fd5b610511836020830160208801610434565b80955050505050509250929050565b60006020828403121561053257600080fd5b6102c882610402565b6000825161054d818460208701610434565b9190910192915050565b6020815260008251806020840152610576816040850160208701610434565b601f01601f19169190910160400192915050565b61034e806105996000396000f3fe60806040523661001357610011610017565b005b6100115b610027610022610067565b610100565b565b606061004e83836040518060600160405280602781526020016102f260279139610124565b9392505050565b6001600160a01b03163b151590565b90565b600061009a7fa3f0ad74e5423aebfd80d3ef4346578335a9a72aeaee59ff6cb3582b35133d50546001600160a01b031690565b6001600160a01b0316635c60da1b6040518163ffffffff1660e01b8152600401602060405180830381865afa1580156100d7573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906100fb9190610249565b905090565b3660008037600080366000845af43d6000803e80801561011f573d6000f35b3d6000fd5b6060600080856001600160a01b03168560405161014191906102a2565b600060405180830381855af49150503d806000811461017c576040519150601f19603f3d011682016040523d82523d6000602084013e610181565b606091505b50915091506101928683838761019c565b9695505050505050565b6060831561020d578251610206576001600160a01b0385163b6102065760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e747261637400000060448201526064015b60405180910390fd5b5081610217565b610217838361021f565b949350505050565b81511561022f5781518083602001fd5b8060405162461bcd60e51b81526004016101fd91906102be565b60006020828403121561025b57600080fd5b81516001600160a01b038116811461004e57600080fd5b60005b8381101561028d578181015183820152602001610275565b8381111561029c576000848401525b50505050565b600082516102b4818460208701610272565b9190910192915050565b60208152600082518060208401526102dd816040850160208701610272565b601f01601f1916919091016040019291505056fe416464726573733a206c6f772d6c6576656c2064656c65676174652063616c6c206661696c6564a2646970667358221220d51e81d3bc5ed20a26aeb05dce7e825c503b2061aa78628027300c8d65b9d89a64736f6c634300080c0033416464726573733a206c6f772d6c6576656c2064656c65676174652063616c6c206661696c6564"; function setUp() public { + vm.chainId(1); // set chainid to 1 so that capsule implementation can use default network constants addrs[0] = address(0x1); // Simulated VALIDATOR1 address addrs[1] = address(0x2); // Simulated VALIDATOR2 address addrs[2] = address(0x3); // Simulated VALIDATOR3 address diff --git a/test/foundry/unit/ExoCapsule.t.sol b/test/foundry/unit/ExoCapsule.t.sol index 4a76bf9f..56995f3c 100644 --- a/test/foundry/unit/ExoCapsule.t.sol +++ b/test/foundry/unit/ExoCapsule.t.sol @@ -48,6 +48,7 @@ contract DepositSetup is Test { uint256 mockCurrentBlockTimestamp; function setUp() public { + vm.chainId(1); // set chainid to 1 so that capsule implementation can use default network constants string memory validatorInfo = vm.readFile("test/foundry/test-data/validator_container_proof_8955769.json"); validatorContainer = stdJson.readBytes32Array(validatorInfo, ".ValidatorFields"); @@ -356,6 +357,8 @@ contract WithdrawalSetup is Test { uint256 activationTimestamp; function setUp() public { + vm.chainId(1); // set chainid to 1 so that capsule implementation can use default network constants + string memory validatorInfo = vm.readFile("test/foundry/test-data/validator_container_proof_302913.json"); _setValidatorContainer(validatorInfo); From 4e5780c22614e88693ccff0926ae2b83d8d500d6 Mon Sep 17 00:00:00 2001 From: adu Date: Tue, 21 Jan 2025 15:04:13 +0800 Subject: [PATCH 2/4] docs: add comment --- src/core/ClientChainGateway.sol | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/core/ClientChainGateway.sol b/src/core/ClientChainGateway.sol index 66edaecb..5ede2b62 100644 --- a/src/core/ClientChainGateway.sol +++ b/src/core/ClientChainGateway.sol @@ -144,6 +144,10 @@ contract ClientChainGateway is return (SENDER_VERSION, RECEIVER_VERSION); } + /** + * @notice Deploy the reward vault contract. + * @dev The reward vault would be deployed with beacon proxy pattern like other vaults + */ // The bytecode returned by the BEACON_PROXY_BYTECODE contract is static, so there is no risk of collision. // slither-disable-next-line encode-packed-collision function deployRewardVault() external onlyOwner whenNotPaused { From 8f7d668fbcec08647dbc677bb6c4e3aad4b3c58f Mon Sep 17 00:00:00 2001 From: adu Date: Tue, 21 Jan 2025 15:07:19 +0800 Subject: [PATCH 3/4] Update src/core/ClientChainGateway.sol Co-authored-by: Max <82761650+MaxMustermann2@users.noreply.github.com> --- src/core/ClientChainGateway.sol | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/core/ClientChainGateway.sol b/src/core/ClientChainGateway.sol index 5ede2b62..8f7fbeec 100644 --- a/src/core/ClientChainGateway.sol +++ b/src/core/ClientChainGateway.sol @@ -144,10 +144,8 @@ contract ClientChainGateway is return (SENDER_VERSION, RECEIVER_VERSION); } - /** - * @notice Deploy the reward vault contract. - * @dev The reward vault would be deployed with beacon proxy pattern like other vaults - */ + /// @notice Deploy the reward vault contract. + /// @dev The reward vault would be deployed with beacon proxy pattern like other vaults // The bytecode returned by the BEACON_PROXY_BYTECODE contract is static, so there is no risk of collision. // slither-disable-next-line encode-packed-collision function deployRewardVault() external onlyOwner whenNotPaused { From bf5b2ada7e696152a92974d2bca185cf433a837f Mon Sep 17 00:00:00 2001 From: adu Date: Tue, 21 Jan 2025 15:08:32 +0800 Subject: [PATCH 4/4] fix format --- src/core/ClientChainGateway.sol | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/core/ClientChainGateway.sol b/src/core/ClientChainGateway.sol index 8f7fbeec..ae992034 100644 --- a/src/core/ClientChainGateway.sol +++ b/src/core/ClientChainGateway.sol @@ -144,8 +144,8 @@ contract ClientChainGateway is return (SENDER_VERSION, RECEIVER_VERSION); } - /// @notice Deploy the reward vault contract. - /// @dev The reward vault would be deployed with beacon proxy pattern like other vaults + /// @notice Deploy the reward vault contract. + /// @dev The reward vault would be deployed with beacon proxy pattern like other vaults // The bytecode returned by the BEACON_PROXY_BYTECODE contract is static, so there is no risk of collision. // slither-disable-next-line encode-packed-collision function deployRewardVault() external onlyOwner whenNotPaused {