From de35d2d0968c35dd806f455c84bd497150f80739 Mon Sep 17 00:00:00 2001 From: Ed Mazurek Date: Wed, 10 Apr 2024 10:00:17 -0400 Subject: [PATCH] change `Deposit.balance` type to uint96 for storage packing --- src/UniStaker.sol | 32 +- test/UniStaker.integration.t.sol | 10 +- test/UniStaker.t.sol | 511 ++++++++++++++--------------- test/helpers/IntegrationTest.sol | 4 +- test/helpers/UniStaker.handler.sol | 16 +- 5 files changed, 284 insertions(+), 289 deletions(-) diff --git a/src/UniStaker.sol b/src/UniStaker.sol index 4cd6690..026aa26 100644 --- a/src/UniStaker.sol +++ b/src/UniStaker.sol @@ -95,7 +95,7 @@ contract UniStaker is INotifiableRewardReceiver, Multicall, EIP712, Nonces { /// @param delegatee The governance delegate who receives the voting weight for this deposit. /// @param beneficiary The address that accrues staking rewards earned by this deposit. struct Deposit { - uint256 balance; + uint96 balance; address owner; address delegatee; address beneficiary; @@ -103,11 +103,11 @@ contract UniStaker is INotifiableRewardReceiver, Multicall, EIP712, Nonces { /// @notice Type hash used when encoding data for `stakeOnBehalf` calls. bytes32 public constant STAKE_TYPEHASH = keccak256( - "Stake(uint256 amount,address delegatee,address beneficiary,address depositor,uint256 nonce,uint256 deadline)" + "Stake(uint96 amount,address delegatee,address beneficiary,address depositor,uint256 nonce,uint256 deadline)" ); /// @notice Type hash used when encoding data for `stakeMoreOnBehalf` calls. bytes32 public constant STAKE_MORE_TYPEHASH = keccak256( - "StakeMore(uint256 depositId,uint256 amount,address depositor,uint256 nonce,uint256 deadline)" + "StakeMore(uint256 depositId,uint96 amount,address depositor,uint256 nonce,uint256 deadline)" ); /// @notice Type hash used when encoding data for `alterDelegateeOnBehalf` calls. bytes32 public constant ALTER_DELEGATEE_TYPEHASH = keccak256( @@ -119,7 +119,7 @@ contract UniStaker is INotifiableRewardReceiver, Multicall, EIP712, Nonces { ); /// @notice Type hash used when encoding data for `withdrawOnBehalf` calls. bytes32 public constant WITHDRAW_TYPEHASH = keccak256( - "Withdraw(uint256 depositId,uint256 amount,address depositor,uint256 nonce,uint256 deadline)" + "Withdraw(uint256 depositId,uint96 amount,address depositor,uint256 nonce,uint256 deadline)" ); /// @notice Type hash used when encoding data for `claimRewardOnBehalf` calls. bytes32 public constant CLAIM_REWARD_TYPEHASH = @@ -259,7 +259,7 @@ contract UniStaker is INotifiableRewardReceiver, Multicall, EIP712, Nonces { /// @return _depositId The unique identifier for this deposit. /// @dev The delegatee may not be the zero address. The deposit will be owned by the message /// sender, and the beneficiary will also be the message sender. - function stake(uint256 _amount, address _delegatee) + function stake(uint96 _amount, address _delegatee) external returns (DepositIdentifier _depositId) { @@ -274,7 +274,7 @@ contract UniStaker is INotifiableRewardReceiver, Multicall, EIP712, Nonces { /// @return _depositId Unique identifier for this deposit. /// @dev Neither the delegatee nor the beneficiary may be the zero address. The deposit will be /// owned by the message sender. - function stake(uint256 _amount, address _delegatee, address _beneficiary) + function stake(uint96 _amount, address _delegatee, address _beneficiary) external returns (DepositIdentifier _depositId) { @@ -296,7 +296,7 @@ contract UniStaker is INotifiableRewardReceiver, Multicall, EIP712, Nonces { /// @dev Neither the delegatee nor the beneficiary may be the zero address. The deposit will be /// owned by the message sender. function permitAndStake( - uint256 _amount, + uint96 _amount, address _delegatee, address _beneficiary, uint256 _deadline, @@ -320,7 +320,7 @@ contract UniStaker is INotifiableRewardReceiver, Multicall, EIP712, Nonces { /// @return _depositId Unique identifier for this deposit. /// @dev Neither the delegatee nor the beneficiary may be the zero address. function stakeOnBehalf( - uint256 _amount, + uint96 _amount, address _delegatee, address _beneficiary, address _depositor, @@ -354,7 +354,7 @@ contract UniStaker is INotifiableRewardReceiver, Multicall, EIP712, Nonces { /// @param _depositId Unique identifier of the deposit to which stake will be added. /// @param _amount Quantity of stake to be added. /// @dev The message sender must be the owner of the deposit. - function stakeMore(DepositIdentifier _depositId, uint256 _amount) external { + function stakeMore(DepositIdentifier _depositId, uint96 _amount) external { Deposit storage deposit = deposits[_depositId]; _revertIfNotDepositOwner(deposit, msg.sender); _stakeMore(deposit, _depositId, _amount); @@ -374,7 +374,7 @@ contract UniStaker is INotifiableRewardReceiver, Multicall, EIP712, Nonces { /// @dev The message sender must be the owner of the deposit. function permitAndStakeMore( DepositIdentifier _depositId, - uint256 _amount, + uint96 _amount, uint256 _deadline, uint8 _v, bytes32 _r, @@ -397,7 +397,7 @@ contract UniStaker is INotifiableRewardReceiver, Multicall, EIP712, Nonces { /// @param _signature Signature of the user authorizing this stake. function stakeMoreOnBehalf( DepositIdentifier _depositId, - uint256 _amount, + uint96 _amount, address _depositor, uint256 _deadline, bytes memory _signature @@ -525,7 +525,7 @@ contract UniStaker is INotifiableRewardReceiver, Multicall, EIP712, Nonces { /// @param _amount Quantity of staked token to withdraw. /// @dev The message sender must be the owner of the deposit. Stake is withdrawn to the message /// sender's account. - function withdraw(DepositIdentifier _depositId, uint256 _amount) external { + function withdraw(DepositIdentifier _depositId, uint96 _amount) external { Deposit storage deposit = deposits[_depositId]; _revertIfNotDepositOwner(deposit, msg.sender); _withdraw(deposit, _depositId, _amount); @@ -541,7 +541,7 @@ contract UniStaker is INotifiableRewardReceiver, Multicall, EIP712, Nonces { /// @dev Stake is withdrawn to the deposit owner's account. function withdrawOnBehalf( DepositIdentifier _depositId, - uint256 _amount, + uint96 _amount, address _depositor, uint256 _deadline, bytes memory _signature @@ -694,7 +694,7 @@ contract UniStaker is INotifiableRewardReceiver, Multicall, EIP712, Nonces { /// @notice Internal convenience methods which performs the staking operations. /// @dev This method must only be called after proper authorization has been completed. /// @dev See public stake methods for additional documentation. - function _stake(address _depositor, uint256 _amount, address _delegatee, address _beneficiary) + function _stake(address _depositor, uint96 _amount, address _delegatee, address _beneficiary) internal returns (DepositIdentifier _depositId) { @@ -725,7 +725,7 @@ contract UniStaker is INotifiableRewardReceiver, Multicall, EIP712, Nonces { /// @notice Internal convenience method which adds more stake to an existing deposit. /// @dev This method must only be called after proper authorization has been completed. /// @dev See public stakeMore methods for additional documentation. - function _stakeMore(Deposit storage deposit, DepositIdentifier _depositId, uint256 _amount) + function _stakeMore(Deposit storage deposit, DepositIdentifier _depositId, uint96 _amount) internal { _checkpointGlobalReward(); @@ -779,7 +779,7 @@ contract UniStaker is INotifiableRewardReceiver, Multicall, EIP712, Nonces { /// @notice Internal convenience method which withdraws the stake from an existing deposit. /// @dev This method must only be called after proper authorization has been completed. /// @dev See public withdraw methods for additional documentation. - function _withdraw(Deposit storage deposit, DepositIdentifier _depositId, uint256 _amount) + function _withdraw(Deposit storage deposit, DepositIdentifier _depositId, uint96 _amount) internal { _checkpointGlobalReward(); diff --git a/test/UniStaker.integration.t.sol b/test/UniStaker.integration.t.sol index 73f7b6f..8c26b99 100644 --- a/test/UniStaker.integration.t.sol +++ b/test/UniStaker.integration.t.sol @@ -241,7 +241,7 @@ contract Propose is IntegrationTest { contract Stake is IntegrationTest, PercentAssertions { function testForkFuzz_CorrectlyStakeAndEarnRewardsAfterFullDuration( address _depositor, - uint256 _amount, + uint96 _amount, address _delegatee, uint128 _swapAmount ) public { @@ -259,7 +259,7 @@ contract Stake is IntegrationTest, PercentAssertions { function testForkFuzz_CorrectlyStakeAndClaimRewardsAfterFullDuration( address _depositor, - uint256 _amount, + uint96 _amount, address _delegatee, uint128 _swapAmount ) public { @@ -287,7 +287,7 @@ contract Stake is IntegrationTest, PercentAssertions { function testForkFuzz_CorrectlyStakeAndEarnRewardsAfterPartialDuration( address _depositor, - uint256 _amount, + uint96 _amount, address _delegatee, uint128 _swapAmount, uint256 _percentDuration @@ -310,8 +310,8 @@ contract Stake is IntegrationTest, PercentAssertions { function testForkFuzz_CorrectlyStakeMoreAndEarnRewardsAfterFullDuration( address _depositor, - uint256 _initialAmount, - uint256 _additionalAmount, + uint96 _initialAmount, + uint96 _additionalAmount, address _delegatee, uint128 _swapAmount, uint256 _percentDuration diff --git a/test/UniStaker.t.sol b/test/UniStaker.t.sol index 9d13901..fd04353 100644 --- a/test/UniStaker.t.sol +++ b/test/UniStaker.t.sol @@ -61,21 +61,21 @@ contract UniStakerTest is Test, PercentAssertions { vm.warp(block.timestamp + _seconds); } - function _boundMintAmount(uint256 _amount) internal pure returns (uint256) { - return bound(_amount, 0, 100_000_000_000e18); + function _boundMintAmount(uint96 _amount) internal pure returns (uint96) { + return uint96(bound(_amount, 0, 100_000_000e18)); } - function _mintGovToken(address _to, uint256 _amount) internal { + function _mintGovToken(address _to, uint96 _amount) internal { vm.assume(_to != address(0)); govToken.mint(_to, _amount); } - function _boundToRealisticStake(uint256 _stakeAmount) + function _boundToRealisticStake(uint96 _stakeAmount) public pure - returns (uint256 _boundedStakeAmount) + returns (uint96 _boundedStakeAmount) { - _boundedStakeAmount = bound(_stakeAmount, 0.1e18, 25_000_000e18); + _boundedStakeAmount = uint96(bound(_stakeAmount, 0.1e18, 25_000_000e18)); } // Remember each depositor and surrogate (as they're deployed) and ensure that there is @@ -92,7 +92,7 @@ contract UniStakerTest is Test, PercentAssertions { ); } - function _stake(address _depositor, uint256 _amount, address _delegatee) + function _stake(address _depositor, uint96 _amount, address _delegatee) internal returns (UniStaker.DepositIdentifier _depositId) { @@ -107,7 +107,7 @@ contract UniStakerTest is Test, PercentAssertions { _assumeSafeDepositorAndSurrogate(_depositor, _delegatee); } - function _stake(address _depositor, uint256 _amount, address _delegatee, address _beneficiary) + function _stake(address _depositor, uint96 _amount, address _delegatee, address _beneficiary) internal returns (UniStaker.DepositIdentifier _depositId) { @@ -127,7 +127,7 @@ contract UniStakerTest is Test, PercentAssertions { view returns (UniStaker.Deposit memory) { - (uint256 _balance, address _owner, address _delegatee, address _beneficiary) = + (uint96 _balance, address _owner, address _delegatee, address _beneficiary) = uniStaker.deposits(_depositId); return UniStaker.Deposit({ balance: _balance, @@ -137,9 +137,9 @@ contract UniStakerTest is Test, PercentAssertions { }); } - function _boundMintAndStake(address _depositor, uint256 _amount, address _delegatee) + function _boundMintAndStake(address _depositor, uint96 _amount, address _delegatee) internal - returns (uint256 _boundedAmount, UniStaker.DepositIdentifier _depositId) + returns (uint96 _boundedAmount, UniStaker.DepositIdentifier _depositId) { _boundedAmount = _boundMintAmount(_amount); _mintGovToken(_depositor, _boundedAmount); @@ -148,10 +148,10 @@ contract UniStakerTest is Test, PercentAssertions { function _boundMintAndStake( address _depositor, - uint256 _amount, + uint96 _amount, address _delegatee, address _beneficiary - ) internal returns (uint256 _boundedAmount, UniStaker.DepositIdentifier _depositId) { + ) internal returns (uint96 _boundedAmount, UniStaker.DepositIdentifier _depositId) { _boundedAmount = _boundMintAmount(_amount); _mintGovToken(_depositor, _boundedAmount); _depositId = _stake(_depositor, _boundedAmount, _delegatee, _beneficiary); @@ -212,10 +212,10 @@ contract Constructor is UniStakerTest { contract Stake is UniStakerTest { function testFuzz_DeploysAndTransfersTokensToANewSurrogateWhenAnAccountStakes( address _depositor, - uint256 _amount, + uint96 _amount, address _delegatee ) public { - _amount = bound(_amount, 1, type(uint224).max); + _amount = uint96(bound(_amount, 1, type(uint96).max)); _mintGovToken(_depositor, _amount); _stake(_depositor, _amount, _delegatee); @@ -228,10 +228,10 @@ contract Stake is UniStakerTest { function testFuzz_EmitsAStakingDepositEventWhenStakingWithoutASpecifiedBeneficiary( address _depositor, - uint256 _amount, + uint96 _amount, address _delegatee ) public { - _amount = bound(_amount, 1, type(uint224).max); + _amount = uint96(bound(_amount, 1, type(uint96).max)); _mintGovToken(_depositor, _amount); UniStaker.DepositIdentifier depositId = uniStaker.exposed_useDepositId(); @@ -253,10 +253,10 @@ contract Stake is UniStakerTest { function testFuzz_EmitsABeneficiaryAlteredEventWhenStakingWithoutASpecifiedBeneficiary( address _depositor, - uint256 _amount, + uint96 _amount, address _delegatee ) public { - _amount = bound(_amount, 1, type(uint224).max); + _amount = uint96(bound(_amount, 1, type(uint96).max)); _mintGovToken(_depositor, _amount); UniStaker.DepositIdentifier depositId = uniStaker.exposed_useDepositId(); @@ -277,10 +277,10 @@ contract Stake is UniStakerTest { function testFuzz_EmitsADelegateeAlteredEventWhenStakingWithoutASpecifiedBeneficiary( address _depositor, - uint256 _amount, + uint96 _amount, address _delegatee ) public { - _amount = bound(_amount, 1, type(uint224).max); + _amount = uint96(bound(_amount, 1, type(uint96).max)); _mintGovToken(_depositor, _amount); UniStaker.DepositIdentifier depositId = uniStaker.exposed_useDepositId(); @@ -301,11 +301,11 @@ contract Stake is UniStakerTest { function testFuzz_EmitsAStakingDepositEventWhenStakingWithASpecifiedBeneficiary( address _depositor, - uint256 _amount, + uint96 _amount, address _delegatee, address _beneficiary ) public { - _amount = bound(_amount, 1, type(uint224).max); + _amount = uint96(bound(_amount, 1, type(uint96).max)); _mintGovToken(_depositor, _amount); UniStaker.DepositIdentifier depositId = uniStaker.exposed_useDepositId(); @@ -327,11 +327,11 @@ contract Stake is UniStakerTest { function testFuzz_EmitsABeneficiaryAlteredEventWhenStakingWithASpecifiedBeneficiary( address _depositor, - uint256 _amount, + uint96 _amount, address _delegatee, address _beneficiary ) public { - _amount = bound(_amount, 1, type(uint224).max); + _amount = uint96(bound(_amount, 1, type(uint96).max)); _mintGovToken(_depositor, _amount); UniStaker.DepositIdentifier depositId = uniStaker.exposed_useDepositId(); @@ -352,11 +352,11 @@ contract Stake is UniStakerTest { function testFuzz_EmitsADelegateeAlteredEventWhenStakingWithASpecifiedBeneficiary( address _depositor, - uint256 _amount, + uint96 _amount, address _delegatee, address _beneficiary ) public { - _amount = bound(_amount, 1, type(uint224).max); + _amount = uint96(bound(_amount, 1, type(uint96).max)); _mintGovToken(_depositor, _amount); UniStaker.DepositIdentifier depositId = uniStaker.exposed_useDepositId(); @@ -377,9 +377,9 @@ contract Stake is UniStakerTest { function testFuzz_TransfersToAnExistingSurrogateWhenStakedToTheSameDelegatee( address _depositor1, - uint256 _amount1, + uint96 _amount1, address _depositor2, - uint256 _amount2, + uint96 _amount2, address _delegatee ) public { _amount1 = _boundMintAmount(_amount1); @@ -405,9 +405,9 @@ contract Stake is UniStakerTest { function testFuzz_DeploysAndTransfersTokenToTwoSurrogatesWhenAccountsStakesToDifferentDelegatees( address _depositor1, - uint256 _amount1, + uint96 _amount1, address _depositor2, - uint256 _amount2, + uint96 _amount2, address _delegatee1, address _delegatee2 ) public { @@ -439,7 +439,7 @@ contract Stake is UniStakerTest { function testFuzz_UpdatesTheTotalStakedWhenAnAccountStakes( address _depositor, - uint256 _amount, + uint96 _amount, address _delegatee ) public { _amount = _boundMintAmount(_amount); @@ -452,9 +452,9 @@ contract Stake is UniStakerTest { function testFuzz_UpdatesTheTotalStakedWhenTwoAccountsStake( address _depositor1, - uint256 _amount1, + uint96 _amount1, address _depositor2, - uint256 _amount2, + uint96 _amount2, address _delegatee1, address _delegatee2 ) public { @@ -472,8 +472,8 @@ contract Stake is UniStakerTest { function testFuzz_UpdatesAnAccountsTotalStakedAccounting( address _depositor, - uint256 _amount1, - uint256 _amount2, + uint96 _amount1, + uint96 _amount2, address _delegatee1, address _delegatee2 ) public { @@ -492,9 +492,9 @@ contract Stake is UniStakerTest { function testFuzz_UpdatesDifferentAccountsTotalStakedAccountingIndependently( address _depositor1, - uint256 _amount1, + uint96 _amount1, address _depositor2, - uint256 _amount2, + uint96 _amount2, address _delegatee1, address _delegatee2 ) public { @@ -513,7 +513,7 @@ contract Stake is UniStakerTest { function testFuzz_TracksTheBalanceForASpecificDeposit( address _depositor, - uint256 _amount, + uint96 _amount, address _delegatee ) public { _amount = _boundMintAmount(_amount); @@ -528,8 +528,8 @@ contract Stake is UniStakerTest { function testFuzz_TracksTheBalanceForDifferentDepositsFromTheSameAccountIndependently( address _depositor, - uint256 _amount1, - uint256 _amount2, + uint96 _amount1, + uint96 _amount2, address _delegatee1, address _delegatee2 ) public { @@ -555,8 +555,8 @@ contract Stake is UniStakerTest { function testFuzz_TracksTheBalanceForDepositsFromDifferentAccountsIndependently( address _depositor1, address _depositor2, - uint256 _amount1, - uint256 _amount2, + uint96 _amount1, + uint96 _amount2, address _delegatee1, address _delegatee2 ) public { @@ -582,7 +582,7 @@ contract Stake is UniStakerTest { function testFuzz_AssignsEarningPowerToDepositorIfNoBeneficiaryIsSpecified( address _depositor, - uint256 _amount, + uint96 _amount, address _delegatee ) public { _amount = _boundMintAmount(_amount); @@ -597,7 +597,7 @@ contract Stake is UniStakerTest { function testFuzz_AssignsEarningPowerToTheBeneficiaryProvided( address _depositor, - uint256 _amount, + uint96 _amount, address _delegatee, address _beneficiary ) public { @@ -613,8 +613,8 @@ contract Stake is UniStakerTest { function testFuzz_AssignsEarningPowerToDifferentBeneficiariesForDifferentDepositsFromTheSameDepositor( address _depositor, - uint256 _amount1, - uint256 _amount2, + uint96 _amount1, + uint96 _amount2, address _delegatee, address _beneficiary1, address _beneficiary2 @@ -642,8 +642,8 @@ contract Stake is UniStakerTest { function testFuzz_AssignsEarningPowerToTheSameBeneficiarySpecifiedByTwoDifferentDepositors( address _depositor1, address _depositor2, - uint256 _amount1, - uint256 _amount2, + uint96 _amount1, + uint96 _amount2, address _delegatee, address _beneficiary ) public { @@ -669,7 +669,7 @@ contract Stake is UniStakerTest { function test_NeverReusesADepositIdentifier() public { address _depositor = address(0xdeadbeef); - uint256 _amount = 116; + uint96 _amount = 116; address _delegatee = address(0xaceface); UniStaker.DepositIdentifier _depositId; @@ -690,7 +690,7 @@ contract Stake is UniStakerTest { // that the DepositIdentifier is never reused. for (uint256 _i; _i < 5000; _i++) { // Perform the stake and save the deposit identifier - _amount = _bound(_amount, 0, 100_000_000_000e18); + _amount = uint96(bound(_amount, 0, 100_000_000_000e18)); _mintGovToken(_depositor, _amount); _depositId = _stake(_depositor, _amount, _delegatee); @@ -701,12 +701,12 @@ contract Stake is UniStakerTest { // Assign new inputs for the next deposit by hashing the last inputs _depositor = address(uint160(uint256(keccak256(abi.encode(_depositor))))); - _amount = uint256(keccak256(abi.encode(_amount))); + _amount = uint96(uint256(keccak256(abi.encode(_amount)))); _delegatee = address(uint160(uint256(keccak256(abi.encode(_delegatee))))); } } - function testFuzz_RevertIf_DelegateeIsTheZeroAddress(address _depositor, uint256 _amount) public { + function testFuzz_RevertIf_DelegateeIsTheZeroAddress(address _depositor, uint96 _amount) public { _amount = _boundMintAmount(_amount); _mintGovToken(_depositor, _amount); govToken.approve(address(uniStaker), _amount); @@ -718,7 +718,7 @@ contract Stake is UniStakerTest { function testFuzz_RevertIf_BeneficiaryIsTheZeroAddress( address _depositor, - uint256 _amount, + uint96 _amount, address _delegatee ) public { vm.assume(_delegatee != address(0)); @@ -738,7 +738,7 @@ contract PermitAndStake is UniStakerTest { function testFuzz_PerformsTheApprovalByCallingPermitThenPerformsStake( uint256 _depositorPrivateKey, - uint256 _depositAmount, + uint96 _depositAmount, address _delegatee, address _beneficiary, uint256 _deadline, @@ -784,7 +784,7 @@ contract PermitAndStake is UniStakerTest { function testFuzz_RevertIf_ThePermitSignatureIsInvalid( address _notDepositor, uint256 _depositorPrivateKey, - uint256 _depositAmount, + uint96 _depositAmount, address _delegatee, address _beneficiary, uint256 _deadline @@ -826,7 +826,7 @@ contract StakeOnBehalf is UniStakerTest { function testFuzz_StakesOnBehalfOfAnotherAccount( uint256 _depositorPrivateKey, address _sender, - uint256 _depositAmount, + uint96 _depositAmount, address _delegatee, address _beneficiary, uint256 _currentNonce, @@ -878,7 +878,7 @@ contract StakeOnBehalf is UniStakerTest { function testFuzz_RevertIf_WrongNonceIsUsed( uint256 _depositorPrivateKey, address _sender, - uint256 _depositAmount, + uint96 _depositAmount, address _delegatee, address _beneficiary, uint256 _currentNonce, @@ -926,7 +926,7 @@ contract StakeOnBehalf is UniStakerTest { function testFuzz_RevertIf_DeadlineExpired( uint256 _depositorPrivateKey, address _sender, - uint256 _depositAmount, + uint96 _depositAmount, address _delegatee, address _beneficiary, uint256 _currentNonce, @@ -972,7 +972,7 @@ contract StakeOnBehalf is UniStakerTest { function testFuzz_RevertIf_InvalidSignatureIsPassed( uint256 _depositorPrivateKey, address _sender, - uint256 _depositAmount, + uint96 _depositAmount, address _delegatee, address _beneficiary, uint256 _currentNonce, @@ -1010,7 +1010,7 @@ contract StakeOnBehalf is UniStakerTest { // Here we use `_randomSeed` as an arbitrary source of randomness to replace a legit parameter // with an attack-like one. if (_randomSeed % 6 == 0) { - _depositAmount = uint256(keccak256(abi.encode(_depositAmount))); + _depositAmount = uint96(uint256(keccak256(abi.encode(_depositAmount)))); } else if (_randomSeed % 6 == 1) { _delegatee = address(uint160(uint256(keccak256(abi.encode(_delegatee))))); } else if (_randomSeed % 6 == 2) { @@ -1034,8 +1034,8 @@ contract StakeOnBehalf is UniStakerTest { contract StakeMore is UniStakerTest { function testFuzz_TransfersStakeToTheExistingSurrogate( address _depositor, - uint256 _depositAmount, - uint256 _addAmount, + uint96 _depositAmount, + uint96 _addAmount, address _delegatee, address _beneficiary ) public { @@ -1058,8 +1058,8 @@ contract StakeMore is UniStakerTest { function testFuzz_AddsToExistingBeneficiaryEarningPower( address _depositor, - uint256 _depositAmount, - uint256 _addAmount, + uint96 _depositAmount, + uint96 _addAmount, address _delegatee, address _beneficiary ) public { @@ -1080,8 +1080,8 @@ contract StakeMore is UniStakerTest { function testFuzz_AddsToTheTotalStaked( address _depositor, - uint256 _depositAmount, - uint256 _addAmount, + uint96 _depositAmount, + uint96 _addAmount, address _delegatee, address _beneficiary ) public { @@ -1102,8 +1102,8 @@ contract StakeMore is UniStakerTest { function testFuzz_AddsToDepositorsTotalStaked( address _depositor, - uint256 _depositAmount, - uint256 _addAmount, + uint96 _depositAmount, + uint96 _addAmount, address _delegatee, address _beneficiary ) public { @@ -1124,8 +1124,8 @@ contract StakeMore is UniStakerTest { function testFuzz_AddsToTheDepositBalance( address _depositor, - uint256 _depositAmount, - uint256 _addAmount, + uint96 _depositAmount, + uint96 _addAmount, address _delegatee, address _beneficiary ) public { @@ -1148,12 +1148,12 @@ contract StakeMore is UniStakerTest { function testFuzz_EmitsAnEventWhenStakingMore( address _depositor, - uint256 _depositAmount, - uint256 _addAmount, + uint96 _depositAmount, + uint96 _addAmount, address _delegatee, address _beneficiary ) public { - uint256 _totalAdditionalStake; + uint96 _totalAdditionalStake; UniStaker.DepositIdentifier _depositId; (_depositAmount, _depositId) = _boundMintAndStake(_depositor, _depositAmount, _delegatee, _beneficiary); @@ -1181,8 +1181,8 @@ contract StakeMore is UniStakerTest { function testFuzz_RevertIf_TheCallerIsNotTheDepositor( address _depositor, address _notDepositor, - uint256 _depositAmount, - uint256 _addAmount, + uint96 _depositAmount, + uint96 _addAmount, address _delegatee, address _beneficiary ) public { @@ -1210,7 +1210,7 @@ contract StakeMore is UniStakerTest { function testFuzz_RevertIf_TheDepositIdentifierIsInvalid( address _depositor, UniStaker.DepositIdentifier _depositId, - uint256 _addAmount + uint96 _addAmount ) public { vm.assume(_depositor != address(0)); _addAmount = _boundToRealisticStake(_addAmount); @@ -1233,8 +1233,8 @@ contract PermitAndStakeMore is UniStakerTest { function testFuzz_PerformsTheApprovalByCallingPermitThenPerformsStakeMore( uint256 _depositorPrivateKey, - uint256 _initialDepositAmount, - uint256 _stakeMoreAmount, + uint96 _initialDepositAmount, + uint96 _stakeMoreAmount, address _delegatee, address _beneficiary, uint256 _currentNonce, @@ -1288,8 +1288,8 @@ contract PermitAndStakeMore is UniStakerTest { function testFuzz_RevertIf_CallerIsNotTheDepositOwner( address _depositor, uint256 _notDepositorPrivateKey, - uint256 _initialDepositAmount, - uint256 _stakeMoreAmount, + uint96 _initialDepositAmount, + uint96 _stakeMoreAmount, address _delegatee, address _beneficiary, uint256 _deadline @@ -1335,7 +1335,7 @@ contract PermitAndStakeMore is UniStakerTest { } function testFuzz_RevertIf_ThePermitSignatureIsInvalid( - uint256 _initialDepositAmount, + uint96 _initialDepositAmount, address _delegatee, address _beneficiary ) public { @@ -1344,7 +1344,7 @@ contract PermitAndStakeMore is UniStakerTest { // We can't fuzz the these values because we need to pre-compute the invalid // recovered signer so we can expect it in the revert error message thrown (address _depositor, uint256 _depositorPrivateKey) = makeAddrAndKey("depositor"); - uint256 _stakeMoreAmount = 1578e18; + uint96 _stakeMoreAmount = 1578e18; uint256 _deadline = 1e18 days; uint256 _wrongNonce = 1; // If any of the values defined above are changed, the expected recovered address must also @@ -1388,8 +1388,8 @@ contract StakeMoreOnBehalf is UniStakerTest { function testFuzz_StakeMoreOnBehalfOfDepositor( uint256 _depositorPrivateKey, address _sender, - uint256 _initialDepositAmount, - uint256 _stakeMoreAmount, + uint96 _initialDepositAmount, + uint96 _stakeMoreAmount, address _delegatee, address _beneficiary, uint256 _currentNonce, @@ -1445,8 +1445,8 @@ contract StakeMoreOnBehalf is UniStakerTest { function testFuzz_RevertIf_WrongNonceIsUsed( uint256 _depositorPrivateKey, address _sender, - uint256 _initialDepositAmount, - uint256 _stakeMoreAmount, + uint96 _initialDepositAmount, + uint96 _stakeMoreAmount, address _delegatee, address _beneficiary, uint256 _currentNonce, @@ -1498,8 +1498,8 @@ contract StakeMoreOnBehalf is UniStakerTest { function testFuzz_RevertIf_DeadlineExpired( uint256 _depositorPrivateKey, address _sender, - uint256 _initialDepositAmount, - uint256 _stakeMoreAmount, + uint96 _initialDepositAmount, + uint96 _stakeMoreAmount, address _delegatee, address _beneficiary, uint256 _currentNonce, @@ -1550,8 +1550,8 @@ contract StakeMoreOnBehalf is UniStakerTest { address _sender, address _depositor, address _notDepositor, - uint256 _initialDepositAmount, - uint256 _stakeMoreAmount, + uint96 _initialDepositAmount, + uint96 _stakeMoreAmount, address _delegatee, address _beneficiary, uint256 _currentNonce, @@ -1584,8 +1584,8 @@ contract StakeMoreOnBehalf is UniStakerTest { function testFuzz_RevertIf_InvalidSignatureIsPassed( uint256 _depositorPrivateKey, address _sender, - uint256 _initialDepositAmount, - uint256 _stakeMoreAmount, + uint96 _initialDepositAmount, + uint96 _stakeMoreAmount, address _delegatee, address _beneficiary, uint256 _currentNonce, @@ -1630,7 +1630,7 @@ contract StakeMoreOnBehalf is UniStakerTest { // Here we use `_randomSeed` as an arbitrary source of randomness to replace a legit parameter // with an attack-like one. if (_randomSeed % 4 == 0) { - _stakeMoreAmount = uint256(keccak256(abi.encode(_stakeMoreAmount))); + _stakeMoreAmount = uint96(uint256(keccak256(abi.encode(_stakeMoreAmount)))); } else if (_randomSeed % 4 == 1) { _messageHash = _modifyMessage(_messageHash, uint256(keccak256(abi.encode(_randomSeed)))); } else if (_randomSeed % 4 == 2) { @@ -1648,7 +1648,7 @@ contract StakeMoreOnBehalf is UniStakerTest { contract AlterDelegatee is UniStakerTest { function testFuzz_AllowsStakerToUpdateTheirDelegatee( address _depositor, - uint256 _depositAmount, + uint96 _depositAmount, address _firstDelegatee, address _beneficiary, address _newDelegatee @@ -1673,7 +1673,7 @@ contract AlterDelegatee is UniStakerTest { function testFuzz_AllowsStakerToReiterateTheirDelegatee( address _depositor, - uint256 _depositAmount, + uint96 _depositAmount, address _delegatee, address _beneficiary ) public { @@ -1697,7 +1697,7 @@ contract AlterDelegatee is UniStakerTest { function testFuzz_EmitsAnEventWhenADelegateeIsChanged( address _depositor, - uint256 _depositAmount, + uint96 _depositAmount, address _firstDelegatee, address _beneficiary, address _newDelegatee @@ -1718,7 +1718,7 @@ contract AlterDelegatee is UniStakerTest { function testFuzz_RevertIf_TheCallerIsNotTheDepositor( address _depositor, address _notDepositor, - uint256 _depositAmount, + uint96 _depositAmount, address _firstDelegatee, address _beneficiary, address _newDelegatee @@ -1761,7 +1761,7 @@ contract AlterDelegatee is UniStakerTest { function testFuzz_RevertIf_DelegateeIsTheZeroAddress( address _depositor, - uint256 _depositAmount, + uint96 _depositAmount, address _delegatee ) public { UniStaker.DepositIdentifier _depositId; @@ -1779,7 +1779,7 @@ contract AlterDelegateeOnBehalf is UniStakerTest { function testFuzz_AlterDelegateeOnBehalfOfDepositor( uint256 _depositorPrivateKey, address _sender, - uint256 _amount, + uint96 _amount, address _delegatee, address _beneficiary, address _newDelegatee, @@ -1828,7 +1828,7 @@ contract AlterDelegateeOnBehalf is UniStakerTest { function testFuzz_RevertIf_WrongNonceIsUsed( uint256 _depositorPrivateKey, address _sender, - uint256 _amount, + uint96 _amount, address _delegatee, address _beneficiary, address _newDelegatee, @@ -1855,12 +1855,7 @@ contract AlterDelegateeOnBehalf is UniStakerTest { bytes32 _message = keccak256( abi.encode( - uniStaker.ALTER_DELEGATEE_TYPEHASH(), - _depositId, - _newDelegatee, - _depositor, - _suppliedNonce, - _deadline + uniStaker.ALTER_DELEGATEE_TYPEHASH(), _depositId, _newDelegatee, _depositor, _suppliedNonce ) ); @@ -1876,7 +1871,7 @@ contract AlterDelegateeOnBehalf is UniStakerTest { function testFuzz_RevertIf_DeadlineExpired( uint256 _depositorPrivateKey, address _sender, - uint256 _amount, + uint96 _amount, address _delegatee, address _beneficiary, address _newDelegatee, @@ -1923,7 +1918,7 @@ contract AlterDelegateeOnBehalf is UniStakerTest { address _sender, address _depositor, address _notDepositor, - uint256 _amount, + uint96 _amount, address _delegatee, address _newDelegatee, address _beneficiary, @@ -1955,7 +1950,7 @@ contract AlterDelegateeOnBehalf is UniStakerTest { function testFuzz_RevertIf_InvalidSignatureIsPassed( uint256 _depositorPrivateKey, address _sender, - uint256 _amount, + uint96 _amount, address _delegatee, address _beneficiary, address _newDelegatee, @@ -2011,7 +2006,7 @@ contract AlterDelegateeOnBehalf is UniStakerTest { contract AlterBeneficiary is UniStakerTest { function testFuzz_AllowsStakerToUpdateTheirBeneficiary( address _depositor, - uint256 _depositAmount, + uint96 _depositAmount, address _delegatee, address _firstBeneficiary, address _newBeneficiary @@ -2034,7 +2029,7 @@ contract AlterBeneficiary is UniStakerTest { function testFuzz_AllowsStakerToReiterateTheirBeneficiary( address _depositor, - uint256 _depositAmount, + uint96 _depositAmount, address _delegatee, address _beneficiary ) public { @@ -2055,7 +2050,7 @@ contract AlterBeneficiary is UniStakerTest { function testFuzz_EmitsAnEventWhenBeneficiaryAltered( address _depositor, - uint256 _depositAmount, + uint96 _depositAmount, address _delegatee, address _firstBeneficiary, address _newBeneficiary @@ -2076,7 +2071,7 @@ contract AlterBeneficiary is UniStakerTest { function testFuzz_RevertIf_TheCallerIsNotTheDepositor( address _depositor, address _notDepositor, - uint256 _depositAmount, + uint96 _depositAmount, address _delegatee, address _firstBeneficiary, address _newBeneficiary @@ -2120,7 +2115,7 @@ contract AlterBeneficiary is UniStakerTest { function testFuzz_RevertIf_BeneficiaryIsTheZeroAddress( address _depositor, - uint256 _depositAmount, + uint96 _depositAmount, address _delegatee ) public { UniStaker.DepositIdentifier _depositId; @@ -2138,7 +2133,7 @@ contract AlterBeneficiaryOnBehalf is UniStakerTest { function testFuzz_AlterBeneficiaryOnBehalfOfDepositor( uint256 _depositorPrivateKey, address _sender, - uint256 _amount, + uint96 _amount, address _delegatee, address _beneficiary, address _newBeneficiary, @@ -2189,7 +2184,7 @@ contract AlterBeneficiaryOnBehalf is UniStakerTest { function testFuzz_RevertIf_WrongNonceIsUsed( uint256 _depositorPrivateKey, address _sender, - uint256 _amount, + uint96 _amount, address _delegatee, address _beneficiary, address _newBeneficiary, @@ -2239,7 +2234,7 @@ contract AlterBeneficiaryOnBehalf is UniStakerTest { function testFuzz_RevertIf_DeadlineExpired( uint256 _depositorPrivateKey, address _sender, - uint256 _amount, + uint96 _amount, address _delegatee, address _beneficiary, address _newBeneficiary, @@ -2288,7 +2283,7 @@ contract AlterBeneficiaryOnBehalf is UniStakerTest { address _sender, address _depositor, address _notDepositor, - uint256 _amount, + uint96 _amount, address _delegatee, address _beneficiary, address _newBeneficiary, @@ -2320,7 +2315,7 @@ contract AlterBeneficiaryOnBehalf is UniStakerTest { function testFuzz_RevertIf_InvalidSignatureIsPassed( uint256 _depositorPrivateKey, address _sender, - uint256 _amount, + uint96 _amount, address _delegatee, address _beneficiary, address _newBeneficiary, @@ -2378,13 +2373,13 @@ contract AlterBeneficiaryOnBehalf is UniStakerTest { contract Withdraw is UniStakerTest { function testFuzz_AllowsDepositorToWithdrawStake( address _depositor, - uint256 _depositAmount, + uint96 _depositAmount, address _delegatee, - uint256 _withdrawalAmount + uint96 _withdrawalAmount ) public { UniStaker.DepositIdentifier _depositId; (_depositAmount, _depositId) = _boundMintAndStake(_depositor, _depositAmount, _delegatee); - _withdrawalAmount = bound(_withdrawalAmount, 0, _depositAmount); + _withdrawalAmount = uint96(bound(_withdrawalAmount, 0, _depositAmount)); vm.prank(_depositor); uniStaker.withdraw(_depositId, _withdrawalAmount); @@ -2399,13 +2394,13 @@ contract Withdraw is UniStakerTest { function testFuzz_UpdatesTheTotalStakedWhenAnAccountWithdraws( address _depositor, - uint256 _depositAmount, + uint96 _depositAmount, address _delegatee, - uint256 _withdrawalAmount + uint96 _withdrawalAmount ) public { UniStaker.DepositIdentifier _depositId; (_depositAmount, _depositId) = _boundMintAndStake(_depositor, _depositAmount, _delegatee); - _withdrawalAmount = bound(_withdrawalAmount, 0, _depositAmount); + _withdrawalAmount = uint96(bound(_withdrawalAmount, 0, _depositAmount)); vm.prank(_depositor); uniStaker.withdraw(_depositId, _withdrawalAmount); @@ -2415,13 +2410,13 @@ contract Withdraw is UniStakerTest { function testFuzz_UpdatesTheTotalStakedWhenTwoAccountsWithdraw( address _depositor1, - uint256 _depositAmount1, + uint96 _depositAmount1, address _delegatee1, address _depositor2, - uint256 _depositAmount2, + uint96 _depositAmount2, address _delegatee2, - uint256 _withdrawalAmount1, - uint256 _withdrawalAmount2 + uint96 _withdrawalAmount1, + uint96 _withdrawalAmount2 ) public { // Make two separate deposits UniStaker.DepositIdentifier _depositId1; @@ -2430,8 +2425,8 @@ contract Withdraw is UniStakerTest { (_depositAmount2, _depositId2) = _boundMintAndStake(_depositor2, _depositAmount2, _delegatee2); // Calculate withdrawal amounts - _withdrawalAmount1 = bound(_withdrawalAmount1, 0, _depositAmount1); - _withdrawalAmount2 = bound(_withdrawalAmount2, 0, _depositAmount2); + _withdrawalAmount1 = uint96(bound(_withdrawalAmount1, 0, _depositAmount1)); + _withdrawalAmount2 = uint96(bound(_withdrawalAmount2, 0, _depositAmount2)); // Execute both withdrawals vm.prank(_depositor1); @@ -2439,18 +2434,18 @@ contract Withdraw is UniStakerTest { vm.prank(_depositor2); uniStaker.withdraw(_depositId2, _withdrawalAmount2); - uint256 _remainingDeposits = + uint96 _remainingDeposits = _depositAmount1 + _depositAmount2 - _withdrawalAmount1 - _withdrawalAmount2; assertEq(uniStaker.totalStaked(), _remainingDeposits); } function testFuzz_UpdatesAnAccountsTotalStakedWhenItWithdrawals( address _depositor, - uint256 _depositAmount1, - uint256 _depositAmount2, + uint96 _depositAmount1, + uint96 _depositAmount2, address _delegatee1, address _delegatee2, - uint256 _withdrawalAmount + uint96 _withdrawalAmount ) public { // Make two separate deposits UniStaker.DepositIdentifier _depositId1; @@ -2459,7 +2454,7 @@ contract Withdraw is UniStakerTest { (_depositAmount2, _depositId2) = _boundMintAndStake(_depositor, _depositAmount2, _delegatee2); // Withdraw part of the first deposit - _withdrawalAmount = bound(_withdrawalAmount, 0, _depositAmount1); + _withdrawalAmount = uint96(bound(_withdrawalAmount, 0, _depositAmount1)); vm.prank(_depositor); uniStaker.withdraw(_depositId1, _withdrawalAmount); @@ -2473,13 +2468,13 @@ contract Withdraw is UniStakerTest { function testFuzz_RemovesEarningPowerFromADepositorWhoHadSelfAssignedIt( address _depositor, - uint256 _depositAmount, + uint96 _depositAmount, address _delegatee, - uint256 _withdrawalAmount + uint96 _withdrawalAmount ) public { UniStaker.DepositIdentifier _depositId; (_depositAmount, _depositId) = _boundMintAndStake(_depositor, _depositAmount, _delegatee); - _withdrawalAmount = bound(_withdrawalAmount, 0, _depositAmount); + _withdrawalAmount = uint96(bound(_withdrawalAmount, 0, _depositAmount)); vm.prank(_depositor); uniStaker.withdraw(_depositId, _withdrawalAmount); @@ -2489,15 +2484,15 @@ contract Withdraw is UniStakerTest { function testFuzz_RemovesEarningPowerFromABeneficiary( address _depositor, - uint256 _depositAmount, + uint96 _depositAmount, address _delegatee, address _beneficiary, - uint256 _withdrawalAmount + uint96 _withdrawalAmount ) public { UniStaker.DepositIdentifier _depositId; (_depositAmount, _depositId) = _boundMintAndStake(_depositor, _depositAmount, _delegatee, _beneficiary); - _withdrawalAmount = bound(_withdrawalAmount, 0, _depositAmount); + _withdrawalAmount = uint96(bound(_withdrawalAmount, 0, _depositAmount)); vm.prank(_depositor); uniStaker.withdraw(_depositId, _withdrawalAmount); @@ -2508,22 +2503,22 @@ contract Withdraw is UniStakerTest { function testFuzz_RemovesEarningPowerFromABeneficiaryAssignedByTwoDepositors( address _depositor1, address _depositor2, - uint256 _depositAmount1, - uint256 _depositAmount2, + uint96 _depositAmount1, + uint96 _depositAmount2, address _delegatee, address _beneficiary, - uint256 _withdrawalAmount1, - uint256 _withdrawalAmount2 + uint96 _withdrawalAmount1, + uint96 _withdrawalAmount2 ) public { UniStaker.DepositIdentifier _depositId1; (_depositAmount1, _depositId1) = _boundMintAndStake(_depositor1, _depositAmount1, _delegatee, _beneficiary); - _withdrawalAmount1 = bound(_withdrawalAmount1, 0, _depositAmount1); + _withdrawalAmount1 = uint96(bound(_withdrawalAmount1, 0, _depositAmount1)); UniStaker.DepositIdentifier _depositId2; (_depositAmount2, _depositId2) = _boundMintAndStake(_depositor2, _depositAmount2, _delegatee, _beneficiary); - _withdrawalAmount2 = bound(_withdrawalAmount2, 0, _depositAmount2); + _withdrawalAmount2 = uint96(bound(_withdrawalAmount2, 0, _depositAmount2)); vm.prank(_depositor1); uniStaker.withdraw(_depositId1, _withdrawalAmount1); @@ -2543,25 +2538,25 @@ contract Withdraw is UniStakerTest { function testFuzz_RemovesEarningPowerFromDifferentBeneficiariesOfTheSameDepositor( address _depositor, - uint256 _depositAmount1, - uint256 _depositAmount2, + uint96 _depositAmount1, + uint96 _depositAmount2, address _delegatee, address _beneficiary1, address _beneficiary2, - uint256 _withdrawalAmount1, - uint256 _withdrawalAmount2 + uint96 _withdrawalAmount1, + uint96 _withdrawalAmount2 ) public { vm.assume(_beneficiary1 != _beneficiary2); UniStaker.DepositIdentifier _depositId1; (_depositAmount1, _depositId1) = _boundMintAndStake(_depositor, _depositAmount1, _delegatee, _beneficiary1); - _withdrawalAmount1 = bound(_withdrawalAmount1, 0, _depositAmount1); + _withdrawalAmount1 = uint96(bound(_withdrawalAmount1, 0, _depositAmount1)); UniStaker.DepositIdentifier _depositId2; (_depositAmount2, _depositId2) = _boundMintAndStake(_depositor, _depositAmount2, _delegatee, _beneficiary2); - _withdrawalAmount2 = bound(_withdrawalAmount2, 0, _depositAmount2); + _withdrawalAmount2 = uint96(bound(_withdrawalAmount2, 0, _depositAmount2)); vm.prank(_depositor); uniStaker.withdraw(_depositId1, _withdrawalAmount1); @@ -2579,25 +2574,25 @@ contract Withdraw is UniStakerTest { function testFuzz_RemovesEarningPowerFromDifferentBeneficiariesAndDifferentDepositors( address _depositor1, address _depositor2, - uint256 _depositAmount1, - uint256 _depositAmount2, + uint96 _depositAmount1, + uint96 _depositAmount2, address _delegatee, address _beneficiary1, address _beneficiary2, - uint256 _withdrawalAmount1, - uint256 _withdrawalAmount2 + uint96 _withdrawalAmount1, + uint96 _withdrawalAmount2 ) public { vm.assume(_beneficiary1 != _beneficiary2); UniStaker.DepositIdentifier _depositId1; (_depositAmount1, _depositId1) = _boundMintAndStake(_depositor1, _depositAmount1, _delegatee, _beneficiary1); - _withdrawalAmount1 = bound(_withdrawalAmount1, 0, _depositAmount1); + _withdrawalAmount1 = uint96(bound(_withdrawalAmount1, 0, _depositAmount1)); UniStaker.DepositIdentifier _depositId2; (_depositAmount2, _depositId2) = _boundMintAndStake(_depositor2, _depositAmount2, _delegatee, _beneficiary2); - _withdrawalAmount2 = bound(_withdrawalAmount2, 0, _depositAmount2); + _withdrawalAmount2 = uint96(bound(_withdrawalAmount2, 0, _depositAmount2)); vm.prank(_depositor1); uniStaker.withdraw(_depositId1, _withdrawalAmount1); @@ -2614,13 +2609,13 @@ contract Withdraw is UniStakerTest { function testFuzz_EmitsAnEventWhenThereIsAWithdrawl( address _depositor, - uint256 _depositAmount, + uint96 _depositAmount, address _delegatee, - uint256 _withdrawalAmount + uint96 _withdrawalAmount ) public { UniStaker.DepositIdentifier _depositId; (_depositAmount, _depositId) = _boundMintAndStake(_depositor, _depositAmount, _delegatee); - _withdrawalAmount = bound(_withdrawalAmount, 0, _depositAmount); + _withdrawalAmount = uint96(bound(_withdrawalAmount, 0, _depositAmount)); vm.expectEmit(); emit UniStaker.StakeWithdrawn(_depositId, _withdrawalAmount, _depositAmount - _withdrawalAmount); @@ -2631,7 +2626,7 @@ contract Withdraw is UniStakerTest { function testFuzz_RevertIf_TheWithdrawerIsNotTheDepositor( address _depositor, - uint256 _amount, + uint96 _amount, address _delegatee, address _notDepositor ) public { @@ -2650,13 +2645,13 @@ contract Withdraw is UniStakerTest { function testFuzz_RevertIf_TheWithdrawalAmountIsGreaterThanTheBalance( address _depositor, - uint256 _amount, - uint256 _amountOver, + uint96 _amount, + uint96 _amountOver, address _delegatee ) public { UniStaker.DepositIdentifier _depositId; (_amount, _depositId) = _boundMintAndStake(_depositor, _amount, _delegatee); - _amountOver = bound(_amountOver, 1, type(uint128).max); + _amountOver = uint96(bound(_amountOver, 1, type(uint128).max)); vm.prank(_depositor); vm.expectRevert(); @@ -2670,10 +2665,10 @@ contract WithdrawOnBehalf is UniStakerTest { function testFuzz_WithdrawOnBehalfOfDepositor( uint256 _depositorPrivateKey, address _sender, - uint256 _depositAmount, + uint96 _depositAmount, address _delegatee, address _beneficiary, - uint256 _withdrawAmount, + uint96 _withdrawAmount, uint256 _currentNonce, uint256 _deadline ) public { @@ -2686,7 +2681,7 @@ contract WithdrawOnBehalf is UniStakerTest { (_depositAmount, _depositId) = _boundMintAndStake(_depositor, _depositAmount, _delegatee, _beneficiary); UniStaker.Deposit memory _deposit = _fetchDeposit(_depositId); - _withdrawAmount = bound(_withdrawAmount, 0, _depositAmount); + _withdrawAmount = uint96(bound(_withdrawAmount, 0, _depositAmount)); stdstore.target(address(uniStaker)).sig("nonces(address)").with_key(_depositor).checked_write( _currentNonce @@ -2718,10 +2713,10 @@ contract WithdrawOnBehalf is UniStakerTest { function testFuzz_RevertIf_WrongNonceIsUsed( uint256 _depositorPrivateKey, address _sender, - uint256 _depositAmount, + uint96 _depositAmount, address _delegatee, address _beneficiary, - uint256 _withdrawAmount, + uint96 _withdrawAmount, uint256 _currentNonce, uint256 _suppliedNonce, uint256 _deadline @@ -2764,10 +2759,10 @@ contract WithdrawOnBehalf is UniStakerTest { function testFuzz_RevertIf_DeadlineExpired( uint256 _depositorPrivateKey, address _sender, - uint256 _depositAmount, + uint96 _depositAmount, address _delegatee, address _beneficiary, - uint256 _withdrawAmount, + uint96 _withdrawAmount, uint256 _currentNonce, uint256 _deadline ) public { @@ -2809,10 +2804,10 @@ contract WithdrawOnBehalf is UniStakerTest { address _sender, address _depositor, address _notDepositor, - uint256 _amount, + uint96 _amount, address _delegatee, address _beneficiary, - uint256 _withdrawAmount, + uint96 _withdrawAmount, uint256 _deadline, bytes memory _signature ) public { @@ -2839,10 +2834,10 @@ contract WithdrawOnBehalf is UniStakerTest { function testFuzz_RevertIf_InvalidSignatureIsPassed( uint256 _depositorPrivateKey, address _sender, - uint256 _depositAmount, + uint96 _depositAmount, address _delegatee, address _beneficiary, - uint256 _withdrawAmount, + uint96 _withdrawAmount, uint256 _currentNonce, uint256 _randomSeed, uint256 _deadline @@ -2878,7 +2873,7 @@ contract WithdrawOnBehalf is UniStakerTest { // Here we use `_randomSeed` as an arbitrary source of randomness to replace a legit parameter // with an attack-like one. if (_randomSeed % 4 == 0) { - _withdrawAmount = uint256(keccak256(abi.encode(_withdrawAmount))); + _withdrawAmount = uint96(uint256(keccak256(abi.encode(_withdrawAmount)))); } else if (_randomSeed % 4 == 1) { _messageHash = _modifyMessage(_messageHash, uint256(keccak256(abi.encode(_randomSeed)))); } else if (_randomSeed % 4 == 2) { @@ -3067,10 +3062,10 @@ contract UniStakerRewardsTest is UniStakerTest { _boundedRewardAmount = bound(_rewardAmount, 200e6, 10_000_000e18); } - function _boundToRealisticStakeAndReward(uint256 _stakeAmount, uint256 _rewardAmount) + function _boundToRealisticStakeAndReward(uint96 _stakeAmount, uint256 _rewardAmount) public pure - returns (uint256 _boundedStakeAmount, uint256 _boundedRewardAmount) + returns (uint96 _boundedStakeAmount, uint256 _boundedRewardAmount) { _boundedStakeAmount = _boundToRealisticStake(_stakeAmount); _boundedRewardAmount = _boundToRealisticReward(_rewardAmount); @@ -3134,7 +3129,7 @@ contract NotifyRewardAmount is UniStakerRewardsTest { function testFuzz_UpdatesTheCheckpointedRewardPerTokenAccumulator( address _depositor, address _delegatee, - uint256 _stakeAmount, + uint96 _stakeAmount, uint256 _rewardAmount, uint256 _durationPercent ) public { @@ -3348,10 +3343,10 @@ contract RewardPerTokenAccumulated is UniStakerRewardsTest { function testFuzz_ReturnsZeroIfThereHasNeverBeenAReward( address _depositor1, address _depositor2, - uint256 _stakeAmount1, - uint256 _stakeAmount2, - uint256 _withdrawAmount, - uint256 _stakeMoreAmount, + uint96 _stakeAmount1, + uint96 _stakeAmount2, + uint96 _withdrawAmount, + uint96 _stakeMoreAmount, uint256 _durationPercent1 ) public { // We'll perform a few arbitrary actions, such as staking, withdrawing, and staking more. @@ -3376,7 +3371,7 @@ contract RewardPerTokenAccumulated is UniStakerRewardsTest { _jumpAheadByPercentOfRewardDuration(_durationPercent2); // First depositor withdraws some stake - _withdrawAmount = bound(_withdrawAmount, 0, _stakeAmount1); + _withdrawAmount = uint96(bound(_withdrawAmount, 0, _stakeAmount1)); vm.prank(_depositor1); uniStaker.withdraw(_depositId1, _withdrawAmount); _jumpAheadByPercentOfRewardDuration(_durationPercent3); @@ -3395,7 +3390,7 @@ contract RewardPerTokenAccumulated is UniStakerRewardsTest { function testFuzz_DoesNotChangeWhileNoTokensAreStaked( address _depositor, - uint256 _stakeAmount, + uint96 _stakeAmount, uint256 _rewardAmount, uint256 _durationPercent1, uint256 _durationPercent2, @@ -3432,15 +3427,15 @@ contract RewardPerTokenAccumulated is UniStakerRewardsTest { function testFuzz_DoesNotChangeWhileNoRewardsAreBeingDistributed( address _depositor, - uint256 _stakeAmount, + uint96 _stakeAmount, uint256 _rewardAmount, - uint256 _withdrawAmount, + uint96 _withdrawAmount, uint256 _durationPercent1, uint256 _durationPercent2, uint256 _durationPercent3 ) public { (_stakeAmount, _rewardAmount) = _boundToRealisticStakeAndReward(_stakeAmount, _rewardAmount); - _withdrawAmount = _bound(_withdrawAmount, 0, _stakeAmount); + _withdrawAmount = uint96(_bound(_withdrawAmount, 0, _stakeAmount)); _durationPercent1 = _bound(_durationPercent1, 0, 200); _durationPercent2 = _bound(_durationPercent2, 0, 200); _durationPercent3 = _bound(_durationPercent3, 0, 200); @@ -3472,13 +3467,13 @@ contract RewardPerTokenAccumulated is UniStakerRewardsTest { function testFuzz_DoesNotChangeIfTimeDoesNotElapse( address _depositor, - uint256 _stakeAmount, + uint96 _stakeAmount, uint256 _rewardAmount, - uint256 _withdrawAmount, + uint96 _withdrawAmount, uint256 _durationPercent1 ) public { (_stakeAmount, _rewardAmount) = _boundToRealisticStakeAndReward(_stakeAmount, _rewardAmount); - _withdrawAmount = _bound(_withdrawAmount, 0, _stakeAmount); + _withdrawAmount = uint96(_bound(_withdrawAmount, 0, _stakeAmount)); _durationPercent1 = _bound(_durationPercent1, 0, 200); // A user deposits staking tokens @@ -3504,7 +3499,7 @@ contract RewardPerTokenAccumulated is UniStakerRewardsTest { function testFuzz_AccruesTheCorrectValueWhenADepositorStakesForSomePortionOfAReward( address _depositor, - uint256 _stakeAmount, + uint96 _stakeAmount, uint256 _rewardAmount, uint256 _durationPercent ) public { @@ -3525,7 +3520,7 @@ contract RewardPerTokenAccumulated is UniStakerRewardsTest { function testFuzz_AccruesTheCorrectValueWhenADepositorStakesAfterAReward( address _depositor, - uint256 _stakeAmount, + uint96 _stakeAmount, uint256 _rewardAmount, uint256 _durationPercent ) public { @@ -3548,7 +3543,7 @@ contract RewardPerTokenAccumulated is UniStakerRewardsTest { function testFuzz_AccruesTheCorrectValueWhenADepositorStakesForARewardDurationAndAnotherDepositorStakesForASecondRewardDuration( address _depositor, - uint256 _stakeAmount, + uint96 _stakeAmount, uint256 _rewardAmount, uint256 _durationPercent ) public { @@ -3576,7 +3571,7 @@ contract RewardPerTokenAccumulated is UniStakerRewardsTest { function testFuzz_AccruesTheCorrectValueWhenTwoDepositorsStakeAtDifferentTimesAndThereAreTwoRewards( address _depositor, - uint256 _stakeAmount, + uint96 _stakeAmount, uint256 _rewardAmount, uint256 _durationPercent1, uint256 _durationPercent2 @@ -3616,14 +3611,14 @@ contract RewardPerTokenAccumulated is UniStakerRewardsTest { function testFuzz_AccruesTheCorrectValueWhenADepositorStakesAndWithdrawsDuringARewardDuration( address _depositor, - uint256 _stakeAmount, + uint96 _stakeAmount, uint256 _rewardAmount, - uint256 _withdrawalAmount, + uint96 _withdrawalAmount, uint256 _durationPercent1, uint256 _durationPercent2 ) public { (_stakeAmount, _rewardAmount) = _boundToRealisticStakeAndReward(_stakeAmount, _rewardAmount); - _withdrawalAmount = _bound(_withdrawalAmount, 0, _stakeAmount - 1); + _withdrawalAmount = uint96(_bound(_withdrawalAmount, 0, _stakeAmount - 1)); _durationPercent1 = _bound(_durationPercent1, 0, 100); _durationPercent2 = _bound(_durationPercent2, 0, 100 - _durationPercent1); @@ -3652,8 +3647,8 @@ contract RewardPerTokenAccumulated is UniStakerRewardsTest { function testFuzz_AccruesTheCorrectValueWhenTwoDepositorsStakeDifferentAmountsAtDifferentTimesOverTwoRewards( address _depositor1, address _depositor2, - uint256 _stakeAmount1, - uint256 _stakeAmount2, + uint96 _stakeAmount1, + uint96 _stakeAmount2, uint256 _rewardAmount, uint256 _durationPercent1, uint256 _durationPercent2, @@ -3705,7 +3700,7 @@ contract RewardPerTokenAccumulated is UniStakerRewardsTest { function testFuzz_AccruesTheCorrectValueWhenAnArbitraryNumberOfDepositorsStakeDifferentAmountsOverTheCourseOfARewardDuration( address _depositor, - uint256 _stakeAmount, + uint96 _stakeAmount, uint256 _rewardAmount, uint256 _durationPercent ) public { @@ -3722,7 +3717,7 @@ contract RewardPerTokenAccumulated is UniStakerRewardsTest { while (_totalDurationPercent < 100) { // On each iteration we derive new values _depositor = address(uint160(uint256(keccak256(abi.encode(_depositor))))); - _stakeAmount = uint256(keccak256(abi.encode(_stakeAmount))); + _stakeAmount = uint96(uint256(keccak256(abi.encode(_stakeAmount)))); _stakeAmount = _boundToRealisticStake(_stakeAmount); _durationPercent = uint256(keccak256(abi.encode(_durationPercent))); // We make sure the duration jump on each iteration isn't so small that we slow the test @@ -3755,7 +3750,7 @@ contract UnclaimedReward is UniStakerRewardsTest { function testFuzz_CalculatesCorrectEarningsForASingleDepositorThatStakesForFullDuration( address _depositor, address _delegatee, - uint256 _stakeAmount, + uint96 _stakeAmount, uint256 _rewardAmount ) public { (_stakeAmount, _rewardAmount) = _boundToRealisticStakeAndReward(_stakeAmount, _rewardAmount); @@ -3775,7 +3770,7 @@ contract UnclaimedReward is UniStakerRewardsTest { address _depositor, address _delegatee, address _beneficiary, - uint256 _stakeAmount, + uint96 _stakeAmount, uint256 _rewardAmount ) public { (_stakeAmount, _rewardAmount) = _boundToRealisticStakeAndReward(_stakeAmount, _rewardAmount); @@ -3796,7 +3791,7 @@ contract UnclaimedReward is UniStakerRewardsTest { address _delegatee, address _beneficiary1, address _beneficiary2, - uint256 _stakeAmount, + uint96 _stakeAmount, uint256 _rewardAmount, uint256 _percentDuration ) public { @@ -3832,7 +3827,7 @@ contract UnclaimedReward is UniStakerRewardsTest { function testFuzz_CalculatesCorrectEarningsForASingleUserThatDepositsStakeForPartialDuration( address _depositor, address _delegatee, - uint256 _stakeAmount, + uint96 _stakeAmount, uint256 _rewardAmount, uint256 _durationPercent ) public { @@ -3855,7 +3850,7 @@ contract UnclaimedReward is UniStakerRewardsTest { function testFuzz_CalculatesCorrectEarningsForASingleUserThatDepositsPartiallyThroughTheDuration( address _depositor, address _delegatee, - uint256 _stakeAmount, + uint96 _stakeAmount, uint256 _rewardAmount ) public { (_stakeAmount, _rewardAmount) = _boundToRealisticStakeAndReward(_stakeAmount, _rewardAmount); @@ -3877,7 +3872,7 @@ contract UnclaimedReward is UniStakerRewardsTest { address _depositor, address _delegatee, address _beneficiary, - uint256 _stakeAmount, + uint96 _stakeAmount, uint256 _rewardAmount, uint256 _durationPercent ) public { @@ -3904,7 +3899,7 @@ contract UnclaimedReward is UniStakerRewardsTest { address _depositor, address _delegatee, address _beneficiary, - uint256 _stakeAmount, + uint96 _stakeAmount, uint256 _rewardAmount ) public { vm.assume(_beneficiary != address(0)); @@ -3928,7 +3923,7 @@ contract UnclaimedReward is UniStakerRewardsTest { function testFuzz_CalculatesCorrectEarningsForASingleUserThatDepositsStakeForTheFullDurationWithNoNewRewards( address _depositor, address _delegatee, - uint256 _stakeAmount, + uint96 _stakeAmount, uint256 _rewardAmount, uint16 _noRewardsSkip ) public { @@ -3954,7 +3949,7 @@ contract UnclaimedReward is UniStakerRewardsTest { function testFuzz_CalculatesCorrectEarningsForASingleUserThatDepositsStakeForTheFullDurationWithDelayedReward( address _depositor, address _delegatee, - uint256 _stakeAmount, + uint96 _stakeAmount, uint256 _rewardAmount, uint16 _noRewardsSkip ) public { @@ -3984,7 +3979,7 @@ contract UnclaimedReward is UniStakerRewardsTest { address _delegatee, address _beneficiary1, address _beneficiary2, - uint256 _stakeAmount, + uint96 _stakeAmount, uint256 _rewardAmount, uint256 _percentDuration, uint16 _noRewardsSkip @@ -4029,7 +4024,7 @@ contract UnclaimedReward is UniStakerRewardsTest { function testFuzz_CalculatesCorrectEarningsForASingleUserThatDepositsStakeForTheFullDurationAndClaims( address _depositor, address _delegatee, - uint256 _stakeAmount, + uint96 _stakeAmount, uint256 _rewardAmount, uint256 _durationPercent ) public { @@ -4067,7 +4062,7 @@ contract UnclaimedReward is UniStakerRewardsTest { function testFuzz_CalculatesCorrectEarningsForASingleUserThatDepositsStakeForThePartialDurationAndClaims( address _depositor, address _delegatee, - uint256 _stakeAmount, + uint96 _stakeAmount, uint256 _rewardAmount, uint256 _durationPercent ) public { @@ -4105,7 +4100,7 @@ contract UnclaimedReward is UniStakerRewardsTest { address _depositor1, address _depositor2, address _delegatee, - uint256 _stakeAmount, + uint96 _stakeAmount, uint256 _rewardAmount ) public { vm.assume(_depositor1 != _depositor2); @@ -4131,7 +4126,7 @@ contract UnclaimedReward is UniStakerRewardsTest { address _depositor1, address _depositor2, address _delegatee, - uint256 _stakeAmount, + uint96 _stakeAmount, uint256 _rewardAmount ) public { vm.assume(_depositor1 != _depositor2); @@ -4175,7 +4170,7 @@ contract UnclaimedReward is UniStakerRewardsTest { address _depositor1, address _depositor2, address _delegatee, - uint256 _stakeAmount, + uint96 _stakeAmount, uint256 _rewardAmount ) public { vm.assume(_depositor1 != _depositor2); @@ -4217,7 +4212,7 @@ contract UnclaimedReward is UniStakerRewardsTest { address _depositor1, address _depositor2, address _delegatee, - uint256 _stakeAmount, + uint96 _stakeAmount, uint256 _rewardAmount ) public { vm.assume(_depositor1 != _depositor2); @@ -4272,7 +4267,7 @@ contract UnclaimedReward is UniStakerRewardsTest { address _depositor3, address _depositor4, address _delegatee, - uint256 _stakeAmount, + uint96 _stakeAmount, uint256 _rewardAmount ) public { vm.assume( @@ -4314,7 +4309,7 @@ contract UnclaimedReward is UniStakerRewardsTest { address _depositor3, address _depositor4, address _delegatee, - uint256 _stakeAmount, + uint96 _stakeAmount, uint256 _rewardAmount ) public { vm.assume( @@ -4377,7 +4372,7 @@ contract UnclaimedReward is UniStakerRewardsTest { address _depositor2, address _depositor3, address _depositor4, - uint256 _stakeAmount, + uint96 _stakeAmount, uint256 _rewardAmount ) public { vm.assume( @@ -4468,7 +4463,7 @@ contract UnclaimedReward is UniStakerRewardsTest { address _depositor1, address _depositor2, address _delegatee, - uint256 _stakeAmount, + uint96 _stakeAmount, uint256 _rewardAmount ) public { vm.assume(_depositor1 != _depositor2); @@ -4501,7 +4496,7 @@ contract UnclaimedReward is UniStakerRewardsTest { function testFuzz_CalculatesCorrectEarningsWhenAUserDepositsAndThereAreTwoRewards( address _depositor, address _delegatee, - uint256 _stakeAmount, + uint96 _stakeAmount, uint256 _rewardAmount1, uint256 _rewardAmount2 ) public { @@ -4533,7 +4528,7 @@ contract UnclaimedReward is UniStakerRewardsTest { address _depositor1, address _depositor2, address _delegatee, - uint256 _stakeAmount, + uint96 _stakeAmount, uint256 _rewardAmount1, uint256 _rewardAmount2 ) public { @@ -4582,8 +4577,8 @@ contract UnclaimedReward is UniStakerRewardsTest { address _depositor1, address _depositor2, address _delegatee, - uint256 _stakeAmount1, - uint256 _stakeAmount2, + uint96 _stakeAmount1, + uint96 _stakeAmount2, uint256 _rewardAmount1, uint256 _rewardAmount2 ) public { @@ -4635,7 +4630,7 @@ contract UnclaimedReward is UniStakerRewardsTest { function testFuzz_CalculatesCorrectEarningsWhenAUserDepositsAndThereAreThreeRewards( address _depositor, address _delegatee, - uint256 _stakeAmount, + uint96 _stakeAmount, uint256 _rewardAmount1, uint256 _rewardAmount2, uint256 _rewardAmount3 @@ -4677,7 +4672,7 @@ contract UnclaimedReward is UniStakerRewardsTest { address _depositor1, address _depositor2, address _delegatee, - uint256 _stakeAmount, + uint96 _stakeAmount, uint256 _rewardAmount1, uint256 _rewardAmount2, uint256 _rewardAmount3 @@ -4741,8 +4736,8 @@ contract UnclaimedReward is UniStakerRewardsTest { address _depositor1, address _depositor2, address _delegatee, - uint256 _stakeAmount1, - uint256 _stakeAmount2, + uint96 _stakeAmount1, + uint96 _stakeAmount2, uint256 _rewardAmount1, uint256 _rewardAmount2, uint256 _rewardAmount3 @@ -4804,8 +4799,8 @@ contract UnclaimedReward is UniStakerRewardsTest { address _depositor1, address _depositor2, address _delegatee, - uint256 _stakeAmount1, - uint256 _stakeAmount2, + uint96 _stakeAmount1, + uint96 _stakeAmount2, uint256 _rewardAmount, uint256 _durationPercent ) public { @@ -4840,8 +4835,8 @@ contract UnclaimedReward is UniStakerRewardsTest { address _delegatee = makeAddr("Delegatee"); address _attacker = makeAddr("Attacker"); - uint256 _smallDepositAmount = 0.1e18; - uint256 _largeDepositAmount = 25_000_000e18; + uint96 _smallDepositAmount = 0.1e18; + uint96 _largeDepositAmount = 25_000_000e18; _mintGovToken(_depositor1, _smallDepositAmount); _mintGovToken(_depositor2, _smallDepositAmount); _mintGovToken(_depositor3, _largeDepositAmount); @@ -4881,7 +4876,7 @@ contract ClaimReward is UniStakerRewardsTest { function testFuzz_SendsRewardsEarnedToTheUser( address _depositor, address _delegatee, - uint256 _stakeAmount, + uint96 _stakeAmount, uint256 _rewardAmount, uint256 _durationPercent ) public { @@ -4908,7 +4903,7 @@ contract ClaimReward is UniStakerRewardsTest { function testFuzz_ResetsTheRewardsEarnedByTheUser( address _depositor, address _delegatee, - uint256 _stakeAmount, + uint96 _stakeAmount, uint256 _rewardAmount, uint256 _durationPercent ) public { @@ -4931,7 +4926,7 @@ contract ClaimReward is UniStakerRewardsTest { function testFuzz_EmitsAnEventWhenRewardsAreClaimed( address _depositor, address _delegatee, - uint256 _stakeAmount, + uint96 _stakeAmount, uint256 _rewardAmount, uint256 _durationPercent ) public { @@ -4961,7 +4956,7 @@ contract ClaimRewardOnBehalf is UniStakerRewardsTest { function testFuzz_ClaimRewardOnBehalfOfBeneficiary( uint256 _beneficiaryPrivateKey, address _sender, - uint256 _depositAmount, + uint96 _depositAmount, uint256 _durationPercent, uint256 _rewardAmount, address _delegatee, @@ -5011,7 +5006,7 @@ contract ClaimRewardOnBehalf is UniStakerRewardsTest { function testFuzz_RevertIf_WrongNonceIsUsed( uint256 _beneficiaryPrivateKey, address _sender, - uint256 _depositAmount, + uint96 _depositAmount, uint256 _durationPercent, uint256 _rewardAmount, address _delegatee, @@ -5058,7 +5053,7 @@ contract ClaimRewardOnBehalf is UniStakerRewardsTest { function testFuzz_RevertIf_DeadlineExpired( uint256 _beneficiaryPrivateKey, address _sender, - uint256 _depositAmount, + uint96 _depositAmount, uint256 _durationPercent, uint256 _rewardAmount, address _delegatee, @@ -5103,7 +5098,7 @@ contract ClaimRewardOnBehalf is UniStakerRewardsTest { function testFuzz_RevertIf_InvalidSignatureIsPassed( uint256 _beneficiaryPrivateKey, address _sender, - uint256 _depositAmount, + uint96 _depositAmount, address _depositor, address _delegatee, uint256 _currentNonce, @@ -5167,42 +5162,42 @@ contract _FetchOrDeploySurrogate is UniStakerRewardsTest { } contract Multicall is UniStakerRewardsTest { - function _encodeStake(address _delegatee, uint256 _stakeAmount) + function _encodeStake(address _delegatee, uint96 _stakeAmount) internal pure returns (bytes memory) { return - abi.encodeWithSelector(bytes4(keccak256("stake(uint256,address)")), _stakeAmount, _delegatee); + abi.encodeWithSelector(bytes4(keccak256("stake(uint96,address)")), _stakeAmount, _delegatee); } - function _encodeStake(address _delegatee, uint256 _stakeAmount, address _beneficiary) + function _encodeStake(address _delegatee, uint96 _stakeAmount, address _beneficiary) internal pure returns (bytes memory) { return abi.encodeWithSelector( - bytes4(keccak256("stake(uint256,address,address)")), _stakeAmount, _delegatee, _beneficiary + bytes4(keccak256("stake(uint96,address,address)")), _stakeAmount, _delegatee, _beneficiary ); } - function _encodeStakeMore(UniStaker.DepositIdentifier _depositId, uint256 _stakeAmount) + function _encodeStakeMore(UniStaker.DepositIdentifier _depositId, uint96 _stakeAmount) internal pure returns (bytes memory) { return abi.encodeWithSelector( - bytes4(keccak256("stakeMore(uint256,uint256)")), _depositId, _stakeAmount + bytes4(keccak256("stakeMore(uint256,uint96)")), _depositId, _stakeAmount ); } - function _encodeWithdraw(UniStaker.DepositIdentifier _depositId, uint256 _amount) + function _encodeWithdraw(UniStaker.DepositIdentifier _depositId, uint96 _amount) internal pure returns (bytes memory) { return - abi.encodeWithSelector(bytes4(keccak256("withdraw(uint256,uint256)")), _depositId, _amount); + abi.encodeWithSelector(bytes4(keccak256("withdraw(uint256,uint96)")), _depositId, _amount); } function _encodeAlterBeneficiary(UniStaker.DepositIdentifier _depositId, address _beneficiary) @@ -5229,8 +5224,8 @@ contract Multicall is UniStakerRewardsTest { address _depositor, address _delegatee1, address _delegatee2, - uint256 _stakeAmount1, - uint256 _stakeAmount2 + uint96 _stakeAmount1, + uint96 _stakeAmount2 ) public { _stakeAmount1 = _boundToRealisticStake(_stakeAmount1); _stakeAmount2 = _boundToRealisticStake(_stakeAmount2); @@ -5254,8 +5249,8 @@ contract Multicall is UniStakerRewardsTest { address _delegatee1, address _beneficiary0, address _beneficiary1, - uint256 _stakeAmount0, - uint256 _stakeAmount1, + uint96 _stakeAmount0, + uint96 _stakeAmount1, uint256 _timeElapsed ) public { _stakeAmount0 = _boundToRealisticStake(_stakeAmount0); @@ -5285,7 +5280,7 @@ contract Multicall is UniStakerRewardsTest { uniStaker.multicall(_calls); vm.stopPrank(); - (uint256 _amountResult,, address _delegateeResult, address _beneficiaryResult) = + (uint96 _amountResult,, address _delegateeResult, address _beneficiaryResult) = uniStaker.deposits(_depositId); assertEq(uniStaker.depositorTotalStaked(_depositor), _stakeAmount0 + _stakeAmount1); assertEq(_amountResult, _stakeAmount0 + _stakeAmount1); diff --git a/test/helpers/IntegrationTest.sol b/test/helpers/IntegrationTest.sol index abc0d07..a760891 100644 --- a/test/helpers/IntegrationTest.sol +++ b/test/helpers/IntegrationTest.sol @@ -53,9 +53,9 @@ contract IntegrationTest is ProposalTest { v3FactoryOwner.claimFees(IUniswapV3PoolOwnerActions(DAI_WETH_3000_POOL), address(this), 1, 0); } - function _dealStakingToken(address _depositor, uint256 _amount) internal returns (uint256) { + function _dealStakingToken(address _depositor, uint96 _amount) internal returns (uint96) { stdstore.target(STAKE_TOKEN_ADDRESS).sig("mintingAllowedAfter()").checked_write(uint256(0)); - _amount = bound(_amount, 1, 2e25); // max mint cap + _amount = uint96(bound(_amount, 1, 2e25)); // max mint cap IERC20Mint stakeToken = IERC20Mint(STAKE_TOKEN_ADDRESS); vm.prank(STAKING_TOKEN_MINTER); diff --git a/test/helpers/UniStaker.handler.sol b/test/helpers/UniStaker.handler.sol index e4f03b5..e879e00 100644 --- a/test/helpers/UniStaker.handler.sol +++ b/test/helpers/UniStaker.handler.sol @@ -91,7 +91,7 @@ contract UniStakerHandler is CommonBase, StdCheats, StdUtils { ghost_rewardsNotified += _amount; } - function stake(uint256 _amount, address _delegatee, address _beneficiary) + function stake(uint96 _amount, address _delegatee, address _beneficiary) public countCall("stake") doCheckpoints @@ -100,7 +100,7 @@ contract UniStakerHandler is CommonBase, StdCheats, StdUtils { _beneficiaries.add(_beneficiary); _delegates.add(_delegatee); - _amount = bound(_amount, 0, 100_000_000e18); + _amount = uint96(bound(_amount, 0, 100_000_000e18)); // assume user has stake amount _mintStakeToken(_currentActor, _amount); @@ -117,7 +117,7 @@ contract UniStakerHandler is CommonBase, StdCheats, StdUtils { ghost_stakeSum += _amount; } - function validStakeMore(uint256 _amount, uint256 _actorSeed, uint256 _actorDepositSeed) + function validStakeMore(uint96 _amount, uint256 _actorSeed, uint256 _actorDepositSeed) public countCall("validStakeMore") doCheckpoints @@ -127,8 +127,8 @@ contract UniStakerHandler is CommonBase, StdCheats, StdUtils { vm.assume(_depositIds[_currentActor].length > 0); UniStaker.DepositIdentifier _depositId = UniStaker.DepositIdentifier.wrap(_getActorRandDepositId(_actorDepositSeed)); - (uint256 _balance,,,) = uniStaker.deposits(_depositId); - _amount = bound(_amount, 0, _balance); + (uint96 _balance,,,) = uniStaker.deposits(_depositId); + _amount = uint96(bound(_amount, 0, _balance)); vm.startPrank(_currentActor); stakeToken.approve(address(uniStaker), _amount); uniStaker.stakeMore(_depositId, _amount); @@ -136,7 +136,7 @@ contract UniStakerHandler is CommonBase, StdCheats, StdUtils { ghost_stakeSum += _amount; } - function validWithdraw(uint256 _amount, uint256 _actorSeed, uint256 _actorDepositSeed) + function validWithdraw(uint96 _amount, uint256 _actorSeed, uint256 _actorDepositSeed) public countCall("validWithdraw") doCheckpoints @@ -146,8 +146,8 @@ contract UniStakerHandler is CommonBase, StdCheats, StdUtils { vm.assume(_depositIds[_currentActor].length > 0); UniStaker.DepositIdentifier _depositId = UniStaker.DepositIdentifier.wrap(_getActorRandDepositId(_actorDepositSeed)); - (uint256 _balance,,,) = uniStaker.deposits(_depositId); - _amount = bound(_amount, 0, _balance); + (uint96 _balance,,,) = uniStaker.deposits(_depositId); + _amount = uint96(bound(_amount, 0, _balance)); vm.startPrank(_currentActor); uniStaker.withdraw(_depositId, _amount); vm.stopPrank();