From a59d8a4482828c890c3f6e60abd0c7c070232d6e Mon Sep 17 00:00:00 2001 From: Dirk Brink Date: Fri, 22 Dec 2023 10:22:38 -0800 Subject: [PATCH] evm: wipe slots with warnings --- .../CircleIntegration/Implementation.sol | 16 ++++++++++++++++ evm/src/contracts/CircleIntegration/Storage.sol | 9 +++++++++ 2 files changed, 25 insertions(+) diff --git a/evm/src/contracts/CircleIntegration/Implementation.sol b/evm/src/contracts/CircleIntegration/Implementation.sol index e587c7b..b0923eb 100644 --- a/evm/src/contracts/CircleIntegration/Implementation.sol +++ b/evm/src/contracts/CircleIntegration/Implementation.sol @@ -15,6 +15,22 @@ contract Implementation is Logic { function initialize() public virtual initializer { // This function needs to be exposed for an upgrade to pass. Any additional logic can be // placed here. + + /** + * WARNING: This snippet should be removed for any following contract upgrades + * We are using the below snippet to reset storage slots that are no longer being used + * for safety and to free them up for future use. We don't want to inadvertantly wipe + * the same slots on future upgrades. See Storage.sol for reasoning. + */ + assembly ("memory-safe") { + sstore(0x0, 0x0) + sstore(0x1, 0x0) + sstore(0x2, 0x0) + sstore(0x3, 0x0) + sstore(0x4, 0x0) + sstore(0xA, 0x0) + } + } modifier initializer() { diff --git a/evm/src/contracts/CircleIntegration/Storage.sol b/evm/src/contracts/CircleIntegration/Storage.sol index fc24e98..16eba9c 100644 --- a/evm/src/contracts/CircleIntegration/Storage.sol +++ b/evm/src/contracts/CircleIntegration/Storage.sol @@ -2,6 +2,15 @@ pragma solidity ^0.8.22; + +/** + * WARNING: This is the state layout of V0 before the first upgrade. + * Slots 0 -> 4 inclusive and slot 10 will be wiped to 0 on initialisation of the new + * implementation and will be safe to use again in the future. We are no longer + * using those variables in state, but they are instead immutables in the new implementation. + * If using those slots again, ensure the slots are not being wiped to 0 in the + * initialiser in future upgrades. + */ /** * struct State { * // state.slot := 0x0