Skip to content

Commit efa1d22

Browse files
authored
fix: Fix build with new storage layout (#237)
2 parents 1e89ce3 + 72ab9d8 commit efa1d22

File tree

12 files changed

+72
-29
lines changed

12 files changed

+72
-29
lines changed

.prettierignore

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
2+
artifacts/
3+
audit/
4+
build/
5+
cache/
6+
coverage/
7+
coverage.json
8+
deployments/
9+
node_modules/
10+
typechain/

contracts/modules/facets/IexecAccessorsABILegacyFacet.sol

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@ contract IexecAccessorsABILegacyFacet is IexecAccessorsABILegacy, FacetBase {
8282
bytes memory
8383
)
8484
{
85-
PocoStorage storage $ = getPocoStorage();
86-
IexecLibCore_v5.Task memory task = $.m_tasks[_taskid];
85+
/// @dev Using $.m_tasks causes "Stack too deep" error.
86+
IexecLibCore_v5.Task memory task = getPocoStorage().m_tasks[_taskid];
8787
return (
8888
task.status,
8989
task.dealid,
@@ -110,9 +110,7 @@ contract IexecAccessorsABILegacyFacet is IexecAccessorsABILegacy, FacetBase {
110110
returns (IexecLibCore_v5.ContributionStatusEnum, bytes32, bytes32, address)
111111
{
112112
PocoStorage storage $ = getPocoStorage();
113-
IexecLibCore_v5.Contribution memory contribution = $.m_contributions[
114-
_taskid
115-
][_worker];
113+
IexecLibCore_v5.Contribution memory contribution = $.m_contributions[_taskid][_worker];
116114
return (
117115
contribution.status,
118116
contribution.resultHash,

contracts/modules/facets/IexecPocoBoostFacet.sol

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -406,13 +406,18 @@ contract IexecPocoBoostFacet is
406406
"PocoBoost: Invalid contribution authorization signature"
407407
);
408408
address target = deal.callback;
409-
bytes32 resultDigest = keccak256(target == address(0) ? results : resultsCallback);
410409
// Check enclave signature
411410
require(
412411
enclaveChallenge == address(0) ||
413412
_verifySignatureOfEthSignedMessage(
414413
enclaveChallenge,
415-
abi.encodePacked(msg.sender, taskId, resultDigest),
414+
abi.encodePacked(
415+
msg.sender,
416+
taskId,
417+
// Result digest
418+
/// @dev extracting it in a variable causes "Stack too deep" error.
419+
keccak256(target == address(0) ? results : resultsCallback)
420+
),
416421
enclaveSign
417422
),
418423
"PocoBoost: Invalid enclave signature"
@@ -469,10 +474,10 @@ contract IexecPocoBoostFacet is
469474
if (target != address(0)) {
470475
require(resultsCallback.length > 0, "PocoBoost: Callback requires data");
471476
/*
472-
* The caller must be able to complete the task even if the external
473-
* call reverts.
477+
* The caller (worker) must be able to complete the task even if the external
478+
* call reverts, hence we don't check the success of the call.
479+
* See Halborn audit report for details.
474480
*/
475-
// See Halborn audit report for details
476481
//slither-disable-next-line low-level-calls
477482
(bool success, ) = target.call{gas: $.m_callbackgas}(
478483
abi.encodeCall(IOracleConsumer.receiveResult, (taskId, resultsCallback))

deploy/0_deploy.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ export default async function deploy() {
181181
rlcInstanceAddress,
182182
'Staked RLC',
183183
'SRLC',
184-
9, // TODO: generic ?
184+
9,
185185
appRegistryAddress,
186186
datasetRegistryAddress,
187187
workerpoolRegistryAddress,

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"test:native": "npm run clean && TEST__IS_NATIVE_CHAIN=true npx hardhat test test/byContract/IexecEscrow/IexecEscrowNative.test.ts",
2020
"coverage": "npx hardhat coverage",
2121
"verify": "npx hardhat verify",
22-
"format": "npx prettier --write ./contracts/**/*.sol",
22+
"format": "npx prettier --write '**/*.{js,ts,sol,json,yml}'",
2323
"uml": "npm run sol-to-uml && npm run puml-to-links && npm run storage-to-diagrams",
2424
"sol-to-uml": "npx zx scripts/tools/sol-to-uml.mjs",
2525
"puml-to-links": "npx zx scripts/tools/puml-to-links.mjs",
@@ -86,4 +86,4 @@
8686
"sol2uml": "After 2.5.19, see https://github.com/naddison36/sol2uml/issues/183",
8787
"solidity-coverage": "Fixing Hardhat's solidity-coverage: TypeError: provider.send is not a function"
8888
}
89-
}
89+
}

test/byContract/IexecAccessors/IexecAccessors.test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,8 +209,7 @@ describe('IexecAccessors', async () => {
209209
expect(contribution.weight).to.equal(1);
210210
});
211211

212-
it('viewScore', async function () {
213-
// TODO
212+
it.skip('[TODO] viewScore', async function () {
214213
expect(await iexecPoco.viewScore(worker1.address)).to.equal(0);
215214
});
216215

test/byContract/IexecConfiguration/IexecConfiguration.test.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
IexecInterfaceNative__factory,
1414
} from '../../../typechain';
1515
import { getIexecAccounts } from '../../../utils/poco-tools';
16+
import { getPocoStorageSlotLocation } from '../../../utils/proxy-tools';
1617
import { loadHardhatFixtureDeployment } from '../../utils/hardhat-fixture-deployer';
1718
import { hashDomain } from '../../utils/utils';
1819

@@ -113,20 +114,21 @@ describe('IexecConfiguration', async () => {
113114
});
114115

115116
describe('Import score', () => {
116-
it('[TODO] Should import score', async () => {
117-
// Not tested
118-
});
117+
it.skip('[TODO] Should import score', async () => {});
118+
119119
it('Should not import score when no v3_iexecHub configured', async () => {
120120
await expect(iexecPoco.importScore(worker.address)).to.be.revertedWithoutReason();
121121
});
122+
122123
it('Should not import score when already imported', async () => {
123124
const workerScoreImportedSlot = ethers.stripZerosLeft(
124125
ethers.keccak256(
125126
ethers.AbiCoder.defaultAbiCoder().encode(
126127
['address', 'uint256'],
127128
[
128129
worker.address,
129-
23, // Slot index of m_v3_scoreImported in Store
130+
// 23 is the slot index of m_v3_scoreImported in Store
131+
getPocoStorageSlotLocation(23n),
130132
],
131133
),
132134
),
@@ -203,7 +205,7 @@ describe('IexecConfiguration', async () => {
203205
async function setDomainSeparatorInStorage(domainSeparator: string) {
204206
await setStorageAt(
205207
proxyAddress,
206-
'0x0b', // Slot index of EIP712DOMAIN_SEPARATOR in Store
208+
getPocoStorageSlotLocation(11n), // 11 is the slot index of EIP712DOMAIN_SEPARATOR in Store
207209
domainSeparator,
208210
);
209211
// Double check the update of the domain separator happened

test/byContract/IexecEscrow/IexecEscrowNative.test.ts

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { ethers } from 'hardhat';
1010
import { IexecInterfaceNative, IexecInterfaceNative__factory } from '../../../typechain';
1111
import config from '../../../utils/config';
1212
import { getIexecAccounts } from '../../../utils/poco-tools';
13+
import { getPocoStorageSlotLocation } from '../../../utils/proxy-tools';
1314
import { loadHardhatFixtureDeployment } from '../../utils/hardhat-fixture-deployer';
1415
import { setZeroAddressBalance } from '../../utils/utils';
1516

@@ -75,7 +76,6 @@ if (config.isNativeChain()) {
7576
});
7677
});
7778

78-
// TODO 'Should deposit with zero value'
7979
describe('Deposit', () => {
8080
it('Should deposit native tokens', async () => {
8181
expect(await iexecPocoAsAccountA.deposit.staticCall(...depositArgs)).to.be.true;
@@ -105,6 +105,16 @@ if (config.isNativeChain()) {
105105
.withArgs(AddressZero, accountA.address, depositAmount);
106106
});
107107

108+
it('Should deposit amount zero', async () => {
109+
expect(await iexecPocoAsAccountA.deposit.staticCall({ value: 0 })).to.be.true;
110+
const tx = iexecPocoAsAccountA.deposit({ value: 0 });
111+
await expect(tx).to.changeEtherBalances([accountA, iexecPoco], [0, 0]);
112+
await expect(tx).to.changeTokenBalances(iexecPoco, [accountA], [0]);
113+
await expect(tx)
114+
.to.emit(iexecPoco, 'Transfer')
115+
.withArgs(AddressZero, accountA.address, 0);
116+
});
117+
108118
it('Should not deposit native tokens when caller is address 0', async () => {
109119
const zeroAddressSigner = await ethers.getImpersonatedSigner(ZeroAddress);
110120
const iexecPocoAsAddress0 = iexecPoco.connect(zeroAddressSigner);
@@ -214,7 +224,6 @@ if (config.isNativeChain()) {
214224
});
215225
});
216226

217-
// TODO 'Should withdraw with zero value'
218227
describe('Withdraw', () => {
219228
it('Should withdraw native tokens', async () => {
220229
await iexecPocoAsAccountA.deposit(...depositArgs);
@@ -231,6 +240,19 @@ if (config.isNativeChain()) {
231240
.withArgs(accountA.address, AddressZero, withdrawAmount);
232241
});
233242

243+
it('Should withdraw amount zero', async () => {
244+
await iexecPocoAsAccountA.deposit(...depositArgs);
245+
expect(await iexecPocoAsAccountA.withdraw.staticCall(0)).to.be.true;
246+
const tx = iexecPocoAsAccountA.withdraw(0);
247+
await expect(tx).to.changeEtherBalances([accountA, iexecPoco], [0, 0]);
248+
await expect(tx).to.changeTokenBalances(iexecPoco, [accountA], [0]);
249+
await expect(tx)
250+
.to.emit(iexecPoco, 'Transfer')
251+
.withArgs(accountA.address, AddressZero, 0);
252+
// User balance haven't changed.
253+
expect(await iexecPoco.balanceOf(accountA.address)).to.equal(depositAmount);
254+
});
255+
234256
it('Should not withdraw native tokens with empty balance', async () => {
235257
await expect(
236258
iexecPocoAsAccountA.withdraw(...withdrawArg),
@@ -291,7 +313,7 @@ if (config.isNativeChain()) {
291313
const expectedDelta = 5n;
292314
await setStorageAt(
293315
proxyAddress,
294-
'0x07', // Slot index of `m_totalSupply` in Store
316+
getPocoStorageSlotLocation(7n), // 7 is the slot index of `m_totalSupply` in Store
295317
ethers.toBeHex(initTotalSupply - expectedDelta),
296318
);
297319
expect(await iexecPoco.totalSupply()).to.equal(

test/byContract/IexecPoco/IexecPoco1.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -942,7 +942,7 @@ describe('IexecPoco1', () => {
942942
// const appOrderConsumedSlotIndex = ethers.keccak256(
943943
// ethers.concat([
944944
// appOrderHash, // key in the mapping.
945-
// '0x12', // m_consumed mapping index.
945+
// getPocoStorageSlotLocation(12n), // 12 is the slot index of `m_consumed` in Store.
946946
// ])
947947
// );
948948
// // Set order as fully consumed.

test/byContract/IexecPoco/IexecPoco2-contribute-and-finalize.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ describe('IexecPoco2#contributeAndFinalize', () => {
350350
).to.be.revertedWithoutReason(); // require#2
351351
});
352352

353-
it('Should not contributeAndFinalize when someone else has already contributed', async () => {
353+
it.skip('[TODO] Should not contributeAndFinalize when someone else has already contributed', async () => {
354354
// TODO require#3
355355
});
356356

0 commit comments

Comments
 (0)