Skip to content

Commit b36b4a8

Browse files
reednaaggonzalez94jsanmigimeno
authored
Upgrade compact version to post audit fixes (openintentsframework#6)
* Initial documentation pass of everything except oracles and input settlers and readme * typos * Complete the contracts and libraries * Update readme * grammar * Output chain instaed of destination chain * Apply suggestions from code review Co-authored-by: Gustavo Gonzalez <ggonzalezsomer@gmail.com> * Rename IOIFCallback to IOpenIntentCallback * Rename inputs callback and fillBatch * delete unused tests * Upgrade compact version to post audit fixes * Apply suggestions from code review Co-authored-by: jsanmigimeno <8038323+jsanmigimeno@users.noreply.github.com> --------- Co-authored-by: Gustavo Gonzalez <ggonzalezsomer@gmail.com> Co-authored-by: jsanmigimeno <8038323+jsanmigimeno@users.noreply.github.com>
1 parent a743143 commit b36b4a8

File tree

8 files changed

+83
-67
lines changed

8 files changed

+83
-67
lines changed

lib/the-compact

Submodule the-compact updated 101 files

snapshots/inputSettler.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
"7683open": "86728",
88
"7683openFor": "134449",
99
"BasePurchaseOrder": "137111",
10-
"CompactFinaliseFor": "137488",
11-
"CompactFinaliseSelf": "128908",
12-
"CompactFinaliseTo": "128908",
10+
"CompactFinaliseFor": "139548",
11+
"CompactFinaliseSelf": "130968",
12+
"CompactFinaliseTo": "130968",
1313
"IntegrationCoinFill": "112123",
14-
"IntegrationCompactFinaliseSelf": "125571",
14+
"IntegrationCompactFinaliseSelf": "127601",
1515
"IntegrationWormholeReceiveMessage": "73550",
1616
"IntegrationWormholeSubmit": "42532",
1717
"maxTimestamp1": "505",

src/input/7683/InputSettler7683.sol

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -326,12 +326,12 @@ contract InputSettler7683 is BaseInputSettler, IInputSettler7683 {
326326
bytes32 payloadHash = _proofPayloadHash(orderId, solvers[i], outputFilledAt, output);
327327

328328
uint256 chainId = output.chainId;
329-
bytes32 remoteOracle = output.oracle;
329+
bytes32 outputOracle = output.oracle;
330330
bytes32 outputSettler = output.settler;
331331
assembly ("memory-safe") {
332332
let offset := add(add(proofSeries, 0x20), mul(i, 0x80))
333333
mstore(offset, chainId)
334-
mstore(add(offset, 0x20), remoteOracle)
334+
mstore(add(offset, 0x20), outputOracle)
335335
mstore(add(offset, 0x40), outputSettler)
336336
mstore(add(offset, 0x60), payloadHash)
337337
}
@@ -365,12 +365,12 @@ contract InputSettler7683 is BaseInputSettler, IInputSettler7683 {
365365
bytes32 payloadHash = _proofPayloadHash(orderId, solver, outputFilledAt, output);
366366

367367
uint256 chainId = output.chainId;
368-
bytes32 remoteOracle = output.oracle;
368+
bytes32 outputOracle = output.oracle;
369369
bytes32 outputSettler = output.settler;
370370
assembly ("memory-safe") {
371371
let offset := add(add(proofSeries, 0x20), mul(i, 0x80))
372372
mstore(offset, chainId)
373-
mstore(add(offset, 0x20), remoteOracle)
373+
mstore(add(offset, 0x20), outputOracle)
374374
mstore(add(offset, 0x40), outputSettler)
375375
mstore(add(offset, 0x60), payloadHash)
376376
}

src/input/types/StandardOrderType.sol

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -77,38 +77,4 @@ library StandardOrderType {
7777
)
7878
);
7979
}
80-
81-
// --- Compact Hash --- //
82-
83-
bytes constant BATCH_COMPACT_TYPE_STUB = bytes(
84-
"BatchCompact(address arbiter,address sponsor,uint256 nonce,uint256 expires,uint256[2][] idsAndAmounts,Mandate mandate)"
85-
);
86-
bytes constant BATCH_COMPACT_TYPE = abi.encodePacked(BATCH_COMPACT_TYPE_STUB, CATALYST_WITNESS_TYPE);
87-
bytes32 constant BATCH_COMPACT_TYPE_HASH = keccak256(BATCH_COMPACT_TYPE);
88-
89-
function compactHash(
90-
address arbiter,
91-
address sponsor,
92-
uint256 nonce,
93-
uint256 expires,
94-
StandardOrder calldata order
95-
) internal pure returns (bytes32) {
96-
return keccak256(
97-
abi.encode(
98-
BATCH_COMPACT_TYPE_HASH,
99-
arbiter,
100-
sponsor,
101-
nonce,
102-
expires,
103-
hashIdsAndAmounts(order.inputs),
104-
witnessHash(order)
105-
)
106-
);
107-
}
108-
109-
function hashIdsAndAmounts(
110-
uint256[2][] calldata inputs
111-
) internal pure returns (bytes32) {
112-
return keccak256(abi.encodePacked(inputs));
113-
}
11480
}

test/input/compact/InputSettlerCompact.base.t.sol

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,36 @@ contract InputSettlerCompactTestBase is Test {
142142
messages.storeGuardianSetPub(guardianSet, uint32(0));
143143
}
144144

145+
struct Lock {
146+
bytes12 lockTag;
147+
address token;
148+
uint256 amount;
149+
}
150+
151+
function getLockHash(
152+
uint256[2][] memory idsAndAmounts
153+
) public pure returns (bytes32) {
154+
bytes32[] memory lockHashes = new bytes32[](idsAndAmounts.length);
155+
for (uint256 i; i < idsAndAmounts.length; ++i) {
156+
uint256[2] memory idsAndAmount = idsAndAmounts[i];
157+
Lock memory lock = Lock({
158+
lockTag: bytes12(bytes32(idsAndAmount[0])),
159+
token: address(uint160(idsAndAmount[0])),
160+
amount: idsAndAmount[1]
161+
});
162+
lockHashes[i] = keccak256(
163+
abi.encode(
164+
keccak256(bytes("Lock(bytes12 lockTag,address token,uint256 amount)")),
165+
lock.lockTag,
166+
lock.token,
167+
lock.amount
168+
)
169+
);
170+
}
171+
172+
return keccak256(abi.encodePacked(lockHashes));
173+
}
174+
145175
function getCompactBatchWitnessSignature(
146176
uint256 privateKey,
147177
address arbiter,
@@ -159,14 +189,14 @@ contract InputSettlerCompactTestBase is Test {
159189
abi.encode(
160190
keccak256(
161191
bytes(
162-
"BatchCompact(address arbiter,address sponsor,uint256 nonce,uint256 expires,uint256[2][] idsAndAmounts,Mandate mandate)Mandate(uint32 fillDeadline,address localOracle,MandateOutput[] outputs)MandateOutput(bytes32 oracle,bytes32 filler,uint256 chainId,bytes32 token,uint256 amount,bytes32 recipient,bytes call,bytes context)"
192+
"BatchCompact(address arbiter,address sponsor,uint256 nonce,uint256 expires,Lock[] commitments,Mandate mandate)Lock(bytes12 lockTag,address token,uint256 amount)Mandate(uint32 fillDeadline,address localOracle,MandateOutput[] outputs)MandateOutput(bytes32 oracle,bytes32 filler,uint256 chainId,bytes32 token,uint256 amount,bytes32 recipient,bytes call,bytes context)"
163193
)
164194
),
165195
arbiter,
166196
sponsor,
167197
nonce,
168198
expires,
169-
keccak256(abi.encodePacked(idsAndAmounts)),
199+
getLockHash(idsAndAmounts),
170200
witness
171201
)
172202
)
@@ -279,7 +309,7 @@ contract InputSettlerCompactTestBase is Test {
279309
address alloca
280310
) internal pure returns (uint256 id) {
281311
// Derive the allocator ID for the provided allocator address.
282-
uint96 allocatorId = IdLib.usingAllocatorId(alloca);
312+
uint96 allocatorId = IdLib.toAllocatorId(alloca);
283313

284314
// Derive resource lock ID (pack scope, reset period, allocator ID, & token).
285315
id = (

test/input/compact/InputSettlerCompact.t.sol

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,6 @@ contract InputSettlerCompactTest is InputSettlerCompactTestBase {
2828

2929
address owner;
3030

31-
function compactHash(
32-
address arbiter,
33-
address sponsor,
34-
uint256 nonce,
35-
uint256 expires,
36-
StandardOrder calldata order
37-
) external pure returns (bytes32) {
38-
return StandardOrderType.compactHash(arbiter, sponsor, nonce, expires, order);
39-
}
40-
4131
// -- Units Tests -- //
4232

4333
error InvalidProofSeries();

test/integration/SettlerCompact.crosschain.t.sol

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// SPDX-License-Identifier: MIT
22
pragma solidity ^0.8.22;
33

4-
import { Test } from "forge-std/Test.sol";
4+
import { Test, console } from "forge-std/Test.sol";
55

66
import { TheCompact } from "the-compact/src/TheCompact.sol";
77
import { SimpleAllocator } from "the-compact/src/examples/allocator/SimpleAllocator.sol";
@@ -142,6 +142,36 @@ contract InputSettlerCompactTestCrossChain is Test {
142142
messages.storeGuardianSetPub(guardianSet, uint32(0));
143143
}
144144

145+
struct Lock {
146+
bytes12 lockTag;
147+
address token;
148+
uint256 amount;
149+
}
150+
151+
function getLockHash(
152+
uint256[2][] memory idsAndAmounts
153+
) public pure returns (bytes32) {
154+
bytes32[] memory lockHashes = new bytes32[](idsAndAmounts.length);
155+
for (uint256 i; i < idsAndAmounts.length; ++i) {
156+
uint256[2] memory idsAndAmount = idsAndAmounts[i];
157+
Lock memory lock = Lock({
158+
lockTag: bytes12(bytes32(idsAndAmount[0])),
159+
token: address(uint160(idsAndAmount[0])),
160+
amount: idsAndAmount[1]
161+
});
162+
lockHashes[i] = keccak256(
163+
abi.encode(
164+
keccak256(bytes("Lock(bytes12 lockTag,address token,uint256 amount)")),
165+
lock.lockTag,
166+
lock.token,
167+
lock.amount
168+
)
169+
);
170+
}
171+
172+
return keccak256(abi.encodePacked(lockHashes));
173+
}
174+
145175
function getCompactBatchWitnessSignature(
146176
uint256 privateKey,
147177
address arbiter,
@@ -159,14 +189,14 @@ contract InputSettlerCompactTestCrossChain is Test {
159189
abi.encode(
160190
keccak256(
161191
bytes(
162-
"BatchCompact(address arbiter,address sponsor,uint256 nonce,uint256 expires,uint256[2][] idsAndAmounts,Mandate mandate)Mandate(uint32 fillDeadline,address localOracle,MandateOutput[] outputs)MandateOutput(bytes32 oracle,bytes32 filler,uint256 chainId,bytes32 token,uint256 amount,bytes32 recipient,bytes call,bytes context)"
192+
"BatchCompact(address arbiter,address sponsor,uint256 nonce,uint256 expires,Lock[] commitments,Mandate mandate)Lock(bytes12 lockTag,address token,uint256 amount)Mandate(uint32 fillDeadline,address localOracle,MandateOutput[] outputs)MandateOutput(bytes32 oracle,bytes32 filler,uint256 chainId,bytes32 token,uint256 amount,bytes32 recipient,bytes call,bytes context)"
163193
)
164194
),
165195
arbiter,
166196
sponsor,
167197
nonce,
168198
expires,
169-
keccak256(abi.encodePacked(idsAndAmounts)),
199+
getLockHash(idsAndAmounts),
170200
witness
171201
)
172202
)

test/libs/OutputEncodingLib.t.sol

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ contract MandateOutputEncodingLibTest is Test {
5555
// The goal of this output is to fill all bytes such that no bytes are left empty.
5656
// This allows for better comparison to other vm implementations incase something is wrong.
5757
MandateOutput memory output = MandateOutput({
58-
oracle: keccak256(bytes("remoteOracle")),
58+
oracle: keccak256(bytes("outputOracle")),
5959
settler: keccak256(bytes("outputSettler")),
6060
chainId: uint256(keccak256(bytes("chainId"))),
6161
token: keccak256(bytes("token")),
@@ -70,7 +70,7 @@ contract MandateOutputEncodingLibTest is Test {
7070
assertEq(encodedOutput, encodedOutputMemory);
7171
assertEq(
7272
encodedOutput,
73-
hex"2e7527e20e9b97ff3a5ce16d17d50dd1fac8c30234ec6b506d9f3432963d59ea6aa1b29f675730a3d41062603d83a385b254be1e9338406698f9ea0702586f9e8ed9144e2f2122812934305f889c544efe55db33a5fd4b235aaab787c3f913d49b9b0454cadcb5884dd3faa6ba975da4d2459aa3f11d31291a25a8358f84946d89c4783cb6cc307f98e95f2d5d5d8647bdb3d4bdd087209374f187b38e098895811085f5b5d1b29598e73ca51de3d712f5d3103ad50e22dc1f4d3ff1559d511500000000"
73+
hex"4f9c60d16f18ede78fc0a6cfbe7ef0072cdda8cbb9b0b90c5d3578541cb3c1616aa1b29f675730a3d41062603d83a385b254be1e9338406698f9ea0702586f9e8ed9144e2f2122812934305f889c544efe55db33a5fd4b235aaab787c3f913d49b9b0454cadcb5884dd3faa6ba975da4d2459aa3f11d31291a25a8358f84946d89c4783cb6cc307f98e95f2d5d5d8647bdb3d4bdd087209374f187b38e098895811085f5b5d1b29598e73ca51de3d712f5d3103ad50e22dc1f4d3ff1559d511500000000"
7474
);
7575

7676
output.call = abi.encodePacked(keccak256(hex""), keccak256(hex"01"), bytes3(0x010203));
@@ -83,13 +83,13 @@ contract MandateOutputEncodingLibTest is Test {
8383
assertEq(encodedOutput, encodedOutputMemory);
8484
assertEq(
8585
encodedOutput,
86-
hex"2e7527e20e9b97ff3a5ce16d17d50dd1fac8c30234ec6b506d9f3432963d59ea6aa1b29f675730a3d41062603d83a385b254be1e9338406698f9ea0702586f9e8ed9144e2f2122812934305f889c544efe55db33a5fd4b235aaab787c3f913d49b9b0454cadcb5884dd3faa6ba975da4d2459aa3f11d31291a25a8358f84946d89c4783cb6cc307f98e95f2d5d5d8647bdb3d4bdd087209374f187b38e098895811085f5b5d1b29598e73ca51de3d712f5d3103ad50e22dc1f4d3ff1559d51150043c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a4705fe7f977e71dba2ea1a68e21057beebb9be2ac30c6410aa38d4f3fbe41dcffd20102030084f2ee15ea639b73fa3db9b34a245bdfa015c260c598b211bf05a1ecc4b3e3b4f269c322e3248a5dfc29d73c5b0553b0185a35cd5bb6386747517ef7e53b15e287f343681465b9efe82c933c3e8748c70cb8aa06539c361de20f72eac04e766393dbb8d0f4c497851a5043c6363657698cb1387682cac2f786c731f8936109d79501020304"
86+
hex"4f9c60d16f18ede78fc0a6cfbe7ef0072cdda8cbb9b0b90c5d3578541cb3c1616aa1b29f675730a3d41062603d83a385b254be1e9338406698f9ea0702586f9e8ed9144e2f2122812934305f889c544efe55db33a5fd4b235aaab787c3f913d49b9b0454cadcb5884dd3faa6ba975da4d2459aa3f11d31291a25a8358f84946d89c4783cb6cc307f98e95f2d5d5d8647bdb3d4bdd087209374f187b38e098895811085f5b5d1b29598e73ca51de3d712f5d3103ad50e22dc1f4d3ff1559d51150043c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a4705fe7f977e71dba2ea1a68e21057beebb9be2ac30c6410aa38d4f3fbe41dcffd20102030084f2ee15ea639b73fa3db9b34a245bdfa015c260c598b211bf05a1ecc4b3e3b4f269c322e3248a5dfc29d73c5b0553b0185a35cd5bb6386747517ef7e53b15e287f343681465b9efe82c933c3e8748c70cb8aa06539c361de20f72eac04e766393dbb8d0f4c497851a5043c6363657698cb1387682cac2f786c731f8936109d79501020304"
8787
);
8888
}
8989

9090
function test_revert_encodeMandateOutput_RemoteCallOutOfRange() external {
9191
MandateOutput memory output = MandateOutput({
92-
oracle: keccak256(bytes("remoteOracle")),
92+
oracle: keccak256(bytes("outputOracle")),
9393
settler: keccak256(bytes("outputSettler")),
9494
chainId: uint256(keccak256(bytes("chainId"))),
9595
token: keccak256(bytes("token")),
@@ -112,7 +112,7 @@ contract MandateOutputEncodingLibTest is Test {
112112

113113
function test_revert_encodeMandateOutput_FulfillmentContextCallOutOfRange() external {
114114
MandateOutput memory output = MandateOutput({
115-
oracle: keccak256(bytes("remoteOracle")),
115+
oracle: keccak256(bytes("outputOracle")),
116116
settler: keccak256(bytes("outputSettler")),
117117
chainId: uint256(keccak256(bytes("chainId"))),
118118
token: keccak256(bytes("token")),
@@ -146,7 +146,7 @@ contract MandateOutputEncodingLibTest is Test {
146146
bytes memory fulfillmentContext = hex"";
147147

148148
MandateOutput memory output = MandateOutput({
149-
oracle: keccak256(bytes("remoteOracle")),
149+
oracle: keccak256(bytes("outputOracle")),
150150
settler: keccak256(bytes("outputSettler")),
151151
chainId: uint256(keccak256(bytes("chainId"))),
152152
token: token,
@@ -200,7 +200,7 @@ contract MandateOutputEncodingLibTest is Test {
200200
bytes memory fulfillmentContext = hex"";
201201

202202
MandateOutput memory output = MandateOutput({
203-
oracle: keccak256(bytes("remoteOracle")),
203+
oracle: keccak256(bytes("outputOracle")),
204204
settler: keccak256(bytes("outputSettler")),
205205
chainId: uint256(keccak256(bytes("chainId"))),
206206
token: token,
@@ -240,7 +240,7 @@ contract MandateOutputEncodingLibTest is Test {
240240
bytes memory fulfillmentContext = new bytes(65536 - 1);
241241

242242
MandateOutput memory output = MandateOutput({
243-
oracle: keccak256(bytes("remoteOracle")),
243+
oracle: keccak256(bytes("outputOracle")),
244244
settler: keccak256(bytes("outputSettler")),
245245
chainId: uint256(keccak256(bytes("chainId"))),
246246
token: token,

0 commit comments

Comments
 (0)