diff --git a/contracts/facets/FacetBase.sol b/contracts/facets/FacetBase.sol index 8466f0cc7..f42f01523 100644 --- a/contracts/facets/FacetBase.sol +++ b/contracts/facets/FacetBase.sol @@ -14,27 +14,28 @@ import "../interfaces/IOwnable.sol"; */ abstract contract FacetBase { // 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 + 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 // 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; + address internal constant KITTY_ADDRESS = 0x99c2268479b93fDe36232351229815DF80837e23; // Used with ERC-734 Key Manager identity contract for authorization management. - uint256 public constant GROUPMEMBER_PURPOSE = 4; + uint256 internal constant GROUPMEMBER_PURPOSE = 4; modifier onlyOwner() { require(_msgSender() == owner(), "Ownable: caller is not the owner"); _; } - function owner() public view returns (address) { + function owner() internal view returns (address) { + // TODO use LibDiamond.contractOwner() instead of an external call when migrating all contracts to v8. return IOwnable(address(this)).owner(); } diff --git a/contracts/facets/FacetBase.v8.sol b/contracts/facets/FacetBase.v8.sol index b85ffb550..ed5a74cdb 100644 --- a/contracts/facets/FacetBase.v8.sol +++ b/contracts/facets/FacetBase.v8.sol @@ -14,30 +14,20 @@ import {PocoStorageLib} from "../libs/PocoStorageLib.v8.sol"; */ abstract contract FacetBase { // 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 + 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 // 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; + address internal constant KITTY_ADDRESS = 0x99c2268479b93fDe36232351229815DF80837e23; // Used with ERC-734 Key Manager identity contract for authorization management. - uint256 public constant GROUPMEMBER_PURPOSE = 4; - - modifier onlyOwner() { - require(_msgSender() == owner(), "Ownable: caller is not the owner"); - _; - } - - function owner() public view returns (address) { - // Make an external call to delegatecall the OwnershipFacet. - return IERC5313(address(this)).owner(); - } + uint256 internal constant GROUPMEMBER_PURPOSE = 4; function _msgSender() internal view returns (address) { return msg.sender; diff --git a/contracts/facets/IexecAccessorsFacet.sol b/contracts/facets/IexecAccessorsFacet.sol deleted file mode 100644 index f81003632..000000000 --- a/contracts/facets/IexecAccessorsFacet.sol +++ /dev/null @@ -1,176 +0,0 @@ -// SPDX-FileCopyrightText: 2020-2025 IEXEC BLOCKCHAIN TECH -// SPDX-License-Identifier: Apache-2.0 - -pragma solidity ^0.6.0; -pragma experimental ABIEncoderV2; - -import "./FacetBase.sol"; -import "../interfaces/IexecAccessors.sol"; -import {PocoStorageLib} from "../libs/PocoStorageLib.sol"; - -contract IexecAccessorsFacet is IexecAccessors, FacetBase { - function name() external view override returns (string memory) { - PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage(); - return $.m_name; - } - - function symbol() external view override returns (string memory) { - PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage(); - return $.m_symbol; - } - - function decimals() external view override returns (uint8) { - PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage(); - return $.m_decimals; - } - - function totalSupply() external view override returns (uint256) { - PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage(); - return $.m_totalSupply; - } - - function balanceOf(address account) external view override returns (uint256) { - PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage(); - return $.m_balances[account]; - } - - function frozenOf(address account) external view override returns (uint256) { - PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage(); - return $.m_frozens[account]; - } - - function allowance(address account, address spender) external view override returns (uint256) { - PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage(); - return $.m_allowances[account][spender]; - } - - function viewAccount( - address account - ) external view override returns (IexecLibCore_v5.Account memory) { - PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage(); - return IexecLibCore_v5.Account($.m_balances[account], $.m_frozens[account]); - } - - function token() external view override returns (address) { - PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage(); - return address($.m_baseToken); - } - - function viewDeal( - bytes32 _id - ) external view override returns (IexecLibCore_v5.Deal memory deal) { - PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage(); - return $.m_deals[_id]; - } - - function viewConsumed(bytes32 _id) external view override returns (uint256 consumed) { - PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage(); - return $.m_consumed[_id]; - } - - function viewPresigned(bytes32 _id) external view override returns (address signer) { - PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage(); - return $.m_presigned[_id]; - } - - function viewTask( - bytes32 _taskid - ) external view override returns (IexecLibCore_v5.Task memory) { - PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage(); - return $.m_tasks[_taskid]; - } - - function viewContribution( - bytes32 _taskid, - address _worker - ) external view override returns (IexecLibCore_v5.Contribution memory) { - PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage(); - return $.m_contributions[_taskid][_worker]; - } - - function viewScore(address _worker) external view override returns (uint256) { - PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage(); - return $.m_workerScores[_worker]; - } - - function resultFor(bytes32 id) external view override returns (bytes memory) { - PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage(); - IexecLibCore_v5.Task storage task = $.m_tasks[id]; - require(task.status == IexecLibCore_v5.TaskStatusEnum.COMPLETED, "task-pending"); - return task.resultsCallback; // Expansion - result separation - } - - function viewCategory( - uint256 _catid - ) external view override returns (IexecLibCore_v5.Category memory category) { - PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage(); - return $.m_categories[_catid]; - } - - function countCategory() external view override returns (uint256 count) { - PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage(); - return $.m_categories.length; - } - - function appregistry() external view override returns (IRegistry) { - PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage(); - return $.m_appregistry; - } - - function datasetregistry() external view override returns (IRegistry) { - PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage(); - return $.m_datasetregistry; - } - - function workerpoolregistry() external view override returns (IRegistry) { - PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage(); - return $.m_workerpoolregistry; - } - - function teebroker() external view override returns (address) { - PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage(); - return $.m_teebroker; - } - - function callbackgas() external view override returns (uint256) { - PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage(); - return $.m_callbackgas; - } - - function contribution_deadline_ratio() external view override returns (uint256) { - return CONTRIBUTION_DEADLINE_RATIO; - } - - function reveal_deadline_ratio() external view override returns (uint256) { - return REVEAL_DEADLINE_RATIO; - } - - function final_deadline_ratio() external view override returns (uint256) { - return FINAL_DEADLINE_RATIO; - } - - function workerpool_stake_ratio() external view override returns (uint256) { - return WORKERPOOL_STAKE_RATIO; - } - - function kitty_ratio() external view override returns (uint256) { - return KITTY_RATIO; - } - - function kitty_min() external view override returns (uint256) { - return KITTY_MIN; - } - - function kitty_address() external view override returns (address) { - return KITTY_ADDRESS; - } - - function groupmember_purpose() external view override returns (uint256) { - return GROUPMEMBER_PURPOSE; - } - - function eip712domain_separator() external view override returns (bytes32) { - PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage(); - return $.m_eip712DomainSeparator; - } -} diff --git a/scripts/upgrades/accessors/deploy-and-update-accessor-facet.ts b/scripts/upgrades/accessors/deploy-and-update-accessor-facet.ts index 6d62cc1a1..bb21614aa 100644 --- a/scripts/upgrades/accessors/deploy-and-update-accessor-facet.ts +++ b/scripts/upgrades/accessors/deploy-and-update-accessor-facet.ts @@ -57,7 +57,9 @@ import { printFunctions } from '../upgrade-helper'; const newFacetFactory = new IexecPocoAccessorsFacet__factory(iexecLibOrders); const newFacetAddress = await factoryDeployer.deployContract(newFacetFactory); - console.log('\n=== Step 2: Remove old facets (remove all functions of each facet) ==='); + console.log( + '\n=== Step 2: Remove old facets (remove all functions of old accessors facets) ===', + ); const diamondLoupe = DiamondLoupeFacet__factory.connect(diamondProxyAddress, account); const currentFacets = await diamondLoupe.facets(); @@ -67,17 +69,37 @@ import { printFunctions } from '../upgrade-helper'; console.log(` ${facet.facetAddress}: ${facet.functionSelectors.length} functions`); }); - const oldAccessorFacets = [ - '0xEa232be31ab0112916505Aeb7A2a94b5571DCc6b', //IexecAccessorsFacet - '0xeb40697b275413241d9b31dE568C98B3EA12FFF0', //IexecPocoAccessorsFacet - ]; - console.log('Diamond functions before upgrade:'); await printFunctions(diamondProxyAddress); const removalCuts: IDiamond.FacetCutStruct[] = []; + const constantFunctionSignatures = [ + 'CONTRIBUTION_DEADLINE_RATIO()', + 'FINAL_DEADLINE_RATIO()', + 'GROUPMEMBER_PURPOSE()', + 'KITTY_ADDRESS()', + 'KITTY_MIN()', + 'KITTY_RATIO()', + 'REVEAL_DEADLINE_RATIO()', + 'WORKERPOOL_STAKE_RATIO()', + ]; + const constantFunctionsToRemove = constantFunctionSignatures.map((sig) => + ethers.id(sig).slice(0, 10), + ); + console.log( + `Removing specific constant functions from diamond Proxy - will remove ${constantFunctionsToRemove.length} specific constant functions`, + ); + removalCuts.push({ + facetAddress: ZeroAddress, + action: FacetCutAction.Remove, + functionSelectors: constantFunctionsToRemove, + }); - // Remove ALL functions from the old accessor facets using diamondLoupe.facetFunctionSelectors() + const oldAccessorFacets = [ + '0xEa232be31ab0112916505Aeb7A2a94b5571DCc6b', //IexecAccessorsFacet + '0xeb40697b275413241d9b31dE568C98B3EA12FFF0', //IexecPocoAccessorsFacet + ]; + // Remove ALL functions from the old accessor facets using diamondLoupe.facetFunctionSelectors() except of constant founctions for (const facetAddress of oldAccessorFacets) { const selectors = await diamondLoupe.facetFunctionSelectors(facetAddress); if (selectors.length > 0) { diff --git a/test/byContract/IexecAccessors/IexecAccessors.test.ts b/test/byContract/iexecPocoAccessors/IexecPocoAccessors.test.ts similarity index 99% rename from test/byContract/IexecAccessors/IexecAccessors.test.ts rename to test/byContract/iexecPocoAccessors/IexecPocoAccessors.test.ts index c65f79ff4..a6238244c 100644 --- a/test/byContract/IexecAccessors/IexecAccessors.test.ts +++ b/test/byContract/iexecPocoAccessors/IexecPocoAccessors.test.ts @@ -48,7 +48,7 @@ let [requester, appProvider, datasetProvider, scheduler, worker1, anyone]: Signe let ordersAssets: OrdersAssets; let ordersPrices: OrdersPrices; -describe('IexecAccessors', async () => { +describe('IexecPocoAccessors', async () => { beforeEach('Deploy', async () => { // Deploy all contracts proxyAddress = await loadHardhatFixtureDeployment(); diff --git a/utils/tools.ts b/utils/tools.ts index 3d3ba3eef..d3033fbe8 100644 --- a/utils/tools.ts +++ b/utils/tools.ts @@ -11,7 +11,7 @@ export function compactSignature(signature: string): string { } export function bigintToAddress(bigint: bigint) { - return ethers.getAddress(ethers.toBeHex(bigint)); + return ethers.getAddress(ethers.toBeHex(bigint, 20)); } export function minBigInt(a: bigint, b: bigint) {