Skip to content

Commit

Permalink
refactor(excubiae): enforce check-effects-interactions pattern; minor…
Browse files Browse the repository at this point in the history
… gas saving improvements
  • Loading branch information
0xjei committed Jul 10, 2024
1 parent de28e81 commit 38c94ba
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 19 deletions.
4 changes: 2 additions & 2 deletions packages/excubiae/contracts/extensions/EASExcubia.sol
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ contract EASExcubia is Excubia {
// Avoiding passing the gate twice using the same attestation.
if (passedAttestations[attestationId]) revert AlreadyPassed();

super._pass(passerby, data);

passedAttestations[attestationId] = true;

super._pass(passerby, data);
}

/// @notice Internal function to handle the gate protection (attestation check) logic.
Expand Down
4 changes: 2 additions & 2 deletions packages/excubiae/contracts/extensions/ERC721Excubia.sol
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ contract ERC721Excubia is Excubia {
// Avoiding passing the gate twice with the same token ID.
if (passedTokenIds[tokenId]) revert AlreadyPassed();

super._pass(passerby, data);

passedTokenIds[tokenId] = true;

super._pass(passerby, data);
}

/// @notice Internal function to handle the gate protection (token ownership check) logic.
Expand Down
4 changes: 2 additions & 2 deletions packages/excubiae/contracts/extensions/FreeForAllExcubia.sol
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ contract FreeForAllExcubia is Excubia {
// Avoiding passing the gate twice with the same address.
if (passedPassersby[passerby]) revert AlreadyPassed();

super._pass(passerby, data);

passedPassersby[passerby] = true;

super._pass(passerby, data);
}

/// @notice Internal function to handle the gate protection logic.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ contract GitcoinPassportExcubia is Excubia {
function _pass(address passerby, bytes calldata data) internal override {
if (passedUsers[passerby]) revert AlreadyPassed();

super._pass(passerby, data);

passedUsers[passerby] = true;

super._pass(passerby, data);
}

/// @notice Internal function to handle the gate protection (score check) logic.
Expand Down
8 changes: 5 additions & 3 deletions packages/excubiae/contracts/extensions/HatsExcubia.sol
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ contract HatsExcubia is Excubia {

HATS = IHatsMinimal(_hats);

for (uint256 i; i < _criterionHats.length; ++i) {
uint256 numberOfCriterionHats = _criterionHats.length;

for (uint256 i = 0; i < numberOfCriterionHats; ++i) {
criterionHat[_criterionHats[i]] = true;
}
}
Expand All @@ -51,9 +53,9 @@ contract HatsExcubia is Excubia {
// Avoiding passing the gate twice for the same user.
if (passedUsers[passerby]) revert AlreadyPassed();

super._pass(passerby, data);

passedUsers[passerby] = true;

super._pass(passerby, data);
}

/// @notice Internal function to handle the gate protection (hat check) logic.
Expand Down
4 changes: 2 additions & 2 deletions packages/excubiae/contracts/extensions/SemaphoreExcubia.sol
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ contract SemaphoreExcubia is Excubia {
// Avoiding passing the gate twice using the same nullifier.
if (passedNullifiers[proof.nullifier]) revert AlreadyPassed();

super._pass(passerby, data);

passedNullifiers[proof.nullifier] = true;

super._pass(passerby, data);
}

/// @notice Internal function to handle the gate protection (proof check) logic.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,13 @@ contract ZKEdDSAEventTicketPCDExcubia is Excubia {
// Decode the given data bytes.
(, , , uint256[38] memory _pubSignals) = abi.decode(data, (uint256[2], uint256[2][2], uint256[2], uint256[38]));

// Ticket ID is stored at index 0.
uint256 ticketId = _pubSignals[0];

// Avoiding passing the gate twice using the same nullifier.
if (passedZKEdDSAEventTicketPCDs[ticketId]) revert AlreadyPassed();
/// @dev Ticket ID is stored at _pubSignals index 0.
if (passedZKEdDSAEventTicketPCDs[_pubSignals[0]]) revert AlreadyPassed();

super._pass(passerby, data);
passedZKEdDSAEventTicketPCDs[_pubSignals[0]] = true;

passedZKEdDSAEventTicketPCDs[ticketId] = true;
super._pass(passerby, data);
}

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

0 comments on commit 38c94ba

Please sign in to comment.