diff --git a/packages/excubiae/contracts/extensions/EASExcubia.sol b/packages/excubiae/contracts/extensions/EASExcubia.sol index 57eee9b..3be1bd9 100644 --- a/packages/excubiae/contracts/extensions/EASExcubia.sol +++ b/packages/excubiae/contracts/extensions/EASExcubia.sol @@ -53,9 +53,14 @@ contract EASExcubia is Excubia { /// @param passerby The address of the entity attempting to pass the gate. /// @param data Encoded attestation ID. function _pass(address passerby, bytes calldata data) internal override { - super._pass(passerby, data); + bytes32 attestationId = abi.decode(data, (bytes32)); + + // Avoiding double check of the same attestation. + if (registeredAttestations[attestationId]) revert AlreadyRegistered(); - registeredAttestations[decodeAttestationId(data)] = true; + registeredAttestations[attestationId] = true; + + super._pass(passerby, data); } /// @notice Overrides the `_check` function to validate the attestation against specific criteria. @@ -63,11 +68,7 @@ contract EASExcubia is Excubia { /// @param data Encoded attestation ID. /// @return True if the attestation meets all criteria, revert otherwise. function _check(address passerby, bytes calldata data) internal view override returns (bool) { - bytes32 attestationId = decodeAttestationId(data); - - if (registeredAttestations[attestationId]) revert AlreadyRegistered(); - - Attestation memory attestation = EAS.getAttestation(attestationId); + Attestation memory attestation = EAS.getAttestation(abi.decode(data, (bytes32))); if (attestation.schema != SCHEMA) revert UnexpectedSchema(); if (attestation.attester != ATTESTER) revert UnexpectedAttester(); @@ -76,11 +77,4 @@ contract EASExcubia is Excubia { return true; } - - /// @notice Decodes an EAS attestation identifier from the encoded form. - /// @param data Encoded attestation ID. - /// @return Decoded attestation ID. - function decodeAttestationId(bytes calldata data) private pure returns (bytes32) { - return abi.decode(data, (bytes32)); - } } diff --git a/packages/excubiae/package.json b/packages/excubiae/package.json index 8cd4433..e4b83ce 100644 --- a/packages/excubiae/package.json +++ b/packages/excubiae/package.json @@ -33,9 +33,5 @@ "ts-node": "^10.9.2", "typechain": "^8.3.0", "typescript": "^5.3.3" - }, - "dependencies": { - "@ethereum-attestation-service/eas-contracts": "^1.7.1", - "@openzeppelin/contracts": "^5.0.2" } } diff --git a/packages/excubiae/test/EASExcubia.test.ts b/packages/excubiae/test/EASExcubia.test.ts index bb9d2b8..e4c5f6b 100644 --- a/packages/excubiae/test/EASExcubia.test.ts +++ b/packages/excubiae/test/EASExcubia.test.ts @@ -1,6 +1,6 @@ import { expect } from "chai" import { ethers } from "hardhat" -import { BigNumberish, Signer, ZeroAddress, getDefaultProvider } from "ethers" +import { Signer, ZeroAddress } from "ethers" import { EASExcubia, EASExcubia__factory, MockEAS, MockEAS__factory } from "../typechain-types" describe("EASExcubia", function () { @@ -74,6 +74,10 @@ describe("EASExcubia", function () { expect(await easExcubia.gate()).to.eq(gateAddress) }) + it("Should fail to set the gate if already set", async function () { + await expect(easExcubia.setGate(gateAddress)).to.be.revertedWithCustomError(easExcubia, "GateAlreadySet") + }) + it("should throw when the callee is not the gate", async () => { await expect( easExcubia.connect(signer).pass(signerAddress, invalidRecipientAttestationId) diff --git a/yarn.lock b/yarn.lock index 74bf2d6..f8b7350 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3470,13 +3470,11 @@ __metadata: version: 0.0.0-use.local resolution: "excubiae@workspace:packages/excubiae" dependencies: - "@ethereum-attestation-service/eas-contracts": "npm:^1.7.1" "@nomicfoundation/hardhat-chai-matchers": "npm:^2.0.3" "@nomicfoundation/hardhat-ethers": "npm:^3.0.0" "@nomicfoundation/hardhat-network-helpers": "npm:^1.0.0" "@nomicfoundation/hardhat-toolbox": "npm:^4.0.0" "@nomicfoundation/hardhat-verify": "npm:^2.0.0" - "@openzeppelin/contracts": "npm:^5.0.2" "@typechain/ethers-v6": "npm:^0.5.0" "@typechain/hardhat": "npm:^9.0.0" "@types/chai": "npm:^4.2.0"