Skip to content

Commit

Permalink
add storage slots for future proxy upgrades
Browse files Browse the repository at this point in the history
  • Loading branch information
RnkSngh authored and nicopernas committed Apr 4, 2024
1 parent c7f7df2 commit bfa80cd
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 9 deletions.
10 changes: 9 additions & 1 deletion contracts/core/Dispatcher.sol
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ import {Address} from "@openzeppelin/contracts/utils/Address.sol";
* which can be relayed to a rollup module on the Polymerase chain
*/
contract Dispatcher is OwnableUpgradeable, UUPSUpgradeable, IDispatcher {
uint256[49] private __gap;

//
// fields
//
Expand All @@ -53,7 +55,12 @@ contract Dispatcher is OwnableUpgradeable, UUPSUpgradeable, IDispatcher {
// keep track of outbound ack packets to prevent replay attack
mapping(address => mapping(bytes32 => mapping(uint64 => bool))) private _ackPacketCommitment;

LightClient _lightClient;
LightClient _lightClient; // Can't be set to immutable since it needs to be called in the initializer; not the

//////// NEW storage
mapping(bytes32 => string) private _channelIdToConnection;

// constructor

//
// methods
Expand Down Expand Up @@ -584,6 +591,7 @@ contract Dispatcher is OwnableUpgradeable, UUPSUpgradeable, IDispatcher {
_nextSequenceSend[address(portAddress)][local.channelId] = 1;
_nextSequenceRecv[address(portAddress)][local.channelId] = 1;
_nextSequenceAck[address(portAddress)][local.channelId] = 1;
_channelIdToConnection[local.channelId] = connectionHops[0]; // Set channel to connection mapping for finding
}

// Returns the result of the call if no revert, otherwise returns the error if thrown.
Expand Down
2 changes: 1 addition & 1 deletion test/Dispatcher.proof.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ abstract contract DispatcherIbcWithRealProofsSuite is IbcEventsEmitter, Base {
// plant a fake packet commitment so the ack checks go through
// Stdstore doesn't work for proxies so we have to use store
// use "forge inspect --storage" to find the nested mapping slot
bytes32 slot1 = keccak256(abi.encode(address(mars), uint32(107))); // current nested mapping slot: 107
bytes32 slot1 = keccak256(abi.encode(address(mars), uint32(156))); // current nested mapping slot: 157
bytes32 slot2 = keccak256(abi.encode(ch0.channelId, slot1));
bytes32 slot3 = keccak256(abi.encode(uint256(1), slot2));
vm.store(address(dispatcherProxy), slot3, bytes32(uint256(1)));
Expand Down
2 changes: 1 addition & 1 deletion test/Dispatcher.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -622,7 +622,7 @@ contract DappRevertTests is Base {
function test_ack_packet_dapp_revert() public {
// plant a fake packet commitment so the ack checks go through
// use "forge inspect --storage" to find the slot
bytes32 slot1 = keccak256(abi.encode(address(revertingStringMars), uint32(107))); // current nested mapping
bytes32 slot1 = keccak256(abi.encode(address(revertingStringMars), uint32(156))); // current nested mapping
// slot:
bytes32 slot2 = keccak256(abi.encode(ch0.channelId, slot1));
bytes32 slot3 = keccak256(abi.encode(uint256(1), slot2));
Expand Down
8 changes: 4 additions & 4 deletions test/upgradeableProxy/Dispatcher.upgrade.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ abstract contract UpgradeTestUtils {
}

contract ChannelHandShakeUpgradeUtil is ChannelHandshakeUtils {
uint32 nextSequenceSendSlot = 104;
uint32 sendPacketCommitmentSlot = 107;
uint32 nextSequenceAckSlot = 106;
uint32 nextSequenceRecvSlot = 105;
uint32 nextSequenceSendSlot = 153;
uint32 sendPacketCommitmentSlot = 156;
uint32 nextSequenceAckSlot = 155;
uint32 nextSequenceRecvSlot = 154;
IbcPacket[3] packets;
string payload = "msgPayload";
bytes packet = abi.encodePacked(payload);
Expand Down
4 changes: 2 additions & 2 deletions test/upgradeableProxy/DispatcherUUPS.accessControl.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ contract DispatcherUUPSAccessControl is Base {
assertEq(address(dispatcherImplementation2), getProxyImplementation(address(dispatcherProxy), vm));
assertEq(dispatcherProxy.portPrefix(), portPrefix);
assertEq(
address(uint160(uint256(vm.load(address(dispatcherProxy), bytes32(uint256(110)))))),
address(uint160(uint256(vm.load(address(dispatcherProxy), bytes32(uint256(159)))))),
address(dummyConsStateManager)
);
}
Expand All @@ -44,7 +44,7 @@ contract DispatcherUUPSAccessControl is Base {
assertEq(address(dispatcherImplementation3), getProxyImplementation(address(dispatcherProxy), vm));
assertEq(dispatcherProxy.portPrefix(), portPrefix2);
assertEq(
address(uint160(uint256(vm.load(address(dispatcherProxy), bytes32(uint256(110)))))), address(lightClient2)
address(uint160(uint256(vm.load(address(dispatcherProxy), bytes32(uint256(159)))))), address(lightClient2)
);
}

Expand Down
2 changes: 2 additions & 0 deletions test/upgradeableProxy/upgrades/DispatcherV2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ import {Address} from "@openzeppelin/contracts/utils/Address.sol";
* which can be relayed to a rollup module on the Polymerase chain
*/
contract DispatcherV2 is OwnableUpgradeable, UUPSUpgradeable, IDispatcher {
uint256[49] private __gap;

//
// fields
//
Expand Down

0 comments on commit bfa80cd

Please sign in to comment.