Skip to content

Commit

Permalink
use bytes32 (#725)
Browse files Browse the repository at this point in the history
  • Loading branch information
snreynolds authored May 28, 2024
1 parent ad4cb38 commit 9b17e03
Show file tree
Hide file tree
Showing 8 changed files with 11 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/libraries/Lock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import {IHooks} from "../interfaces/IHooks.sol";
/// @notice This is a temporary library that allows us to use transient storage (tstore/tload)
/// TODO: This library can be deleted when we have the transient keyword support in solidity.
library Lock {
// The slot holding the unlocked state, transiently. uint256(keccak256("Unlocked")) - 1;
uint256 constant IS_UNLOCKED_SLOT = 0xc090fc4683624cfc3884e9d8de5eca132f2d0ec062aff75d43c0465d5ceeab23;
// The slot holding the unlocked state, transiently. bytes32(uint256(keccak256("Unlocked")) - 1)
bytes32 constant IS_UNLOCKED_SLOT = 0xc090fc4683624cfc3884e9d8de5eca132f2d0ec062aff75d43c0465d5ceeab23;

function unlock() internal {
assembly {
Expand Down
4 changes: 2 additions & 2 deletions src/libraries/NonZeroDeltaCount.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import {IHooks} from "../interfaces/IHooks.sol";
/// for the nonzero delta count.
/// TODO: This library can be deleted when we have the transient keyword support in solidity.
library NonZeroDeltaCount {
// The slot holding the number of nonzero deltas. uint256(keccak256("NonzeroDeltaCount")) - 1
uint256 constant NONZERO_DELTA_COUNT_SLOT = 0x7d4b3164c6e45b97e7d87b7125a44c5828d005af88f9d751cfd78729c5d99a0b;
// The slot holding the number of nonzero deltas. bytes32(uint256(keccak256("NonzeroDeltaCount")) - 1)
bytes32 constant NONZERO_DELTA_COUNT_SLOT = 0x7d4b3164c6e45b97e7d87b7125a44c5828d005af88f9d751cfd78729c5d99a0b;

function read() internal view returns (uint256 count) {
assembly {
Expand Down
4 changes: 2 additions & 2 deletions src/libraries/Reserves.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import {CustomRevert} from "./CustomRevert.sol";
library Reserves {
using CustomRevert for bytes4;

/// uint256(keccak256("ReservesOf")) - 1
uint256 constant RESERVES_OF_SLOT = 0x1e0745a7db1623981f0b2a5d4232364c00787266eb75ad546f190e6cebe9bd95;
/// bytes32(uint256(keccak256("ReservesOf")) - 1)
bytes32 constant RESERVES_OF_SLOT = 0x1e0745a7db1623981f0b2a5d4232364c00787266eb75ad546f190e6cebe9bd95;
/// @notice The transient reserves for pools with no balance is set to the max as a sentinel to track that it has been synced.
uint256 public constant ZERO_BALANCE = type(uint256).max;

Expand Down
4 changes: 2 additions & 2 deletions src/libraries/StateLibrary.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ library StateLibrary {
// | Name | Type | Slot | Offset | Bytes | Contract |
// |-----------------------|-----------------------------------------|------|--------|-------|---------------------------------|
// | pools | mapping(PoolId => struct Pool.State) | 6 | 0 | 32 | src/PoolManager.sol:PoolManager |
uint256 public constant POOLS_SLOT = 6;
bytes32 public constant POOLS_SLOT = bytes32(uint256(6));

// index of feeGrowthGlobal0X128 in Pool.State
uint256 public constant FEE_GROWTH_GLOBAL0_OFFSET = 1;
Expand Down Expand Up @@ -325,7 +325,7 @@ library StateLibrary {
}

function _getPoolStateSlot(PoolId poolId) internal pure returns (bytes32) {
return keccak256(abi.encodePacked(PoolId.unwrap(poolId), bytes32(POOLS_SLOT)));
return keccak256(abi.encodePacked(PoolId.unwrap(poolId), POOLS_SLOT));
}

function _getTickInfoSlot(PoolId poolId, int24 tick) internal pure returns (bytes32) {
Expand Down
2 changes: 1 addition & 1 deletion test/Reserves.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ contract ReservesTest is Test {
}

function test_reservesOfSlot() public pure {
assertEq(uint256(keccak256("ReservesOf")) - 1, Reserves.RESERVES_OF_SLOT);
assertEq(bytes32(uint256(keccak256("ReservesOf")) - 1), Reserves.RESERVES_OF_SLOT);
}

function test_fuzz_get_set(Currency currency, uint256 value) public {
Expand Down
2 changes: 1 addition & 1 deletion test/libraries/Lock.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ contract LockTest is Test {
}

function test_unlockedSlot() public pure {
assertEq(uint256(keccak256("Unlocked")) - 1, Lock.IS_UNLOCKED_SLOT);
assertEq(bytes32(uint256(keccak256("Unlocked")) - 1), Lock.IS_UNLOCKED_SLOT);
}
}
2 changes: 1 addition & 1 deletion test/libraries/NonZeroDeltaCount.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,6 @@ contract NonZeroDeltaCountTest is Test {
}

function test_nonZeroDeltaCountSlot() public pure {
assertEq(uint256(keccak256("NonzeroDeltaCount")) - 1, NonZeroDeltaCount.NONZERO_DELTA_COUNT_SLOT);
assertEq(bytes32(uint256(keccak256("NonzeroDeltaCount")) - 1), NonZeroDeltaCount.NONZERO_DELTA_COUNT_SLOT);
}
}
1 change: 0 additions & 1 deletion test/utils/Constants.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ library Constants {
/// 0011 1111 1111 1111
address payable constant ALL_HOOKS = payable(0x0000000000000000000000000000000000003fFF);

uint256 constant POOL_SLOT = 10;
uint256 constant TICKS_OFFSET = 4;

uint24 constant FEE_LOW = 500;
Expand Down

0 comments on commit 9b17e03

Please sign in to comment.