Skip to content

Commit 38c94ba

Browse files
committed
refactor(excubiae): enforce check-effects-interactions pattern; minor gas saving improvements
1 parent de28e81 commit 38c94ba

7 files changed

+19
-19
lines changed

packages/excubiae/contracts/extensions/EASExcubia.sol

+2-2
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ contract EASExcubia is Excubia {
6161
// Avoiding passing the gate twice using the same attestation.
6262
if (passedAttestations[attestationId]) revert AlreadyPassed();
6363

64-
super._pass(passerby, data);
65-
6664
passedAttestations[attestationId] = true;
65+
66+
super._pass(passerby, data);
6767
}
6868

6969
/// @notice Internal function to handle the gate protection (attestation check) logic.

packages/excubiae/contracts/extensions/ERC721Excubia.sol

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ contract ERC721Excubia is Excubia {
4242
// Avoiding passing the gate twice with the same token ID.
4343
if (passedTokenIds[tokenId]) revert AlreadyPassed();
4444

45-
super._pass(passerby, data);
46-
4745
passedTokenIds[tokenId] = true;
46+
47+
super._pass(passerby, data);
4848
}
4949

5050
/// @notice Internal function to handle the gate protection (token ownership check) logic.

packages/excubiae/contracts/extensions/FreeForAllExcubia.sol

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ contract FreeForAllExcubia is Excubia {
2727
// Avoiding passing the gate twice with the same address.
2828
if (passedPassersby[passerby]) revert AlreadyPassed();
2929

30-
super._pass(passerby, data);
31-
3230
passedPassersby[passerby] = true;
31+
32+
super._pass(passerby, data);
3333
}
3434

3535
/// @notice Internal function to handle the gate protection logic.

packages/excubiae/contracts/extensions/GitcoinPassportExcubia.sol

+2-2
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@ contract GitcoinPassportExcubia is Excubia {
5353
function _pass(address passerby, bytes calldata data) internal override {
5454
if (passedUsers[passerby]) revert AlreadyPassed();
5555

56-
super._pass(passerby, data);
57-
5856
passedUsers[passerby] = true;
57+
58+
super._pass(passerby, data);
5959
}
6060

6161
/// @notice Internal function to handle the gate protection (score check) logic.

packages/excubiae/contracts/extensions/HatsExcubia.sol

+5-3
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ contract HatsExcubia is Excubia {
3333

3434
HATS = IHatsMinimal(_hats);
3535

36-
for (uint256 i; i < _criterionHats.length; ++i) {
36+
uint256 numberOfCriterionHats = _criterionHats.length;
37+
38+
for (uint256 i = 0; i < numberOfCriterionHats; ++i) {
3739
criterionHat[_criterionHats[i]] = true;
3840
}
3941
}
@@ -51,9 +53,9 @@ contract HatsExcubia is Excubia {
5153
// Avoiding passing the gate twice for the same user.
5254
if (passedUsers[passerby]) revert AlreadyPassed();
5355

54-
super._pass(passerby, data);
55-
5656
passedUsers[passerby] = true;
57+
58+
super._pass(passerby, data);
5759
}
5860

5961
/// @notice Internal function to handle the gate protection (hat check) logic.

packages/excubiae/contracts/extensions/SemaphoreExcubia.sol

+2-2
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,9 @@ contract SemaphoreExcubia is Excubia {
5959
// Avoiding passing the gate twice using the same nullifier.
6060
if (passedNullifiers[proof.nullifier]) revert AlreadyPassed();
6161

62-
super._pass(passerby, data);
63-
6462
passedNullifiers[proof.nullifier] = true;
63+
64+
super._pass(passerby, data);
6565
}
6666

6767
/// @notice Internal function to handle the gate protection (proof check) logic.

packages/excubiae/contracts/extensions/ZKEdDSAEventTicketPCDExcubia.sol

+4-6
Original file line numberDiff line numberDiff line change
@@ -64,15 +64,13 @@ contract ZKEdDSAEventTicketPCDExcubia is Excubia {
6464
// Decode the given data bytes.
6565
(, , , uint256[38] memory _pubSignals) = abi.decode(data, (uint256[2], uint256[2][2], uint256[2], uint256[38]));
6666

67-
// Ticket ID is stored at index 0.
68-
uint256 ticketId = _pubSignals[0];
69-
7067
// Avoiding passing the gate twice using the same nullifier.
71-
if (passedZKEdDSAEventTicketPCDs[ticketId]) revert AlreadyPassed();
68+
/// @dev Ticket ID is stored at _pubSignals index 0.
69+
if (passedZKEdDSAEventTicketPCDs[_pubSignals[0]]) revert AlreadyPassed();
7270

73-
super._pass(passerby, data);
71+
passedZKEdDSAEventTicketPCDs[_pubSignals[0]] = true;
7472

75-
passedZKEdDSAEventTicketPCDs[ticketId] = true;
73+
super._pass(passerby, data);
7674
}
7775

7876
/// @notice Internal function to handle the gate protection (proof check) logic.

0 commit comments

Comments
 (0)