Skip to content

Commit

Permalink
fix: mark capsule owner as payable
Browse files Browse the repository at this point in the history
  • Loading branch information
adu-web3 committed Aug 29, 2024
1 parent 359267d commit edd35c9
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 11 deletions.
6 changes: 3 additions & 3 deletions src/core/ExoCapsule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ contract ExoCapsule is ReentrancyGuardUpgradeable, ExoCapsuleStorage, IExoCapsul
}

/// @inheritdoc IExoCapsule
function initialize(address gateway_, address capsuleOwner_, address beaconOracle_) external initializer {
function initialize(address gateway_, address payable capsuleOwner_, address beaconOracle_) external initializer {
require(gateway_ != address(0), "ExoCapsule: gateway address can not be empty");
require(capsuleOwner_ != address(0), "ExoCapsule: capsule owner address can not be empty");
require(beaconOracle_ != address(0), "ExoCapsule: beacon chain oracle address should not be empty");
Expand Down Expand Up @@ -351,10 +351,10 @@ contract ExoCapsule is ReentrancyGuardUpgradeable, ExoCapsuleStorage, IExoCapsul
}

/// @dev Sends @param amountWei of ETH to the @param recipient.
/// @param recipient The address of the recipient.
/// @param recipient The address of the payable recipient.
/// @param amountWei The amount of ETH to send, in wei.
// slither-disable-next-line arbitrary-send-eth
function _sendETH(address recipient, uint256 amountWei) internal nonReentrant {
function _sendETH(address payable recipient, uint256 amountWei) internal nonReentrant {
(bool sent,) = recipient.call{value: amountWei}("");
if (!sent) {
revert WithdrawalFailure(capsuleOwner, recipient, amountWei);
Expand Down
3 changes: 2 additions & 1 deletion src/core/NativeRestakingController.sol
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ abstract contract NativeRestakingController is
}

/// @notice Creates a new ExoCapsule contract for the message sender.
/// @notice The message sender must be payable
/// @return The address of the newly created ExoCapsule contract.
// The bytecode returned by `BEACON_PROXY_BYTECODE` and `EXO_CAPSULE_BEACON` address are actually fixed size of byte
// array, so it would not cause collision for encodePacked
Expand All @@ -82,7 +83,7 @@ abstract contract NativeRestakingController is

// we follow check-effects-interactions pattern to write state before external call
ownerToCapsule[msg.sender] = capsule;
capsule.initialize(address(this), msg.sender, BEACON_ORACLE_ADDRESS);
capsule.initialize(address(this), payable(msg.sender), BEACON_ORACLE_ADDRESS);

emit CapsuleCreated(msg.sender, address(capsule));

Expand Down
4 changes: 2 additions & 2 deletions src/interfaces/IExoCapsule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ interface IExoCapsule {

/// @notice Initializes the ExoCapsule contract with the given parameters.
/// @param gateway The address of the ClientChainGateway contract.
/// @param capsuleOwner The address of the ExoCapsule owner.
/// @param capsuleOwner The payable address of the ExoCapsule owner.
/// @param beaconOracle The address of the BeaconOracle contract.
function initialize(address gateway, address capsuleOwner, address beaconOracle) external;
function initialize(address gateway, address payable capsuleOwner, address beaconOracle) external;

/// @notice Verifies the deposit proof and returns the amount of deposit.
/// @param validatorContainer The validator container.
Expand Down
2 changes: 1 addition & 1 deletion src/storage/ExoCapsuleStorage.sol
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ contract ExoCapsuleStorage {
uint256 public nonBeaconChainETHBalance;

/// @notice The owner of the ExoCapsule.
address public capsuleOwner;
address payable public capsuleOwner;

/// @notice The address of the NativeRestakingController contract.
INativeRestakingController public gateway;
Expand Down
2 changes: 1 addition & 1 deletion test/foundry/DepositWithdrawPrinciple.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ contract DepositWithdrawPrincipalTest is ExocoreDeployer {
assertEq(address(clientGateway.ownerToCapsule(depositor.addr)), address(capsule));

/// initialize replaced capsule
capsule.initialize(address(clientGateway), depositor.addr, address(beaconOracle));
capsule.initialize(address(clientGateway), payable(depositor.addr), address(beaconOracle));
}

function _testNativeWithdraw(Player memory withdrawer, Player memory relayer, uint256 lastlyUpdatedPrincipalBalance)
Expand Down
6 changes: 3 additions & 3 deletions test/foundry/unit/ExoCapsule.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ contract DepositSetup is Test {

ExoCapsule capsule;
IBeaconChainOracle beaconOracle;
address capsuleOwner;
address payable capsuleOwner;

uint256 constant BEACON_CHAIN_GENESIS_TIME = 1_606_824_023;
/// @notice The number of slots each epoch in the beacon chain
Expand Down Expand Up @@ -70,7 +70,7 @@ contract DepositSetup is Test {
beaconOracle = IBeaconChainOracle(address(0x123));
vm.etch(address(beaconOracle), bytes("aabb"));

capsuleOwner = address(0x125);
capsuleOwner = payable(address(0x125));

ExoCapsule phantomCapsule = new ExoCapsule();

Expand Down Expand Up @@ -284,7 +284,7 @@ contract VerifyDepositProof is DepositSetup {
vm.store(address(anotherCapsule), gatewaySlot, bytes32(uint256(uint160(address(this)))));

bytes32 ownerSlot = bytes32(stdstore.target(address(anotherCapsule)).sig("capsuleOwner()").find());
vm.store(address(anotherCapsule), ownerSlot, bytes32(uint256(uint160(capsuleOwner))));
vm.store(address(anotherCapsule), ownerSlot, bytes32(uint256(uint160(address(capsuleOwner)))));

bytes32 beaconOraclerSlot = bytes32(stdstore.target(address(anotherCapsule)).sig("beaconOracle()").find());
vm.store(address(anotherCapsule), beaconOraclerSlot, bytes32(uint256(uint160(address(beaconOracle)))));
Expand Down

0 comments on commit edd35c9

Please sign in to comment.