Skip to content

Commit

Permalink
refactor(excubiae): adapt SemaphoreExcubia to new _check signature; m…
Browse files Browse the repository at this point in the history
…inors
  • Loading branch information
0xjei committed Jul 3, 2024
1 parent 22ba357 commit 1635de3
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 19 deletions.
7 changes: 2 additions & 5 deletions packages/excubiae/contracts/extensions/SemaphoreExcubia.sol
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ contract SemaphoreExcubia is Excubia {

SEMAPHORE = ISemaphore(_semaphore);

if (ISemaphore(_semaphore).groupCounter() < _groupId) revert InvalidGroup();
if (ISemaphore(_semaphore).groupCounter() <= _groupId) revert InvalidGroup();

GROUP_ID = _groupId;
}
Expand All @@ -63,16 +63,13 @@ contract SemaphoreExcubia is Excubia {
/// @dev Checks if the proof matches the group ID, scope, and is valid.
/// @param passerby The address of the entity attempting to pass the gate.
/// @param data Additional data required for the check (i.e., encoded Semaphore proof).
/// @return True if the proof is valid and the passerby passes the check, false otherwise.
function _check(address passerby, bytes calldata data) internal view override returns (bool) {
function _check(address passerby, bytes calldata data) internal view override {
super._check(passerby, data);

ISemaphore.SemaphoreProof memory proof = abi.decode(data, (ISemaphore.SemaphoreProof));

if (GROUP_ID != proof.scope) revert UnexpectedScope();

if (!SEMAPHORE.verifyProof(GROUP_ID, proof)) revert InvalidProof();

return true;
}
}
6 changes: 3 additions & 3 deletions packages/excubiae/contracts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
"access": "public"
},
"dependencies": {
"@ethereum-attestation-service/eas-contracts": "^1.7.1",
"@openzeppelin/contracts": "^5.0.2",
"@semaphore-protocol/contracts": "^4.0.0-beta.16"
"@ethereum-attestation-service/eas-contracts": "1.7.1",
"@openzeppelin/contracts": "5.0.2",
"@semaphore-protocol/contracts": "4.0.0-beta.16"
}
}
9 changes: 4 additions & 5 deletions packages/excubiae/test/SemaphoreExcubia.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ describe("SemaphoreExcubia", function () {
let mockSemaphore: MockSemaphore
let mockSemaphoreAddress: string

const validGroupId = 1n
const invalidGroupId = 2n
const validGroupId = 0n
const invalidGroupId = 1n

const validProof = {
merkleTreeDepth: 1n,
Expand Down Expand Up @@ -169,10 +169,9 @@ describe("SemaphoreExcubia", function () {
)
})

it("should pass the check", async () => {
const passed = await semaphoreExcubia.check(signerAddress, encodedValidProof)
it("should check", async () => {
await expect(semaphoreExcubia.check(signerAddress, encodedValidProof)).to.not.be.reverted

expect(passed).to.be.true
// check does NOT change the state of the contract (see pass()).
expect(await semaphoreExcubia.passedNullifiers(validProof.nullifier)).to.be.false
})
Expand Down
12 changes: 6 additions & 6 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ __metadata:
languageName: node
linkType: hard

"@ethereum-attestation-service/eas-contracts@npm:^1.7.1":
"@ethereum-attestation-service/eas-contracts@npm:1.7.1":
version: 1.7.1
resolution: "@ethereum-attestation-service/eas-contracts@npm:1.7.1"
dependencies:
Expand Down Expand Up @@ -1150,7 +1150,7 @@ __metadata:
languageName: node
linkType: hard

"@openzeppelin/contracts@npm:^5.0.2":
"@openzeppelin/contracts@npm:5.0.2":
version: 5.0.2
resolution: "@openzeppelin/contracts@npm:5.0.2"
checksum: 10/938ebffbdade7dc59ea3df5b562c0e457bbefde9d82be8fa2acfd11da887df11653ac07922f41746b80cdbc106430e1e6978ce244fe99b00a7d9dc1418fc7670
Expand Down Expand Up @@ -1222,7 +1222,7 @@ __metadata:
languageName: node
linkType: hard

"@semaphore-protocol/contracts@npm:^4.0.0-beta.16":
"@semaphore-protocol/contracts@npm:4.0.0-beta.16":
version: 4.0.0-beta.16
resolution: "@semaphore-protocol/contracts@npm:4.0.0-beta.16"
dependencies:
Expand Down Expand Up @@ -1564,9 +1564,9 @@ __metadata:
version: 0.0.0-use.local
resolution: "@zk-kit/excubiae@workspace:packages/excubiae/contracts"
dependencies:
"@ethereum-attestation-service/eas-contracts": "npm:^1.7.1"
"@openzeppelin/contracts": "npm:^5.0.2"
"@semaphore-protocol/contracts": "npm:^4.0.0-beta.16"
"@ethereum-attestation-service/eas-contracts": "npm:1.7.1"
"@openzeppelin/contracts": "npm:5.0.2"
"@semaphore-protocol/contracts": "npm:4.0.0-beta.16"
languageName: unknown
linkType: soft

Expand Down

0 comments on commit 1635de3

Please sign in to comment.