Skip to content

Commit

Permalink
feat(StableTokenV2): add missing storage slots (#261)
Browse files Browse the repository at this point in the history
  • Loading branch information
ninabarbakadze committed Aug 10, 2023
1 parent 4a0e5de commit 06020be
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 23 deletions.
5 changes: 4 additions & 1 deletion contracts/tokens/patched/ERC20Upgradeable.sol
Expand Up @@ -49,6 +49,9 @@ contract ERC20Upgradeable is Ownable, Initializable, IERC20Upgradeable, IERC20Me
uint256 private _totalSupply;
mapping(address => mapping(address => uint256)) private _allowances;

uint256[4] private __deprecated_inflationState_storage_slot__;

Check warning on line 52 in contracts/tokens/patched/ERC20Upgradeable.sol

View workflow job for this annotation

GitHub Actions / Lint & Test

Variable name must be in mixedCase

Check warning on line 52 in contracts/tokens/patched/ERC20Upgradeable.sol

View workflow job for this annotation

GitHub Actions / Lint & Test

Variable name must be in mixedCase
bytes32 private __deprecated_exchangeRegistryId_storage_slot__;

Check warning on line 53 in contracts/tokens/patched/ERC20Upgradeable.sol

View workflow job for this annotation

GitHub Actions / Lint & Test

Variable name must be in mixedCase

Check warning on line 53 in contracts/tokens/patched/ERC20Upgradeable.sol

View workflow job for this annotation

GitHub Actions / Lint & Test

Variable name must be in mixedCase

/**
* @dev Sets the values for {name} and {symbol}.
*
Expand Down Expand Up @@ -403,5 +406,5 @@ contract ERC20Upgradeable is Ownable, Initializable, IERC20Upgradeable, IERC20Me
* variables without shifting down storage in the inheritance chain.
* See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
*/
uint256[45] private __gap;
uint256[40] private __gap;
}
44 changes: 23 additions & 21 deletions contracts/tokens/patched/README.md
Expand Up @@ -39,32 +39,34 @@ To make this work I copied the contracts from version `v4.8.0` here and modified
> Note: The columns of the table are: slot, offset, name, type
The `initialized` bool upgrades nicely to the new `Initializable` structure in more recent OZ - it was designed this way.
We reserve some deprecated solts, and make sure the others match up 1:1. The name being differnet is not an issue.
We reserve some deprecated slots, and make sure the others match up 1:1. The name being different is not an issue.

And which can then be used in `ERC20Permit` and `StableTokenV2` to finally come up with this:

```
> ./bin/storage-show.sh StableTokenV2
0 0 _owner t_address
0 20 _initialized t_uint8
0 21 _initializing t_bool
1 0 __deprecated_registry_storage_slot__ t_address
2 0 _name t_string_storage
3 0 _symbol t_string_storage
4 0 __deprecated_decimals_storage_slot__ t_uint8
5 0 _balances t_mapping(t_address,t_uint256)
6 0 _totalSupply t_uint256
7 0 _allowances t_mapping(t_address,t_mapping(t_address,t_uint256))
8 0 __gap t_array(t_uint256)45_storage
53 0 _HASHED_NAME t_bytes32
54 0 _HASHED_VERSION t_bytes32
55 0 __gap t_array(t_uint256)50_storage
105 0 _nonces t_mapping(t_address,t_struct(Counter)23999_storage)
106 0 _PERMIT_TYPEHASH_DEPRECATED_SLOT t_bytes32
107 0 __gap t_array(t_uint256)49_storage
156 0 validators t_address
157 0 broker t_address
158 0 exchange t_address
0 0 _owner t_address
0 20 _initialized t_uint8
0 21 _initializing t_bool
1 0 __deprecated_registry_storage_slot__ t_address
2 0 _name t_string_storage
3 0 _symbol t_string_storage
4 0 __deprecated_decimals_storage_slot__ t_uint8
5 0 _balances t_mapping(t_address,t_uint256)
6 0 _totalSupply t_uint256
7 0 _allowances t_mapping(t_address,t_mapping(t_address,t_uint256))
8 0 __deeprecated_inflationState_storage_slot__ t_array(t_uint256)4_storage
12 0 __deprecated_exchangeRegistryId_storage_slot__ t_bytes32
13 0 __gap t_array(t_uint256)40_storage
53 0 _HASHED_NAME t_bytes32
54 0 _HASHED_VERSION t_bytes32
55 0 __gap t_array(t_uint256)50_storage
105 0 _nonces t_mapping(t_address,t_struct(Counter)51157_storage)
106 0 _PERMIT_TYPEHASH_DEPRECATED_SLOT t_bytes32
107 0 __gap t_array(t_uint256)49_storage
156 0 validators t_address
157 0 broker t_address
158 0 exchange t_address
```

In this new implementation we also remove the dependency on the `Registry` and introduce the 3 new storage variables to store addresses for the dependencies directly.
Expand Down
2 changes: 1 addition & 1 deletion slither.db.json

Large diffs are not rendered by default.

0 comments on commit 06020be

Please sign in to comment.