Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
122 changes: 78 additions & 44 deletions contracts/Store.sol
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about using this type of comment to split the storage and make it more readable ? => https://github.com/iExecBlockchainComputing/rlc-multichain/blob/09761d4bb9c252a6ca9a0020d2ad7979ec9ae75f/src/RLCLiquidityUnifier.sol#L62

Copy link
Member Author

@zguesmi zguesmi Jul 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not fan of these comments personally, we use it in other projects.
We can enhance later.

Original file line number Diff line number Diff line change
Expand Up @@ -17,58 +17,92 @@ import "./registries/IRegistry.sol";
/****************************************************************************
* WARNING: Be carefull when editing this file. *
* *
* If you want add new variables for expanded features, add them at the *
* end, or (better?) create a Store_v2 that inherits from this Store. *
* If you want to add new variables, add them to the end of the *
* struct `PocoStorage`. *
* Read more about: *
* - Diamond proxy storage https://eips.ethereum.org/EIPS/eip-2535 *
* - Namespaced storage https://eips.ethereum.org/EIPS/eip-7201 *
* *
* If in doubt, read about Diamond proxy storage. *
****************************************************************************/

// TODO replace with diamond AppStorage using namespaced storage.
// TODO check storage padding.
abstract contract Store {
// Registries
IRegistry internal m_appregistry;
IRegistry internal m_datasetregistry;
IRegistry internal m_workerpoolregistry;
// Poco - Constants
uint256 public constant CONTRIBUTION_DEADLINE_RATIO = 7;
uint256 public constant REVEAL_DEADLINE_RATIO = 2;
uint256 public constant FINAL_DEADLINE_RATIO = 10;
uint256 public constant WORKERPOOL_STAKE_RATIO = 30;
uint256 public constant KITTY_RATIO = 10;
uint256 public constant KITTY_MIN = 1e9; // ADJUSTEMENT VARIABLE

// Escrow
IERC20 internal m_baseToken;
string internal m_name;
string internal m_symbol;
uint8 internal m_decimals;
uint256 internal m_totalSupply;
mapping(address => uint256) internal m_balances;
mapping(address => uint256) internal m_frozens;
mapping(address => mapping(address => uint256)) internal m_allowances;
// Seized funds of workerpools that do not honor their deals are sent
// out to this kitty address.
// It is determined with address(uint256(keccak256(bytes('iExecKitty'))) - 1).
address public constant KITTY_ADDRESS = 0x99c2268479b93fDe36232351229815DF80837e23;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not having a variable (uint256) directly into the PocoStorage struct ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using constant reduces gas cost.


// Poco - Constants
uint256 internal constant CONTRIBUTION_DEADLINE_RATIO = 7;
uint256 internal constant REVEAL_DEADLINE_RATIO = 2;
uint256 internal constant FINAL_DEADLINE_RATIO = 10;
uint256 internal constant WORKERPOOL_STAKE_RATIO = 30;
uint256 internal constant KITTY_RATIO = 10;
uint256 internal constant KITTY_MIN = 1000000000; // ADJUSTEMENT VARIABLE
address internal constant KITTY_ADDRESS = 0x99c2268479b93fDe36232351229815DF80837e23; // address(uint256(keccak256(bytes('iExecKitty'))) - 1);
uint256 internal constant GROUPMEMBER_PURPOSE = 4;
bytes32 internal EIP712DOMAIN_SEPARATOR;
// Used with ERC-734 Key Manager identity contract for authorization management.
uint256 public constant GROUPMEMBER_PURPOSE = 4;

// Poco - Storage
mapping(bytes32 => address) internal m_presigned; // per order
mapping(bytes32 => uint256) internal m_consumed; // per order
mapping(bytes32 => IexecLibCore_v5.Deal) internal m_deals; // per deal
mapping(bytes32 => IexecLibCore_v5.Task) internal m_tasks; // per task
mapping(bytes32 => IexecLibCore_v5.Consensus) internal m_consensus; // per task
mapping(bytes32 => mapping(address => IexecLibCore_v5.Contribution)) internal m_contributions; // per task-worker
mapping(address => uint256) internal m_workerScores; // per worker
// keccak256(abi.encode(uint256(keccak256("iexec.poco.storage.PocoStorage")) - 1)) & ~bytes32(uint256(0xff));
bytes32 private constant POCO_STORAGE_LOCATION =
0x5862653c6982c162832160cf30593645e8487b257e44d77cdd6b51eee2651b00;

// Poco - Settings
address internal m_teebroker;
uint256 internal m_callbackgas;
/// @custom:storage-location erc7201:iexec.poco.storage.PocoStorage
struct PocoStorage {
// Registries
IRegistry m_appregistry;
IRegistry m_datasetregistry;
IRegistry m_workerpoolregistry;
// Escrow
IERC20 m_baseToken;
string m_name;
string m_symbol;
uint8 m_decimals;
uint256 m_totalSupply;
// In order to use the protocol, users have to deposit RLC
// and allow PoCo smart contracts to manage them. This state
// variable keeps track of users balances.
mapping(address => uint256) m_balances;
// When a deal is created, the protocol temporarily locks an amount
// of RLC tokens from the balances of both the requester and the workerpool owners.
// This is to guarantee the payment of different actors later. Frozen funds
// are released when the computation is completed and the result is pushed.
mapping(address => uint256) m_frozens;
mapping(address => mapping(address => uint256)) m_allowances;
// EIP-712 domain hash.
// Modified in IexecConfigurationFacet.updateDomainSeparator
bytes32 EIP712DOMAIN_SEPARATOR; // TODO rename
// Poco - Storage

// Categories
IexecLibCore_v5.Category[] internal m_categories;
// Mapping an order hash to its owner. Since a smart contract cannot sign orders
// with a private key, it adds an entry to this mapping to provide presigned orders.
mapping(bytes32 => address) m_presigned;
// Each order has a volume (>=1). This tracks how much is consumed from
// the volume of each order. Mapping an order hash to its consumed amount.
mapping(bytes32 => uint256) m_consumed;
// a mapping to store PoCo classic deals.
mapping(bytes32 => IexecLibCore_v5.Deal) m_deals;
mapping(bytes32 => IexecLibCore_v5.Task) m_tasks; // per task
mapping(bytes32 => IexecLibCore_v5.Consensus) m_consensus; // per task
mapping(bytes32 => mapping(address => IexecLibCore_v5.Contribution)) m_contributions; // per task-worker
mapping(address => uint256) m_workerScores; // per worker
Comment on lines +78 to +87
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes done in this PR Add comments to store mappings

// Poco - Settings
// Address of a trusted TEE authority that manages enclave challenges.
// Modified in IexecConfigurationFacet.setTeeBroker
address m_teebroker;
// Max amount of gas to be used with callbacks.
// Modified in IexecConfigurationFacet.setCallbackGas
uint256 m_callbackgas;
// List of defined computation categories.
IexecLibCore_v5.Category[] m_categories;
// Backward compatibility
// Modified in IexecConfigurationFacet.configure
IexecHubInterface m_v3_iexecHub;
mapping(address => bool) m_v3_scoreImported;
}

// Backward compatibility
IexecHubInterface internal m_v3_iexecHub;
mapping(address => bool) internal m_v3_scoreImported;
function getPocoStorage() internal pure returns (PocoStorage storage $) {
assembly {
$_slot := POCO_STORAGE_LOCATION
}
}
}
224 changes: 90 additions & 134 deletions contracts/Store.v8.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,144 +11,100 @@ import {IexecLibCore_v5} from "./libs/IexecLibCore_v5.sol";
/****************************************************************************
* WARNING: Be carefull when editing this file. *
* *
* If you want add new variables for expanded features, add them at the *
* end, or (better?) create a Store_v2 that inherits from this Store. *
* If you want to add new variables, add them to the end of the *
* struct `PocoStorage`. *
* Read more about: *
* - Diamond proxy storage https://eips.ethereum.org/EIPS/eip-2535 *
* - Namespaced storage https://eips.ethereum.org/EIPS/eip-7201 *
* *
* If in doubt, read about Diamond proxy storage. *
****************************************************************************/

/// @dev registries
interface IRegistry is IERC721Enumerable {
function isRegistered(address _entry) external view returns (bool);
}

/// @dev Poco store
/**
* @title Central storage of all modules contracts. It follows the Diamond
* pattern aka ERC-2535.
* @dev note the new added state variable "m_dealsBoost" that holds a new type
* of deals for the PoCo Boost workflow.
*/
// TODO replace with diamond AppStorage using namespaced storage.
// TODO check storage padding.
abstract contract Store {
// Registries
//slither-disable-next-line constable-states
IRegistry internal m_appregistry;
//slither-disable-next-line constable-states
IRegistry internal m_datasetregistry;
//slither-disable-next-line constable-states
IRegistry internal m_workerpoolregistry;

// Escrow
//slither-disable-next-line constable-states
IERC20 internal m_baseToken;
//slither-disable-next-line constable-states
string internal m_name;
//slither-disable-next-line constable-states
string internal m_symbol;
//slither-disable-next-line constable-states
uint8 internal m_decimals;
//slither-disable-next-line constable-states
uint256 internal m_totalSupply;

/**
* @dev In order to use the protocol, users have to deposit RLC
* and allow PoCo smart contracts to manage them. This state
* variable keeps track of users balances.
*/
mapping(address => uint256) internal m_balances;

/**
* @dev When a deal is created, the protocol temporarily locks an amount
* of RLC tokens from the balances of both the requester and the workerpool owners.
* This is to guarantee the payment of different actors later. Frozen funds
* are released when the computation is completed and the result is pushed.
*/
mapping(address => uint256) internal m_frozens;

mapping(address => mapping(address => uint256)) internal m_allowances;

// Poco - Constants
uint256 internal constant CONTRIBUTION_DEADLINE_RATIO = 7;
uint256 internal constant REVEAL_DEADLINE_RATIO = 2;
uint256 internal constant FINAL_DEADLINE_RATIO = 10;
uint256 internal constant WORKERPOOL_STAKE_RATIO = 30;
uint256 internal constant KITTY_RATIO = 10;
uint256 internal constant KITTY_MIN = 1e9; // ADJUSTEMENT VARIABLE

/**
* @dev Seized funds of workerpools that do not honor their deals are sent
* out to this kitty address.
* It is determined with address(uint256(keccak256(bytes('iExecKitty'))) - 1).
*/
address internal constant KITTY_ADDRESS = 0x99c2268479b93fDe36232351229815DF80837e23;

/**
* @dev Used with ERC-734 Key Manager identity contract for authorization management.
*/
uint256 internal constant GROUPMEMBER_PURPOSE = 4;

/**
* @dev EIP-712 domain hash.
*/
// Modified in IexecConfigurationFacet.updateDomainSeparator
//slither-disable-next-line constable-states
bytes32 internal EIP712DOMAIN_SEPARATOR;

// Poco - Storage

/**
* @dev Mapping an order hash to its owner. Since a smart contract cannot sign orders
* with a private key, it adds an entry to this mapping to provide presigned orders.
*/
mapping(bytes32 => address) internal m_presigned;

/**
* @dev Each order has a volume (>=1). This tracks how much is consumed from
* the volume of each order. Mapping an order hash to its consumed amount.
*/
mapping(bytes32 => uint256) internal m_consumed;

/**
* @dev a mapping to store PoCo classic deals.
*/
mapping(bytes32 => IexecLibCore_v5.Deal) internal m_deals;

mapping(bytes32 => IexecLibCore_v5.Task) internal m_tasks; // per task
mapping(bytes32 => IexecLibCore_v5.Consensus) internal m_consensus; // per task
mapping(bytes32 => mapping(address => IexecLibCore_v5.Contribution)) internal m_contributions; // per task-worker
mapping(address => uint256) internal m_workerScores; // per worker

// Poco - Settings

/**
* @dev Address of a trusted TEE authority that manages enclave challenges.
*/
// Modified in IexecConfigurationFacet.setTeeBroker
//slither-disable-next-line constable-states
address internal m_teebroker;

/**
* @dev Max amount of gas to be used with callbacks.
*/
// Modified in IexecConfigurationFacet.setCallbackGas
//slither-disable-next-line constable-states
uint256 internal m_callbackgas;

/**
* @dev List of defined computation categories.
*/
IexecLibCore_v5.Category[] internal m_categories;

// Backward compatibility
// Modified in IexecConfigurationFacet.configure
//slither-disable-next-line constable-states
address internal m_v3_iexecHub; // IexecHubInterface
mapping(address => bool) internal m_v3_scoreImported;
uint256 public constant CONTRIBUTION_DEADLINE_RATIO = 7;
uint256 public constant REVEAL_DEADLINE_RATIO = 2;
uint256 public constant FINAL_DEADLINE_RATIO = 10;
uint256 public constant WORKERPOOL_STAKE_RATIO = 30;
uint256 public constant KITTY_RATIO = 10;
uint256 public constant KITTY_MIN = 1e9; // ADJUSTEMENT VARIABLE

// Seized funds of workerpools that do not honor their deals are sent
// out to this kitty address.
// It is determined with address(uint256(keccak256(bytes('iExecKitty'))) - 1).
address public constant KITTY_ADDRESS = 0x99c2268479b93fDe36232351229815DF80837e23;

// Used with ERC-734 Key Manager identity contract for authorization management.
uint256 public constant GROUPMEMBER_PURPOSE = 4;

// keccak256(abi.encode(uint256(keccak256("iexec.poco.storage.PocoStorage")) - 1)) & ~bytes32(uint256(0xff));
bytes32 private constant POCO_STORAGE_LOCATION =
0x5862653c6982c162832160cf30593645e8487b257e44d77cdd6b51eee2651b00;

/// @custom:storage-location erc7201:iexec.poco.storage.PocoStorage
struct PocoStorage {
// Registries
IRegistry m_appregistry;
IRegistry m_datasetregistry;
IRegistry m_workerpoolregistry;
// Escrow
IERC20 m_baseToken;
string m_name;
string m_symbol;
uint8 m_decimals;
uint256 m_totalSupply;
// In order to use the protocol, users have to deposit RLC
// and allow PoCo smart contracts to manage them. This state
// variable keeps track of users balances.
mapping(address => uint256) m_balances;
// When a deal is created, the protocol temporarily locks an amount
// of RLC tokens from the balances of both the requester and the workerpool owners.
// This is to guarantee the payment of different actors later. Frozen funds
// are released when the computation is completed and the result is pushed.
mapping(address => uint256) m_frozens;
mapping(address => mapping(address => uint256)) m_allowances;
// EIP-712 domain hash.
// Modified in IexecConfigurationFacet.updateDomainSeparator
bytes32 EIP712DOMAIN_SEPARATOR; // TODO rename
// Poco - Storage

// Mapping an order hash to its owner. Since a smart contract cannot sign orders
// with a private key, it adds an entry to this mapping to provide presigned orders.
mapping(bytes32 => address) m_presigned;
// Each order has a volume (>=1). This tracks how much is consumed from
// the volume of each order. Mapping an order hash to its consumed amount.
mapping(bytes32 => uint256) m_consumed;
// a mapping to store PoCo classic deals.
mapping(bytes32 => IexecLibCore_v5.Deal) m_deals;
mapping(bytes32 => IexecLibCore_v5.Task) m_tasks; // per task
mapping(bytes32 => IexecLibCore_v5.Consensus) m_consensus; // per task
mapping(bytes32 => mapping(address => IexecLibCore_v5.Contribution)) m_contributions; // per task-worker
mapping(address => uint256) m_workerScores; // per worker
// Poco - Settings
// Address of a trusted TEE authority that manages enclave challenges.
// Modified in IexecConfigurationFacet.setTeeBroker
address m_teebroker;
// Max amount of gas to be used with callbacks.
// Modified in IexecConfigurationFacet.setCallbackGas
uint256 m_callbackgas;
// List of defined computation categories.
IexecLibCore_v5.Category[] m_categories;
// Backward compatibility
// Modified in IexecConfigurationFacet.configure
address m_v3_iexecHub; // IexecHubInterface
mapping(address => bool) m_v3_scoreImported;
// /!\ New storage variables not present in v6 store.
// A mapping to store PoCo Boost deals.
mapping(bytes32 => IexecLibCore_v5.DealBoost) m_dealsBoost;
}

function getPocoStorage() internal pure returns (PocoStorage storage $) {
assembly ("memory-safe") {
$.slot := POCO_STORAGE_LOCATION
}
}
}

/**
* @dev A mapping to store PoCo Boost deals.
*/
mapping(bytes32 => IexecLibCore_v5.DealBoost) internal m_dealsBoost;
// Use in registries.
interface IRegistry is IERC721Enumerable {
function isRegistered(address _entry) external view returns (bool);
}
Comment on lines +107 to 110
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we move that into a dedicated file instead ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not needed because it's only used here.

Loading
Loading