Skip to content

Commit

Permalink
(H-5) - Fix storage slot value check (#1389)
Browse files Browse the repository at this point in the history
* fix storage slot validation

* fix storage validator to take into account dynamic values

* add storage validation on build steps
  • Loading branch information
mjlescano committed Jan 31, 2023
1 parent 557e188 commit 7930cf0
Show file tree
Hide file tree
Showing 11 changed files with 205 additions and 120 deletions.
6 changes: 3 additions & 3 deletions markets/spot-market/package.json
Expand Up @@ -4,9 +4,9 @@
"description": "Spot Market implementation",
"private": true,
"scripts": {
"start": "npm run cannon-build && npm run cannon",
"cannon-build": "npx hardhat cannon:build",
"cannon": "npx cannon spot-market:1.0.0",
"build": "hardhat storage:verify && hardhat cannon:build",
"start": "npm run build && npm run cannon",
"cannon": "cannon spot-market:1.0.0",
"test": "hardhat test",
"coverage": "hardhat coverage --network hardhat",
"compile-contracts": "hardhat compile",
Expand Down
139 changes: 98 additions & 41 deletions markets/spot-market/storage.dump.sol
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity >=0.8.11 < 0.9.0;
pragma solidity >=0.8.11<0.9.0;

// @custom:artifact @synthetixio/core-contracts/contracts/ownership/OwnableStorage.sol:OwnableStorage
library OwnableStorage {
Expand Down Expand Up @@ -100,6 +100,20 @@ library DecimalMath {
uint256 public constant PRECISION_FACTOR = 9;
}

// @custom:artifact @synthetixio/core-contracts/contracts/utils/SetUtil.sol:SetUtil
library SetUtil {
struct UintSet {
Bytes32Set raw;
}
struct AddressSet {
Bytes32Set raw;
}
struct Bytes32Set {
bytes32[] _values;
mapping(bytes32 => uint) _positions;
}
}

// @custom:artifact @synthetixio/core-modules/contracts/modules/NftModule.sol:NftModule
contract NftModule {
bytes32 internal constant _INITIALIZED_NAME = "NftModule";
Expand Down Expand Up @@ -139,6 +153,21 @@ library DecayToken {
}
}

// @custom:artifact @synthetixio/core-modules/contracts/storage/FeatureFlag.sol:FeatureFlag
library FeatureFlag {
struct Data {
bytes32 name;
bool allowAll;
SetUtil.AddressSet permissionedAddresses;
}
function load(bytes32 featureName) internal pure returns (Data storage store) {
bytes32 s = keccak256(abi.encode("io.synthetix.core-modules.FeatureFlag", featureName));
assembly {
store.slot := s
}
}
}

// @custom:artifact @synthetixio/core-modules/contracts/storage/Initialized.sol:Initialized
library Initialized {
struct Data {
Expand All @@ -152,32 +181,22 @@ library Initialized {
}
}

// @custom:artifact @synthetixio/oracle-manager/contracts/storage/NodeOutput.sol:Node
library Node {
struct Data {
int256 price;
uint timestamp;
uint volatilityScore;
uint liquidityScore;
}
}

// @custom:artifact @synthetixio/oracle-manager/contracts/storage/NodeDefinition.sol:NodeDefinition
library NodeDefinition {
enum NodeType {
NONE,
REDUCER,
EXTERNAL,
CHAINLINK,
PYTH,
PriceDeviationCircuitBreaker,
UNISWAP,
StalenessCircuitBreaker
PYTH,
PRICE_DEVIATION_CIRCUIT_BREAKER,
STALENESS_CIRCUIT_BREAKER
}
struct Data {
bytes32[] parents;
NodeType nodeType;
bytes parameters;
bytes32[] parents;
}
function load(bytes32 id) internal pure returns (Data storage data) {
bytes32 s = keccak256(abi.encode("io.synthetix.oracle-manager.Node", id));
Expand All @@ -187,15 +206,68 @@ library NodeDefinition {
}
}

// @custom:artifact contracts/storage/AsyncOrderConfiguration.sol:AsyncOrder
library AsyncOrder {
// @custom:artifact @synthetixio/oracle-manager/contracts/storage/NodeOutput.sol:NodeOutput
library NodeOutput {
struct Data {
int256 price;
uint256 timestamp;
uint256 __slotAvailableForFutureUse1;
uint256 __slotAvailableForFutureUse2;
}
}

// @custom:artifact contracts/interfaces/external/IPythVerifier.sol:IPythVerifier
interface IPythVerifier {
struct Price {
int64 price;
uint64 conf;
int32 expo;
uint publishTime;
}
struct PriceFeed {
bytes32 id;
Price price;
Price emaPrice;
}
}

// @custom:artifact contracts/modules/SpotMarketFactoryModule.sol:SpotMarketFactoryModule
contract SpotMarketFactoryModule {
bytes32 private constant _CREATE_SYNTH_FEATURE_FLAG = "createSynth";
}

// @custom:artifact contracts/storage/AsyncOrderClaim.sol:AsyncOrderClaim
library AsyncOrderClaim {
struct Data {
SpotMarketFactory.TransactionType orderType;
uint256 amountEscrowed;
uint256 settlementStrategyId;
uint256 settlementTime;
int256 utilizationDelta;
uint256 cancellationFee;
}
}

// @custom:artifact contracts/storage/AsyncOrderConfiguration.sol:AsyncOrderConfiguration
library AsyncOrderConfiguration {
enum SettlementStrategyType {
ONCHAIN,
CHAINLINK,
PYTH
}
struct Data {
mapping(uint256 => AsyncOrderClaim.Data) asyncOrderClaims;
uint256 minimumOrderAge;
uint256 settlementWindowDuration;
uint256 livePriceSettlementWindowDuration;
mapping(address => uint256) escrowedSynthShares;
uint256 totalEscrowedSynthShares;
SettlementStrategy[] settlementStrategies;
int256 asyncUtilizationDelta;
}
struct SettlementStrategy {
SettlementStrategyType strategyType;
uint256 fixedFee;
uint256 settlementDelay;
uint256 settlementWindowDuration;
address priceVerificationContract;
}
function load(uint128 marketId) internal pure returns (Data storage store) {
bytes32 s = keccak256(abi.encode("io.synthetix.spot-market.AsyncOrder", marketId));
Expand All @@ -205,19 +277,8 @@ library AsyncOrder {
}
}

// @custom:artifact contracts/storage/AsyncOrderClaim.sol:AsyncOrderClaim
library AsyncOrderClaim {
struct Data {
SpotMarketFactory.TransactionType orderType;
uint256 synthAmountEscrowed;
uint256 usdAmountEscrowed;
uint256 blockNumber;
uint256 timestamp;
}
}

// @custom:artifact contracts/storage/Fee.sol:Fee
library Fee {
// @custom:artifact contracts/storage/FeeConfiguration.sol:FeeConfiguration
library FeeConfiguration {
struct Data {
mapping(address => uint) atomicFixedFeeOverrides;
uint atomicFixedFee;
Expand Down Expand Up @@ -267,7 +328,8 @@ library SpotMarketFactory {
address synthetix;
address initialSynthImplementation;
address initialAsyncOrderClaimImplementation;
mapping(uint128 => address) synthOwners;
mapping(uint128 => address) marketOwners;
mapping(uint128 => address) nominatedMarketOwners;
}
function load() internal pure returns (Data storage store) {
bytes32 s = _SLOT_SPOT_MARKET_FACTORY;
Expand All @@ -280,8 +342,8 @@ library SpotMarketFactory {
// @custom:artifact contracts/storage/Wrapper.sol:Wrapper
library Wrapper {
struct Data {
address collateralType;
bool wrappingEnabled;
address wrapCollateralType;
uint256 maxWrappableAmount;
}
function load(uint128 marketId) internal pure returns (Data storage store) {
bytes32 s = keccak256(abi.encode("io.synthetix.spot-market.Wrapper", marketId));
Expand All @@ -290,8 +352,3 @@ library Wrapper {
}
}
}

// @custom:artifact hardhat/console.sol:console
library console {
address internal constant CONSOLE_ADDRESS = address(0x000000000000000000636F6e736F6c652e6c6f67);
}
4 changes: 1 addition & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions protocol/oracle-manager/package.json
Expand Up @@ -5,8 +5,8 @@
"private": true,
"scripts": {
"test": "hardhat test",
"coverage": "npx hardhat cannon:build && hardhat --network hardhat coverage",
"build": "hardhat cannon:build",
"coverage": "npm run build && hardhat --network hardhat coverage",
"build": "hardhat storage:verify && hardhat cannon:build",
"compile-contracts": "hardhat compile",
"size-contracts": "hardhat compile && hardhat size-contracts",
"lint:fix": "npm run lint:js:fix && npm run lint:sol:fix",
Expand Down
27 changes: 14 additions & 13 deletions protocol/oracle-manager/storage.dump.sol
Expand Up @@ -64,6 +64,11 @@ library ChainlinkNode {
uint256 public constant PRECISION = 18;
}

// @custom:artifact contracts/nodes/PythNode.sol:PythNode
library PythNode {
int256 public constant PRECISION = 18;
}

// @custom:artifact contracts/nodes/ReducerNode.sol:ReducerNode
library ReducerNode {
enum Operations {
Expand All @@ -77,14 +82,9 @@ library ReducerNode {
}
}

// @custom:artifact contracts/storage/NodeOutput.sol:Node
library Node {
struct Data {
int256 price;
uint timestamp;
uint volatilityScore;
uint liquidityScore;
}
// @custom:artifact contracts/nodes/UniswapNode.sol:UniswapNode
library UniswapNode {
uint8 public constant PRECISION = 18;
}

// @custom:artifact contracts/storage/NodeDefinition.sol:NodeDefinition
Expand All @@ -94,14 +94,15 @@ library NodeDefinition {
REDUCER,
EXTERNAL,
CHAINLINK,
UNISWAP,
PYTH,
PriceDeviationCircuitBreaker,
UNISWAP
PRICE_DEVIATION_CIRCUIT_BREAKER,
STALENESS_CIRCUIT_BREAKER
}
struct Data {
bytes32[] parents;
NodeType nodeType;
bytes parameters;
bytes32[] parents;
}
function load(bytes32 id) internal pure returns (Data storage data) {
bytes32 s = keccak256(abi.encode("io.synthetix.oracle-manager.Node", id));
Expand All @@ -116,8 +117,8 @@ library NodeOutput {
struct Data {
int256 price;
uint256 timestamp;
uint256 __slotAvailableForFutureUse_1;
uint256 __slotAvailableForFutureUse_2;
uint256 __slotAvailableForFutureUse1;
uint256 __slotAvailableForFutureUse2;
}
}

Expand Down
2 changes: 1 addition & 1 deletion protocol/synthetix/package.json
Expand Up @@ -4,7 +4,7 @@
"description": "Core Synthetix Protocol Contracts",
"private": true,
"scripts": {
"build": "rm -rf contracts/generated && hardhat generate-testable",
"build": "rm -rf contracts/generated && hardhat storage:verify && hardhat generate-testable",
"test": "npm run build -- --quiet && hardhat test",
"coverage": "npm run build -- --quiet && hardhat coverage --network hardhat",
"compile-contracts": "hardhat compile",
Expand Down

0 comments on commit 7930cf0

Please sign in to comment.