@@ -49,8 +49,8 @@ abstract contract CreateHash is Test {
49
49
// stringified types
50
50
string EIP712_DOMAIN_TYPE = "EIP712Domain(string name,string version,uint256 chainId,address verifyingContract) " ; // Hashed inside the funcion
51
51
// string ALLOCATOR_TYPE = "Allocator(bytes32 hash)"; // Hashed inside the funcion
52
- string REGISTER_ATTEST_TYPE = "RegisterAttest (address signer,bytes32 attestHash ,uint256 expiration,uint256 nonce) " ; // Hashed inside the funcion
53
- string NONCE_CONSUMPTION_TYPE = "NonceConsumption(address signer,uint256[] nonces,bytes32[] attests ) " ; // Hashed inside the funcion
52
+ string REGISTER_ATTESTATION_TYPE = "RegisterAttestation (address signer,bytes32 attestationHash ,uint256 expiration,uint256 nonce) " ; // Hashed inside the funcion
53
+ string NONCE_CONSUMPTION_TYPE = "NonceConsumption(address signer,uint256[] nonces,bytes32[] attestations ) " ; // Hashed inside the funcion
54
54
// EIP712 domain type
55
55
string name = "Allocator " ;
56
56
string version = "1 " ;
@@ -77,12 +77,12 @@ abstract contract CreateHash is Test {
77
77
);
78
78
}
79
79
80
- function _hashRegisterAttest (ServerAllocator.RegisterAttest memory data , address verifyingContract ) internal view returns (bytes32 ) {
80
+ function _hashRegisterAttest (ServerAllocator.RegisterAttestation memory data , address verifyingContract ) internal view returns (bytes32 ) {
81
81
return keccak256 (
82
82
abi.encodePacked (
83
83
"\x19\x01 " , // backslash is needed to escape the character
84
84
_domainSeperator (verifyingContract),
85
- keccak256 (abi.encode (keccak256 (bytes (REGISTER_ATTEST_TYPE )), data.signer, data.attestHash , data.expiration, data.nonce))
85
+ keccak256 (abi.encode (keccak256 (bytes (REGISTER_ATTESTATION_TYPE )), data.signer, data.attestationHash , data.expiration, data.nonce))
86
86
)
87
87
);
88
88
}
@@ -93,7 +93,7 @@ abstract contract CreateHash is Test {
93
93
abi.encodePacked (
94
94
"\x19\x01 " , // backslash is needed to escape the character
95
95
_domainSeperator (verifyingContract),
96
- keccak256 (abi.encode (keccak256 (bytes (NONCE_CONSUMPTION_TYPE)), data.signer, data.nonces, data.attests ))
96
+ keccak256 (abi.encode (keccak256 (bytes (NONCE_CONSUMPTION_TYPE)), data.signer, data.nonces, data.attestations ))
97
97
)
98
98
);
99
99
}
@@ -205,71 +205,71 @@ contract ServerAllocator_Attest is SignerSet {
205
205
206
206
vm.prank (attacker_);
207
207
vm.expectRevert (abi.encodeWithSelector (IServerAllocator.InvalidSigner.selector , attacker_));
208
- serverAllocator.registerAttest (createAttest (attacker_, usdcId, 100 ), vm.getBlockTimestamp () + 1 days);
208
+ serverAllocator.registerAttestation (createAttest (attacker_, usdcId, 100 ), vm.getBlockTimestamp () + 1 days);
209
209
}
210
210
211
211
function test_fuzz_registerAttest_attestExpired (uint256 expiration_ ) public {
212
212
vm.assume (expiration_ < vm.getBlockTimestamp ());
213
213
214
214
vm.prank (signer);
215
215
vm.expectRevert (abi.encodeWithSelector (IServerAllocator.Expired.selector , expiration_, vm.getBlockTimestamp ()));
216
- serverAllocator.registerAttest (createAttest (signer, usdcId, 100 ), expiration_);
216
+ serverAllocator.registerAttestation (createAttest (signer, usdcId, 100 ), expiration_);
217
217
}
218
218
219
219
function test_registerAttest_successful () public {
220
220
vm.prank (signer);
221
221
bytes32 attest = createAttest (signer, usdcId, 100 );
222
222
uint256 expiration = vm.getBlockTimestamp () + 1 days ;
223
223
vm.expectEmit (address (serverAllocator));
224
- emit IServerAllocator.AttestRegistered (attest, expiration);
225
- serverAllocator.registerAttest (attest, expiration);
224
+ emit IServerAllocator.AttestationRegistered (attest, expiration);
225
+ serverAllocator.registerAttestation (attest, expiration);
226
226
227
- assertEq (serverAllocator.checkAttestExpirations (attest)[0 ], expiration);
227
+ assertEq (serverAllocator.checkAttestationExpirations (attest)[0 ], expiration);
228
228
}
229
229
230
230
function test_registerAttestViaSignature_InvalidSignature () public {
231
231
bytes32 attest = createAttest (signer, usdcId, 100 );
232
232
uint256 expiration = vm.getBlockTimestamp () + 1 days ;
233
233
234
- IServerAllocator.RegisterAttest memory attestData = IServerAllocator.RegisterAttest (signer, attest, expiration, 0 );
234
+ IServerAllocator.RegisterAttestation memory attestData = IServerAllocator.RegisterAttestation (signer, attest, expiration, 0 );
235
235
bytes32 message = _hashRegisterAttest (attestData, address (serverAllocator));
236
236
bytes memory signature = _signMessage (message, attackerPK);
237
237
238
238
vm.prank (attacker);
239
239
vm.expectRevert (abi.encodeWithSelector (IServerAllocator.InvalidSignature.selector , signature, attacker));
240
- serverAllocator.registerAttestViaSignature (attestData, signature);
240
+ serverAllocator.registerAttestationViaSignature (attestData, signature);
241
241
}
242
242
243
243
function test_registerAttestViaSignature_successful () public {
244
244
bytes32 attest = createAttest (signer, usdcId, 100 );
245
245
uint256 expiration = vm.getBlockTimestamp () + 1 days ;
246
246
247
- IServerAllocator.RegisterAttest memory attestData = IServerAllocator.RegisterAttest (signer, attest, expiration, 0 );
247
+ IServerAllocator.RegisterAttestation memory attestData = IServerAllocator.RegisterAttestation (signer, attest, expiration, 0 );
248
248
bytes32 message = _hashRegisterAttest (attestData, address (serverAllocator));
249
249
bytes memory signature = _signMessage (message, signerPK);
250
250
251
251
vm.prank (attacker);
252
252
vm.expectEmit (address (serverAllocator));
253
- emit IServerAllocator.AttestRegistered (attest, expiration);
254
- serverAllocator.registerAttestViaSignature (attestData, signature);
253
+ emit IServerAllocator.AttestationRegistered (attest, expiration);
254
+ serverAllocator.registerAttestationViaSignature (attestData, signature);
255
255
}
256
256
257
257
function test_registerAttestViaSignature_AlreadyUsedSig () public {
258
258
bytes32 attest = createAttest (signer, usdcId, 100 );
259
259
uint256 expiration = vm.getBlockTimestamp () + 1 days ;
260
260
261
- IServerAllocator.RegisterAttest memory attestData = IServerAllocator.RegisterAttest (signer, attest, expiration, 0 );
261
+ IServerAllocator.RegisterAttestation memory attestData = IServerAllocator.RegisterAttestation (signer, attest, expiration, 0 );
262
262
bytes32 message = _hashRegisterAttest (attestData, address (serverAllocator));
263
263
bytes memory signature = _signMessage (message, signerPK);
264
264
265
265
vm.prank (attacker);
266
266
vm.expectEmit (address (serverAllocator));
267
- emit IServerAllocator.AttestRegistered (attest, expiration);
268
- serverAllocator.registerAttestViaSignature (attestData, signature);
267
+ emit IServerAllocator.AttestationRegistered (attest, expiration);
268
+ serverAllocator.registerAttestationViaSignature (attestData, signature);
269
269
270
270
vm.prank (attacker);
271
271
vm.expectRevert (abi.encodeWithSelector (IServerAllocator.AlreadyUsedSig.selector , attest, 0 ));
272
- serverAllocator.registerAttestViaSignature (attestData, signature);
272
+ serverAllocator.registerAttestationViaSignature (attestData, signature);
273
273
}
274
274
275
275
function test_registerSameAttestTwice () public {
@@ -280,18 +280,18 @@ contract ServerAllocator_Attest is SignerSet {
280
280
281
281
// first attest
282
282
vm.expectEmit (address (serverAllocator));
283
- emit IServerAllocator.AttestRegistered (attest, expiration1);
284
- serverAllocator.registerAttest (attest, expiration1);
283
+ emit IServerAllocator.AttestationRegistered (attest, expiration1);
284
+ serverAllocator.registerAttestation (attest, expiration1);
285
285
286
- assertEq (serverAllocator.checkAttestExpirations (attest)[0 ], expiration1);
286
+ assertEq (serverAllocator.checkAttestationExpirations (attest)[0 ], expiration1);
287
287
288
288
// second attest with different expiration
289
289
vm.expectEmit (address (serverAllocator));
290
- emit IServerAllocator.AttestRegistered (attest, expiration2);
291
- serverAllocator.registerAttest (attest, expiration2);
290
+ emit IServerAllocator.AttestationRegistered (attest, expiration2);
291
+ serverAllocator.registerAttestation (attest, expiration2);
292
292
293
- assertEq (serverAllocator.checkAttestExpirations (attest)[0 ], expiration1);
294
- assertEq (serverAllocator.checkAttestExpirations (attest)[1 ], expiration2);
293
+ assertEq (serverAllocator.checkAttestationExpirations (attest)[0 ], expiration1);
294
+ assertEq (serverAllocator.checkAttestationExpirations (attest)[1 ], expiration2);
295
295
}
296
296
297
297
function test_fuzz_attest_callerMustBeCompact (address caller_ ) public {
@@ -304,7 +304,7 @@ contract ServerAllocator_Attest is SignerSet {
304
304
305
305
function test_fuzz_attest_notRegistered (address operator_ , address from_ , address to_ , uint256 id_ , uint256 amount_ ) public {
306
306
vm.prank (address (compactContract));
307
- vm.expectRevert (abi.encodeWithSelector (IServerAllocator.UnregisteredAttest .selector , keccak256 (abi.encode (from_, id_, amount_))));
307
+ vm.expectRevert (abi.encodeWithSelector (IServerAllocator.UnregisteredAttestation .selector , keccak256 (abi.encode (from_, id_, amount_))));
308
308
serverAllocator.attest (operator_, from_, to_, id_, amount_);
309
309
}
310
310
@@ -315,14 +315,14 @@ contract ServerAllocator_Attest is SignerSet {
315
315
316
316
// register attest
317
317
vm.prank (signer);
318
- serverAllocator.registerAttest (attest, expiration);
318
+ serverAllocator.registerAttestation (attest, expiration);
319
319
320
320
// move time forward
321
321
vm.warp (vm.getBlockTimestamp () + 1 );
322
322
323
323
// check attest
324
324
vm.prank (address (compactContract));
325
- vm.expectRevert (abi.encodeWithSelector (IServerAllocator.ExpiredAttests .selector , attest));
325
+ vm.expectRevert (abi.encodeWithSelector (IServerAllocator.ExpiredAttestations .selector , attest));
326
326
serverAllocator.attest (signer, attacker, makeAddr ("to " ), usdcId, amount_);
327
327
}
328
328
@@ -332,21 +332,21 @@ contract ServerAllocator_Attest is SignerSet {
332
332
333
333
// register attest
334
334
vm.prank (signer);
335
- serverAllocator.registerAttest (attest, expiration);
335
+ serverAllocator.registerAttestation (attest, expiration);
336
336
337
337
// check for attest
338
- assertEq (serverAllocator.checkAttestExpirations (attest)[0 ], expiration);
338
+ assertEq (serverAllocator.checkAttestationExpirations (attest)[0 ], expiration);
339
339
340
340
// check attest
341
341
vm.prank (address (compactContract));
342
342
vm.expectEmit (address (serverAllocator));
343
- emit IServerAllocator.Attested (from_, id_, amount_);
343
+ emit IServerAllocator.AttestationConsumed (from_, id_, amount_);
344
344
bytes4 attestSelector = serverAllocator.attest (operator_, from_, to_, id_, amount_);
345
345
assertEq (attestSelector, _ATTEST_SELECTOR);
346
346
347
347
// check attest was consumed
348
- vm.expectRevert (abi.encodeWithSelector (IServerAllocator.UnregisteredAttest .selector , attest));
349
- serverAllocator.checkAttestExpirations (attest);
348
+ vm.expectRevert (abi.encodeWithSelector (IServerAllocator.UnregisteredAttestation .selector , attest));
349
+ serverAllocator.checkAttestationExpirations (attest);
350
350
}
351
351
}
352
352
@@ -395,13 +395,13 @@ contract ServerAllocator_Consume is SignerSet {
395
395
attests[2 ] = createAttest (signer, usdcId, 300 );
396
396
397
397
// register attests
398
- serverAllocator.registerAttest (attests[0 ], vm.getBlockTimestamp ());
399
- serverAllocator.registerAttest (attests[1 ], vm.getBlockTimestamp ());
400
- serverAllocator.registerAttest (attests[2 ], vm.getBlockTimestamp ());
398
+ serverAllocator.registerAttestation (attests[0 ], vm.getBlockTimestamp ());
399
+ serverAllocator.registerAttestation (attests[1 ], vm.getBlockTimestamp ());
400
+ serverAllocator.registerAttestation (attests[2 ], vm.getBlockTimestamp ());
401
401
402
- assertEq (serverAllocator.checkAttestExpirations (attests[0 ])[0 ], vm.getBlockTimestamp ());
403
- assertEq (serverAllocator.checkAttestExpirations (attests[1 ])[0 ], vm.getBlockTimestamp ());
404
- assertEq (serverAllocator.checkAttestExpirations (attests[2 ])[0 ], vm.getBlockTimestamp ());
402
+ assertEq (serverAllocator.checkAttestationExpirations (attests[0 ])[0 ], vm.getBlockTimestamp ());
403
+ assertEq (serverAllocator.checkAttestationExpirations (attests[1 ])[0 ], vm.getBlockTimestamp ());
404
+ assertEq (serverAllocator.checkAttestationExpirations (attests[2 ])[0 ], vm.getBlockTimestamp ());
405
405
406
406
vm.expectEmit (address (serverAllocator));
407
407
emit IServerAllocator.NoncesConsumed (nonces);
@@ -413,12 +413,12 @@ contract ServerAllocator_Consume is SignerSet {
413
413
}
414
414
415
415
// check attests were consumed
416
- vm.expectRevert (abi.encodeWithSelector (IServerAllocator.UnregisteredAttest .selector , attests[0 ]));
417
- serverAllocator.checkAttestExpirations (attests[0 ]);
418
- vm.expectRevert (abi.encodeWithSelector (IServerAllocator.UnregisteredAttest .selector , attests[1 ]));
419
- serverAllocator.checkAttestExpirations (attests[1 ]);
420
- vm.expectRevert (abi.encodeWithSelector (IServerAllocator.UnregisteredAttest .selector , attests[2 ]));
421
- serverAllocator.checkAttestExpirations (attests[2 ]);
416
+ vm.expectRevert (abi.encodeWithSelector (IServerAllocator.UnregisteredAttestation .selector , attests[0 ]));
417
+ serverAllocator.checkAttestationExpirations (attests[0 ]);
418
+ vm.expectRevert (abi.encodeWithSelector (IServerAllocator.UnregisteredAttestation .selector , attests[1 ]));
419
+ serverAllocator.checkAttestationExpirations (attests[1 ]);
420
+ vm.expectRevert (abi.encodeWithSelector (IServerAllocator.UnregisteredAttestation .selector , attests[2 ]));
421
+ serverAllocator.checkAttestationExpirations (attests[2 ]);
422
422
}
423
423
424
424
function test_consumeViaSignature_requiresNoncesAndAttestsToBeOfSameLength () public {
@@ -467,14 +467,14 @@ contract ServerAllocator_Consume is SignerSet {
467
467
468
468
vm.startPrank (signer);
469
469
// register attests
470
- serverAllocator.registerAttest (attests[0 ], vm.getBlockTimestamp ());
471
- serverAllocator.registerAttest (attests[1 ], vm.getBlockTimestamp ());
472
- serverAllocator.registerAttest (attests[2 ], vm.getBlockTimestamp ());
470
+ serverAllocator.registerAttestation (attests[0 ], vm.getBlockTimestamp ());
471
+ serverAllocator.registerAttestation (attests[1 ], vm.getBlockTimestamp ());
472
+ serverAllocator.registerAttestation (attests[2 ], vm.getBlockTimestamp ());
473
473
vm.stopPrank ();
474
474
475
- assertEq (serverAllocator.checkAttestExpirations (attests[0 ])[0 ], vm.getBlockTimestamp ());
476
- assertEq (serverAllocator.checkAttestExpirations (attests[1 ])[0 ], vm.getBlockTimestamp ());
477
- assertEq (serverAllocator.checkAttestExpirations (attests[2 ])[0 ], vm.getBlockTimestamp ());
475
+ assertEq (serverAllocator.checkAttestationExpirations (attests[0 ])[0 ], vm.getBlockTimestamp ());
476
+ assertEq (serverAllocator.checkAttestationExpirations (attests[1 ])[0 ], vm.getBlockTimestamp ());
477
+ assertEq (serverAllocator.checkAttestationExpirations (attests[2 ])[0 ], vm.getBlockTimestamp ());
478
478
479
479
bytes32 message = _hashNonceConsumption (IServerAllocator.NonceConsumption (signer, nonces, attests), address (serverAllocator));
480
480
bytes memory signature = _signMessage (message, signerPK);
@@ -490,12 +490,12 @@ contract ServerAllocator_Consume is SignerSet {
490
490
}
491
491
492
492
// check attests were consumed
493
- vm.expectRevert (abi.encodeWithSelector (IServerAllocator.UnregisteredAttest .selector , attests[0 ]));
494
- serverAllocator.checkAttestExpirations (attests[0 ]);
495
- vm.expectRevert (abi.encodeWithSelector (IServerAllocator.UnregisteredAttest .selector , attests[1 ]));
496
- serverAllocator.checkAttestExpirations (attests[1 ]);
497
- vm.expectRevert (abi.encodeWithSelector (IServerAllocator.UnregisteredAttest .selector , attests[2 ]));
498
- serverAllocator.checkAttestExpirations (attests[2 ]);
493
+ vm.expectRevert (abi.encodeWithSelector (IServerAllocator.UnregisteredAttestation .selector , attests[0 ]));
494
+ serverAllocator.checkAttestationExpirations (attests[0 ]);
495
+ vm.expectRevert (abi.encodeWithSelector (IServerAllocator.UnregisteredAttestation .selector , attests[1 ]));
496
+ serverAllocator.checkAttestationExpirations (attests[1 ]);
497
+ vm.expectRevert (abi.encodeWithSelector (IServerAllocator.UnregisteredAttestation .selector , attests[2 ]));
498
+ serverAllocator.checkAttestationExpirations (attests[2 ]);
499
499
}
500
500
}
501
501
0 commit comments