Skip to content

Commit ac25e50

Browse files
authored
Merge pull request #161 from Uniswap/attestable-allocator
AttestableAllocator implementation (off-chain allocator with support for 6909 transfers) NOTE: still in POC state; hasn't been reviewed or audited
2 parents e69f8d9 + 55bfdf9 commit ac25e50

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+986
-411
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
- name: Install Foundry
2424
uses: foundry-rs/foundry-toolchain@v1
2525
with:
26-
version: nightly
26+
version: v1.4.0
2727

2828
- name: Setup Node.js
2929
uses: actions/setup-node@v4

snapshots/hardhat-gas-report.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
·································|················|·····················|···············|···············|··············
3030
| BasicERC20Token · - · - · 897,332 · 3 % · - │
3131
·································|················|·····················|···············|···············|··············
32-
| TheCompact · - · - · 10,423,770 · 34.7 % · - │
32+
| TheCompact · - · - · 10,372,289 · 34.6 % · - │
3333
·································|················|·····················|···············|···············|··············
3434
| Key │
3535
·······················································································································

src/TheCompact.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ contract TheCompact is ITheCompact, ERC6909, TheCompactLogic {
290290
}
291291

292292
/// @inheritdoc ITheCompact
293-
function __benchmark(bytes32 /* salt */ ) external payable {
293+
function __benchmark(bytes32 /* salt */) external payable {
294294
_benchmark();
295295
}
296296

src/examples/allocator/AttestableAllocator.sol

Lines changed: 605 additions & 0 deletions
Large diffs are not rendered by default.

src/lib/ClaimHashFunctionCastLib.sol

Lines changed: 56 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,21 @@ library ClaimHashFunctionCastLib {
2222
* @param fnIn Function pointer to `ClaimHashLib._toGenericMultichainClaimHashAndTypehash`.
2323
* @return fnOut Modified function used in `ClaimHashLib._toMultichainClaimHashAndTypehash`.
2424
*/
25-
function usingMultichainClaim(
26-
function (uint256, uint256, function (uint256, uint256, bytes32, bytes32, uint256) internal view returns (bytes32)) internal view returns (bytes32, bytes32)
27-
fnIn
28-
)
25+
function usingMultichainClaim(function(uint256, uint256, function(uint256, uint256, bytes32, bytes32, uint256)
26+
internal
27+
view returns (bytes32))
28+
internal
29+
view returns (
30+
bytes32,
31+
bytes32
32+
) fnIn)
2933
internal
3034
pure
31-
returns (
32-
function (MultichainClaim calldata, uint256, function (uint256, uint256, bytes32, bytes32, uint256) internal view returns (bytes32)) internal view returns (bytes32, bytes32)
33-
fnOut
34-
)
35+
returns (function(MultichainClaim calldata, uint256, function(uint256, uint256, bytes32, bytes32, uint256)
36+
internal
37+
view returns (bytes32))
38+
internal
39+
view returns (bytes32, bytes32) fnOut)
3540
{
3641
assembly ("memory-safe") {
3742
fnOut := fnIn
@@ -44,16 +49,21 @@ library ClaimHashFunctionCastLib {
4449
* @param fnIn Function pointer to `ClaimHashLib._toGenericMultichainClaimHashAndTypehash`.
4550
* @return fnOut Modified function used in `ClaimHashLib._toExogenousMultichainClaimHashAndTypehash`.
4651
*/
47-
function usingExogenousMultichainClaim(
48-
function (uint256, uint256, function (uint256, uint256, bytes32, bytes32, uint256) internal view returns (bytes32)) internal view returns (bytes32, bytes32)
49-
fnIn
50-
)
52+
function usingExogenousMultichainClaim(function(uint256, uint256, function(uint256, uint256, bytes32, bytes32, uint256)
53+
internal
54+
view returns (bytes32))
55+
internal
56+
view returns (
57+
bytes32,
58+
bytes32
59+
) fnIn)
5160
internal
5261
pure
53-
returns (
54-
function (ExogenousMultichainClaim calldata, uint256, function (uint256, uint256, bytes32, bytes32, uint256) internal view returns (bytes32)) internal view returns (bytes32, bytes32)
55-
fnOut
56-
)
62+
returns (function(ExogenousMultichainClaim calldata, uint256, function(uint256, uint256, bytes32, bytes32, uint256)
63+
internal
64+
view returns (bytes32))
65+
internal
66+
view returns (bytes32, bytes32) fnOut)
5767
{
5868
assembly ("memory-safe") {
5969
fnOut := fnIn
@@ -66,16 +76,21 @@ library ClaimHashFunctionCastLib {
6676
* @param fnIn Function pointer to `ClaimHashLib._toGenericMultichainClaimHashAndTypehash`.
6777
* @return fnOut Modified function used in `ClaimHashLib._toBatchMultichainClaimHashAndTypehash`.
6878
*/
69-
function usingBatchMultichainClaim(
70-
function (uint256, uint256, function (uint256, uint256, bytes32, bytes32, uint256) internal view returns (bytes32)) internal view returns (bytes32, bytes32)
71-
fnIn
72-
)
79+
function usingBatchMultichainClaim(function(uint256, uint256, function(uint256, uint256, bytes32, bytes32, uint256)
80+
internal
81+
view returns (bytes32))
82+
internal
83+
view returns (
84+
bytes32,
85+
bytes32
86+
) fnIn)
7387
internal
7488
pure
75-
returns (
76-
function (BatchMultichainClaim calldata, uint256, function (uint256, uint256, bytes32, bytes32, uint256) internal view returns (bytes32)) internal view returns (bytes32, bytes32)
77-
fnOut
78-
)
89+
returns (function(BatchMultichainClaim calldata, uint256, function(uint256, uint256, bytes32, bytes32, uint256)
90+
internal
91+
view returns (bytes32))
92+
internal
93+
view returns (bytes32, bytes32) fnOut)
7994
{
8095
assembly ("memory-safe") {
8196
fnOut := fnIn
@@ -88,16 +103,21 @@ library ClaimHashFunctionCastLib {
88103
* @param fnIn Function pointer to `ClaimHashLib._toGenericBatchMultichainClaimHashAndTypehash`.
89104
* @return fnOut Modified function used in `ClaimHashLib._toExogenousBatchMultichainClaimHashAndTypehash`.
90105
*/
91-
function usingExogenousBatchMultichainClaim(
92-
function (uint256, uint256, function (uint256, uint256, bytes32, bytes32, uint256) internal view returns (bytes32)) internal view returns (bytes32, bytes32)
93-
fnIn
94-
)
106+
function usingExogenousBatchMultichainClaim(function(uint256, uint256, function(uint256, uint256, bytes32, bytes32, uint256)
107+
internal
108+
view returns (bytes32))
109+
internal
110+
view returns (
111+
bytes32,
112+
bytes32
113+
) fnIn)
95114
internal
96115
pure
97-
returns (
98-
function (ExogenousBatchMultichainClaim calldata, uint256, function (uint256, uint256, bytes32, bytes32, uint256) internal view returns (bytes32)) internal view returns (bytes32, bytes32)
99-
fnOut
100-
)
116+
returns (function(ExogenousBatchMultichainClaim calldata, uint256, function(uint256, uint256, bytes32, bytes32, uint256)
117+
internal
118+
view returns (bytes32))
119+
internal
120+
view returns (bytes32, bytes32) fnOut)
101121
{
102122
assembly ("memory-safe") {
103123
fnOut := fnIn
@@ -110,10 +130,10 @@ library ClaimHashFunctionCastLib {
110130
* @param fnIn Function pointer to `HashLib.toCommitmentsHashFromSingleLock`.
111131
* @return fnOut Modified function used in `ClaimHashLib._toMultichainClaimHashAndTypehash`.
112132
*/
113-
function usingMultichainClaim(function (uint256) internal pure returns (uint256) fnIn)
133+
function usingMultichainClaim(function(uint256) internal pure returns (uint256) fnIn)
114134
internal
115135
pure
116-
returns (function (MultichainClaim calldata) internal pure returns (uint256) fnOut)
136+
returns (function(MultichainClaim calldata) internal pure returns (uint256) fnOut)
117137
{
118138
assembly ("memory-safe") {
119139
fnOut := fnIn
@@ -126,10 +146,10 @@ library ClaimHashFunctionCastLib {
126146
* @param fnIn Function pointer to `CHashLib.toCommitmentsHashFromSingleLock`.
127147
* @return fnOut Modified function used in `ClaimHashLib._toExogenousMultichainClaimHashAndTypehash`.
128148
*/
129-
function usingExogenousMultichainClaim(function (uint256) internal pure returns (uint256) fnIn)
149+
function usingExogenousMultichainClaim(function(uint256) internal pure returns (uint256) fnIn)
130150
internal
131151
pure
132-
returns (function (ExogenousMultichainClaim calldata) internal pure returns (uint256) fnOut)
152+
returns (function(ExogenousMultichainClaim calldata) internal pure returns (uint256) fnOut)
133153
{
134154
assembly ("memory-safe") {
135155
fnOut := fnIn

src/lib/ClaimHashLib.sol

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,11 @@ library ClaimHashLib {
2727
using ClaimHashFunctionCastLib for function(uint256) internal pure returns (uint256);
2828
using ClaimHashFunctionCastLib for function(uint256) internal view returns (bytes32, bytes32);
2929
using ClaimHashFunctionCastLib for function(uint256, uint256) internal view returns (bytes32, bytes32);
30-
using
31-
ClaimHashFunctionCastLib
32-
for
33-
function(uint256, uint256, function(uint256, uint256, bytes32, bytes32, uint256) internal view returns (bytes32)) internal view returns (bytes32, bytes32);
30+
using ClaimHashFunctionCastLib for function(uint256, uint256, function(uint256, uint256, bytes32, bytes32, uint256)
31+
internal
32+
view returns (bytes32))
33+
internal
34+
view returns (bytes32, bytes32);
3435
using HashLib for uint256;
3536
using HashLib for Claim;
3637
using HashLib for BatchClaim;

src/lib/ComponentLib.sol

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -173,9 +173,8 @@ library ComponentLib {
173173
BatchClaimComponent calldata claimComponent = claims[i];
174174

175175
// Process each component, verifying total amount and executing operations.
176-
claimComponent.portions.verifyAndProcessComponents(
177-
sponsor, claimComponent.id, claimComponent.allocatedAmount
178-
);
176+
claimComponent.portions
177+
.verifyAndProcessComponents(sponsor, claimComponent.id, claimComponent.allocatedAmount);
179178
}
180179
}
181180

@@ -215,8 +214,8 @@ library ComponentLib {
215214
claimComponent = claims[i];
216215
id = claimComponent.id;
217216

218-
errorBuffer |=
219-
(id.toAllocatorId() != firstAllocatorId).or(id.scopeNotMultichain(sponsorDomainSeparator)).asUint256();
217+
errorBuffer |= (id.toAllocatorId() != firstAllocatorId).or(id.scopeNotMultichain(sponsorDomainSeparator))
218+
.asUint256();
220219

221220
// Include the id and amount in idsAndAmounts.
222221
idsAndAmounts[i] = [id, claimComponent.allocatedAmount];

src/lib/DepositViaPermit2Lib.sol

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -287,12 +287,16 @@ library DepositViaPermit2Lib {
287287
mstore(memoryLocation, sub(add(tokenPermissionsFragmentStart, 0x2f), memoryOffset))
288288

289289
// Derive activation typehash.
290-
activationTypehash :=
291-
keccak256(activationStart, sub(add(tokenPermissionsFragmentStart, 1), activationStart))
290+
activationTypehash := keccak256(
291+
activationStart,
292+
sub(add(tokenPermissionsFragmentStart, 1), activationStart)
293+
)
292294

293295
// Derive compact typehash.
294-
compactTypehash :=
295-
keccak256(categorySpecificStart, sub(add(tokenPermissionsFragmentStart, 1), categorySpecificStart))
296+
compactTypehash := keccak256(
297+
categorySpecificStart,
298+
sub(add(tokenPermissionsFragmentStart, 1), categorySpecificStart)
299+
)
296300
break
297301
}
298302
}

src/lib/DepositViaPermit2Logic.sol

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,7 @@ contract DepositViaPermit2Logic is DepositLogic {
5858
* @param signature The Permit2 signature from the depositor authorizing the deposit.
5959
* @return The ERC6909 token identifier of the associated resource lock.
6060
*/
61-
function _depositViaPermit2(address token, address recipient, bytes calldata signature)
62-
internal
63-
returns (uint256)
64-
{
61+
function _depositViaPermit2(address token, address recipient, bytes calldata signature) internal returns (uint256) {
6562
// Derive the CompactDeposit witness hash.
6663
bytes32 witness = uint256(0xa4).asStubborn().deriveCompactDepositWitnessHash();
6764

@@ -277,8 +274,9 @@ contract DepositViaPermit2Logic is DepositLogic {
277274
}
278275

279276
// Begin preparing Permit2 call data.
280-
(m, typestringMemoryLocation) = totalTokensLessInitialNative
281-
.beginPreparingBatchDepositPermit2Calldata(firstUnderlyingTokenIsNative);
277+
(m, typestringMemoryLocation) = totalTokensLessInitialNative.beginPreparingBatchDepositPermit2Calldata(
278+
firstUnderlyingTokenIsNative
279+
);
282280

283281
// Prepare the typestring fragment and get batch activation and compact typehashes.
284282
(activationTypehash, compactTypehash) = typestringMemoryLocation.writeWitnessAndGetTypehashes(
@@ -302,8 +300,10 @@ contract DepositViaPermit2Logic is DepositLogic {
302300
and(add(0x153, add(witness.length, iszero(iszero(witness.length)))), not(0x1f))
303301

304302
// Derive the signature offset value.
305-
signatureOffsetValue :=
306-
add(add(0x180, shl(7, totalTokensLessInitialNative)), totalWitnessMemoryOffset)
303+
signatureOffsetValue := add(
304+
add(0x180, shl(7, totalTokensLessInitialNative)),
305+
totalWitnessMemoryOffset
306+
)
307307
}
308308

309309
// Write the signature and perform the Permit2 call.

src/lib/EmissaryLib.sol

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -297,11 +297,7 @@ library EmissaryLib {
297297
* @param lockTag The lock tag to which the emissary assignment is associated.
298298
* @return config The configuration for the emissary in storage.
299299
*/
300-
function _getEmissaryConfig(address sponsor, bytes12 lockTag)
301-
private
302-
pure
303-
returns (EmissaryConfig storage config)
304-
{
300+
function _getEmissaryConfig(address sponsor, bytes12 lockTag) private pure returns (EmissaryConfig storage config) {
305301
// Pack and hash scope, sponsor, and lock tag to derive emissary config storage slot.
306302
assembly ("memory-safe") {
307303
// Start by writing the sponsor address to scratch space so that the 20 bytes of

0 commit comments

Comments
 (0)