Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: remove governance role exocoreValidatorSet and keep owner only #47

Merged
merged 1 commit into from
Jul 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion script/7_DeployBootstrap.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ contract DeployBootstrapOnly is BaseScript {
exocoreValidatorSet.addr,
block.timestamp + 365 days + 24 hours,
24 hours,
payable(exocoreValidatorSet.addr),
whitelistTokens, // vault is auto deployed
address(proxyAdmin)
)
Expand Down
1 change: 0 additions & 1 deletion script/integration/1_DeployBootstrap.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ contract DeployContracts is Script {
vm.addr(contractDeployer),
block.timestamp + 3 minutes,
1 seconds,
payable(exocoreValidatorSet),
whitelistTokens,
address(proxyAdmin)
)
Expand Down
5 changes: 2 additions & 3 deletions src/core/BaseRestakingController.sol
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,8 @@ abstract contract BaseRestakingController is
).addExecutorOrderedExecutionOption();
MessagingFee memory fee = _quote(EXOCORE_CHAIN_ID, payload, options, false);

MessagingReceipt memory receipt = _lzSend(
EXOCORE_CHAIN_ID, payload, options, MessagingFee(fee.nativeFee, 0), exocoreValidatorSetAddress, false
);
MessagingReceipt memory receipt =
_lzSend(EXOCORE_CHAIN_ID, payload, options, MessagingFee(fee.nativeFee, 0), msg.sender, false);
emit MessageSent(action, receipt.guid, receipt.nonce, receipt.fee.nativeFee);
}

Expand Down
5 changes: 0 additions & 5 deletions src/core/Bootstrap.sol
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ contract Bootstrap is
address owner,
uint256 spawnTime_,
uint256 offsetDuration_,
address payable exocoreValidatorSetAddress_,
address[] calldata whitelistTokens_,
address customProxyAdmin_
) external initializer {
Expand All @@ -58,14 +57,10 @@ contract Bootstrap is
require(spawnTime_ > offsetDuration_, "Bootstrap: spawn time should be greater than offset duration");
uint256 lockTime = spawnTime_ - offsetDuration_;
require(lockTime > block.timestamp, "Bootstrap: lock time should be in the future");
require(
exocoreValidatorSetAddress_ != address(0), "Bootstrap: exocore validator set address should not be empty"
);
require(customProxyAdmin_ != address(0), "Bootstrap: custom proxy admin should not be empty");

exocoreSpawnTime = spawnTime_;
offsetDuration = offsetDuration_;
exocoreValidatorSetAddress = exocoreValidatorSetAddress_;

_addWhitelistTokens(whitelistTokens_);

Expand Down
25 changes: 6 additions & 19 deletions src/core/ClientChainGateway.sol
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,10 @@ contract ClientChainGateway is

// initialization happens from another contract so it must be external.
// reinitializer(2) is used so that the ownable and oappcore functions can be called again.
function initialize(address payable exocoreValidatorSetAddress_) external reinitializer(2) {
function initialize(address owner_) external reinitializer(2) {
_clearBootstrapData();

require(
exocoreValidatorSetAddress_ != address(0),
"ClientChainGateway: exocore validator set address should not be empty"
);

exocoreValidatorSetAddress = exocoreValidatorSetAddress_;
require(owner_ != address(0), "ClientChainGateway: contract owner should not be empty");

_registeredResponseHooks[Action.REQUEST_DEPOSIT] = this.afterReceiveDepositResponse.selector;
_registeredResponseHooks[Action.REQUEST_WITHDRAW_PRINCIPAL_FROM_EXOCORE] =
Expand All @@ -83,8 +78,8 @@ contract ClientChainGateway is

bootstrapped = true;

_transferOwnership(exocoreValidatorSetAddress);
__OAppCore_init_unchained(exocoreValidatorSetAddress);
_transferOwnership(owner_);
__OAppCore_init_unchained(owner_);
__Pausable_init_unchained();
__ReentrancyGuard_init_unchained();
}
Expand All @@ -105,19 +100,11 @@ contract ClientChainGateway is
delete registeredOperators;
}

function pause() external {
require(
msg.sender == exocoreValidatorSetAddress,
"ClientChainGateway: caller is not Exocore validator set aggregated address"
);
function pause() external onlyOwner {
_pause();
}

function unpause() external {
require(
msg.sender == exocoreValidatorSetAddress,
"ClientChainGateway: caller is not Exocore validator set aggregated address"
);
function unpause() external onlyOwner {
_unpause();
}

Expand Down
27 changes: 7 additions & 20 deletions src/core/ExocoreGateway.sol
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,12 @@ contract ExocoreGateway is

receive() external payable {}

function initialize(address payable exocoreValidatorSetAddress_) external initializer {
require(
exocoreValidatorSetAddress_ != address(0),
"ExocoreGateway: validator set address cannot be the zero address"
);

exocoreValidatorSetAddress = exocoreValidatorSetAddress_;
function initialize(address owner_) external initializer {
require(owner_ != address(0), "ExocoreGateway: owner address cannot be the zero address");

_initializeWhitelistFunctionSelectors();
_transferOwnership(exocoreValidatorSetAddress);
__OAppCore_init_unchained(exocoreValidatorSetAddress);
_transferOwnership(owner_);
__OAppCore_init_unchained(owner_);
__Pausable_init_unchained();
__ReentrancyGuard_init_unchained();
}
Expand All @@ -76,19 +71,11 @@ contract ExocoreGateway is
this.requestDepositThenDelegateTo.selector;
}

function pause() external {
require(
msg.sender == exocoreValidatorSetAddress,
"ExocoreGateway: caller is not Exocore validator set aggregated address"
);
function pause() external onlyOwner {
_pause();
}

function unpause() external {
require(
msg.sender == exocoreValidatorSetAddress,
"ExocoreGateway: caller is not Exocore validator set aggregated address"
);
function unpause() external onlyOwner {
_unpause();
}

Expand Down Expand Up @@ -444,7 +431,7 @@ contract ExocoreGateway is
MessagingFee memory fee = _quote(srcChainId, payload, options, false);

MessagingReceipt memory receipt =
_lzSend(srcChainId, payload, options, MessagingFee(fee.nativeFee, 0), exocoreValidatorSetAddress, payByApp);
_lzSend(srcChainId, payload, options, MessagingFee(fee.nativeFee, 0), msg.sender, payByApp);
emit MessageSent(act, receipt.guid, receipt.nonce, receipt.fee.nativeFee);
}

Expand Down
2 changes: 0 additions & 2 deletions src/storage/GatewayStorage.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ contract GatewayStorage {
}

mapping(Action => bytes4) internal _whiteListFunctionSelectors;
address payable public exocoreValidatorSetAddress;

mapping(uint32 eid => mapping(bytes32 sender => uint64 nonce)) public inboundNonce;

event MessageSent(Action indexed act, bytes32 packetId, uint64 nonce, uint256 nativeFee);
Expand Down
79 changes: 7 additions & 72 deletions test/foundry/unit/Bootstrap.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -107,14 +107,7 @@ contract BootstrapTest is Test {
address(proxyAdmin),
abi.encodeCall(
bootstrap.initialize,
(
deployer,
spawnTime,
offsetDuration,
payable(exocoreValidatorSet),
whitelistTokens,
address(proxyAdmin)
)
(deployer, spawnTime, offsetDuration, whitelistTokens, address(proxyAdmin))
)
)
)
Expand Down Expand Up @@ -958,14 +951,7 @@ contract BootstrapTest is Test {
address(proxyAdmin),
abi.encodeCall(
bootstrap.initialize,
(
address(0x0),
spawnTime,
offsetDuration,
payable(exocoreValidatorSet),
whitelistTokens,
address(proxyAdmin)
)
(address(0x0), spawnTime, offsetDuration, whitelistTokens, address(proxyAdmin))
)
)
)
Expand All @@ -988,14 +974,7 @@ contract BootstrapTest is Test {
address(proxyAdmin),
abi.encodeCall(
bootstrap.initialize,
(
deployer,
block.timestamp - 10,
offsetDuration,
payable(exocoreValidatorSet),
whitelistTokens,
address(proxyAdmin)
)
(deployer, block.timestamp - 10, offsetDuration, whitelistTokens, address(proxyAdmin))
)
)
)
Expand All @@ -1016,8 +995,7 @@ contract BootstrapTest is Test {
address(bootstrapLogic),
address(proxyAdmin),
abi.encodeCall(
bootstrap.initialize,
(deployer, spawnTime, 0, payable(exocoreValidatorSet), whitelistTokens, address(proxyAdmin))
bootstrap.initialize, (deployer, spawnTime, 0, whitelistTokens, address(proxyAdmin))
)
)
)
Expand All @@ -1038,10 +1016,7 @@ contract BootstrapTest is Test {
new TransparentUpgradeableProxy(
address(bootstrapLogic),
address(proxyAdmin),
abi.encodeCall(
bootstrap.initialize,
(deployer, 21, 22, payable(exocoreValidatorSet), whitelistTokens, address(proxyAdmin))
)
abi.encodeCall(bootstrap.initialize, (deployer, 21, 22, whitelistTokens, address(proxyAdmin)))
)
)
)
Expand All @@ -1061,39 +1036,7 @@ contract BootstrapTest is Test {
new TransparentUpgradeableProxy(
address(bootstrapLogic),
address(proxyAdmin),
abi.encodeCall(
bootstrap.initialize,
(deployer, 21, 9, payable(exocoreValidatorSet), whitelistTokens, address(proxyAdmin))
)
)
)
)
);
}

function test15_Initialize_ExocoreValSetZero() public {
vm.startPrank(deployer);
Bootstrap bootstrapLogic = new Bootstrap(
address(clientChainLzEndpoint), exocoreChainId, address(vaultBeacon), address(beaconProxyBytecode)
);
vm.expectRevert("Bootstrap: exocore validator set address should not be empty");
Bootstrap(
payable(
address(
new TransparentUpgradeableProxy(
address(bootstrapLogic),
address(proxyAdmin),
abi.encodeCall(
bootstrap.initialize,
(
deployer,
spawnTime,
offsetDuration,
payable(address(0)),
whitelistTokens,
address(proxyAdmin)
)
)
abi.encodeCall(bootstrap.initialize, (deployer, 21, 9, whitelistTokens, address(proxyAdmin)))
)
)
)
Expand All @@ -1113,15 +1056,7 @@ contract BootstrapTest is Test {
address(bootstrapLogic),
address(proxyAdmin),
abi.encodeCall(
bootstrap.initialize,
(
deployer,
spawnTime,
offsetDuration,
payable(exocoreValidatorSet),
whitelistTokens,
address(0x0)
)
bootstrap.initialize, (deployer, spawnTime, offsetDuration, whitelistTokens, address(0x0))
)
)
)
Expand Down
6 changes: 1 addition & 5 deletions test/foundry/unit/ClientChainGateway.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ contract Pausable is SetUp {
}

function test_RevertWhen_UnauthorizedPauser() public {
vm.expectRevert("ClientChainGateway: caller is not Exocore validator set aggregated address");
vm.expectRevert("Ownable: caller is not the owner");
vm.startPrank(deployer.addr);
clientGateway.pause();
}
Expand Down Expand Up @@ -260,10 +260,6 @@ contract Initialize is SetUp {
assertEq(address(clientGateway.EXO_CAPSULE_BEACON()), address(capsuleBeacon));
}

function test_ExocoreValidatoSetAddressInitialized() public {
assertEq(clientGateway.exocoreValidatorSetAddress(), exocoreValidatorSet.addr);
}

function test_OwnerInitialized() public {
assertEq(clientGateway.owner(), exocoreValidatorSet.addr);
}
Expand Down
2 changes: 1 addition & 1 deletion test/foundry/unit/ExocoreGateway.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ contract Pausable is SetUp {
}

function test_RevertWhen_UnauthorizedPauser() public {
vm.expectRevert(bytes("ExocoreGateway: caller is not Exocore validator set aggregated address"));
vm.expectRevert(bytes("Ownable: caller is not the owner"));
vm.startPrank(deployer.addr);
exocoreGateway.pause();
}
Expand Down
27 changes: 10 additions & 17 deletions test/mocks/ExocoreGatewayMock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,12 @@ contract ExocoreGatewayMock is

receive() external payable {}

function initialize(address payable exocoreValidatorSetAddress_) external initializer {
require(exocoreValidatorSetAddress_ != address(0), "ExocoreGateway: invalid exocore validator set address");

exocoreValidatorSetAddress = exocoreValidatorSetAddress_;
function initialize(address owner_) external initializer {
require(owner_ != address(0), "ExocoreGateway: owner can not be zero address");

_initializeWhitelistFunctionSelectors();
_transferOwnership(exocoreValidatorSetAddress);
__OAppCore_init_unchained(exocoreValidatorSetAddress);
_transferOwnership(owner_);
__OAppCore_init_unchained(owner_);
__Pausable_init_unchained();
}

Expand All @@ -96,19 +94,11 @@ contract ExocoreGatewayMock is
_whiteListFunctionSelectors[Action.REQUEST_WITHDRAW_REWARD_FROM_EXOCORE] = this.requestWithdrawReward.selector;
}

function pause() external {
require(
msg.sender == exocoreValidatorSetAddress,
"ExocoreGateway: caller is not Exocore validator set aggregated address"
);
function pause() external onlyOwner {
_pause();
}

function unpause() external {
require(
msg.sender == exocoreValidatorSetAddress,
"ExocoreGateway: caller is not Exocore validator set aggregated address"
);
function unpause() external onlyOwner {
_unpause();
}

Expand Down Expand Up @@ -189,6 +179,9 @@ contract ExocoreGatewayMock is
super.setPeer(clientChainId, clientChainGateway);
}

// Though this function would call precompiled contract, all precompiled contracts belong to Exocore
// and we could make sure its implementation does not have dangerous behavior like reentrancy.
// slither-disable-next-line reentrancy-no-eth
function addWhitelistTokens(
uint32 clientChainId,
bytes32[] calldata tokens,
Expand Down Expand Up @@ -461,7 +454,7 @@ contract ExocoreGatewayMock is
MessagingFee memory fee = _quote(srcChainId, payload, options, false);

MessagingReceipt memory receipt =
_lzSend(srcChainId, payload, options, MessagingFee(fee.nativeFee, 0), exocoreValidatorSetAddress, payByApp);
_lzSend(srcChainId, payload, options, MessagingFee(fee.nativeFee, 0), msg.sender, payByApp);
emit MessageSent(act, receipt.guid, receipt.nonce, receipt.fee.nativeFee);
}

Expand Down
Loading