From cc3d03a34f951d701487e964495cbed2557c53ef Mon Sep 17 00:00:00 2001 From: Eric Woolsey Date: Wed, 11 Dec 2024 18:36:51 -0800 Subject: [PATCH] cleanup --- pbh-verifier/Dockerfile | 17 +++++++++ pbh-verifier/LICENSE.md | 18 +++++++++ pbh-verifier/script/Counter.s.sol.bak | 19 ---------- pbh-verifier/src/PBHVerifier.sol | 37 ++++--------------- pbh-verifier/src/helpers/ByteHasher.sol | 2 +- .../src/helpers/PBHExternalNullifier.sol | 5 +-- pbh-verifier/test/PBHExternalNullifier.t.sol | 4 +- pbh-verifier/test/PBHVerifier.t.sol | 4 +- 8 files changed, 50 insertions(+), 56 deletions(-) create mode 100644 pbh-verifier/Dockerfile create mode 100644 pbh-verifier/LICENSE.md delete mode 100644 pbh-verifier/script/Counter.s.sol.bak diff --git a/pbh-verifier/Dockerfile b/pbh-verifier/Dockerfile new file mode 100644 index 00000000..3c219146 --- /dev/null +++ b/pbh-verifier/Dockerfile @@ -0,0 +1,17 @@ +FROM ghcr.io/foundry-rs/foundry:latest + +WORKDIR /world-id + +COPY . . + +# Fetch libs +RUN forge install + +# Build the project +RUN forge build + +# RUN ls script; exit 1 +RUN ./script/generate_anvil_state.sh + +ENTRYPOINT ["anvil", "--host", "0.0.0.0", "--load-state", "state.json"] +CMD [] diff --git a/pbh-verifier/LICENSE.md b/pbh-verifier/LICENSE.md new file mode 100644 index 00000000..4c1e8d7e --- /dev/null +++ b/pbh-verifier/LICENSE.md @@ -0,0 +1,18 @@ +MIT License + +Copyright 2023 Worldcoin Foundation + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and +associated documentation files (the "Software"), to deal in the Software without restriction, +including without limitation the rights to use, copy, modify, merge, publish, distribute, +sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial +portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT +NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES +OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/pbh-verifier/script/Counter.s.sol.bak b/pbh-verifier/script/Counter.s.sol.bak deleted file mode 100644 index cdc1fe9a..00000000 --- a/pbh-verifier/script/Counter.s.sol.bak +++ /dev/null @@ -1,19 +0,0 @@ -// SPDX-License-Identifier: UNLICENSED -pragma solidity ^0.8.13; - -import {Script, console} from "forge-std/Script.sol"; -import {Counter} from "../src/Counter.sol"; - -contract CounterScript is Script { - Counter public counter; - - function setUp() public {} - - function run() public { - vm.startBroadcast(); - - counter = new Counter(); - - vm.stopBroadcast(); - } -} diff --git a/pbh-verifier/src/PBHVerifier.sol b/pbh-verifier/src/PBHVerifier.sol index 7600a063..10cb68c0 100644 --- a/pbh-verifier/src/PBHVerifier.sol +++ b/pbh-verifier/src/PBHVerifier.sol @@ -26,42 +26,23 @@ contract PBHVerifier { event PBH( uint256 indexed nullifierHash ); - - /////////////////////////////////////////////////////////////////////////////// - /// Structs /// - ////////////////////////////////////////////////////////////////////////////// - - struct PBHPayload { - uint256 root; - uint256 nullifierHash; - ExternalNullifier externalNullifier; - uint256[8] proof; - } - - /** - * External Nullifier struct - * @param pbhNonce - A nonce between 0 and numPbhPerMonth. - * @param month - An integer representing the current month. - * @param year - An integer representing the current year. - */ - struct ExternalNullifier { - uint8 pbhNonce; - uint16 month; - uint8 year; - } /////////////////////////////////////////////////////////////////////////////// /// Vars /// ////////////////////////////////////////////////////////////////////////////// + /// @dev The World ID group ID (always 1) + uint256 internal immutable GROUP_ID = 1; + /// @dev The World ID instance that will be used for verifying proofs IWorldIDGroups internal immutable worldId; - /// @dev The World ID group ID (always 1) - uint256 internal immutable groupId = 1; - /// @dev Make this configurable uint8 internal immutable numPbhPerMonth; + + /////////////////////////////////////////////////////////////////////////////// + /// Mappings /// + ////////////////////////////////////////////////////////////////////////////// /// @dev Whether a nullifier hash has been used already. Used to guarantee an action is only performed once by a single person mapping(uint256 => bool) internal nullifierHashes; @@ -107,11 +88,10 @@ contract PBHVerifier { // Verify the external nullifier PBHExternalNullifier.verify(pbhExternalNullifier, numPbhPerMonth); - // We now verify the provided proof is valid and the user is verified by World ID worldId.verifyProof( root, - groupId, + GROUP_ID, signalHash, nullifierHash, pbhExternalNullifier, @@ -124,4 +104,3 @@ contract PBHVerifier { emit PBH(nullifierHash); } } - diff --git a/pbh-verifier/src/helpers/ByteHasher.sol b/pbh-verifier/src/helpers/ByteHasher.sol index f1e0b220..c655a1d9 100644 --- a/pbh-verifier/src/helpers/ByteHasher.sol +++ b/pbh-verifier/src/helpers/ByteHasher.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -pragma solidity ^0.8.10; +pragma solidity ^0.8.20; library ByteHasher { /// @dev Creates a keccak256 hash of a bytestring. diff --git a/pbh-verifier/src/helpers/PBHExternalNullifier.sol b/pbh-verifier/src/helpers/PBHExternalNullifier.sol index 9b07c61c..e3a1d8f0 100644 --- a/pbh-verifier/src/helpers/PBHExternalNullifier.sol +++ b/pbh-verifier/src/helpers/PBHExternalNullifier.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -pragma solidity ^0.8.10; +pragma solidity ^0.8.20; import "@BokkyPooBahsDateTimeLibrary/BokkyPooBahsDateTimeLibrary.sol"; @@ -7,7 +7,6 @@ import "@BokkyPooBahsDateTimeLibrary/BokkyPooBahsDateTimeLibrary.sol"; /// @notice Library for encoding, decoding, and verifying PBH external nullifiers. /// External nullifiers are used to uniquely identify actions or events /// within a specific year and month using a nonce. -/// @dev Utilizes `PBHExternalNullifier` as a custom type for encoded nullifiers. /// @dev The encoding format is as follows: /// - Bits 32-255: Empty /// - Bits 16-31: Year @@ -33,7 +32,7 @@ library PBHExternalNullifier { /// @return The encoded PBHExternalNullifier. function encode(uint8 pbhNonce, uint8 month, uint16 year) internal pure returns (uint256) { require(month > 0 && month < 13, InvalidExternalNullifierMonth()); - require(year <= 9999, InvalidExternalNullifierYear()); + require(year < 10000, InvalidExternalNullifierYear()); return (uint32(year) << 16) | (uint32(month) << 8) | uint32(pbhNonce); } diff --git a/pbh-verifier/test/PBHExternalNullifier.t.sol b/pbh-verifier/test/PBHExternalNullifier.t.sol index 4489f627..a9356d5d 100644 --- a/pbh-verifier/test/PBHExternalNullifier.t.sol +++ b/pbh-verifier/test/PBHExternalNullifier.t.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -pragma solidity ^0.8.10; +pragma solidity ^0.8.20; import "forge-std/Test.sol"; import "@helpers/PBHExternalNullifier.sol"; @@ -113,4 +113,4 @@ contract PBHExternalNullifierLibTest is Test { vm.expectRevert(PBHExternalNullifier.InvalidPbhNonce.selector); PBHExternalNullifier.verify(encoded, MAX_PBH_PER_MONTH); } -} \ No newline at end of file +} diff --git a/pbh-verifier/test/PBHVerifier.t.sol b/pbh-verifier/test/PBHVerifier.t.sol index c5f3b9b5..256f45fd 100644 --- a/pbh-verifier/test/PBHVerifier.t.sol +++ b/pbh-verifier/test/PBHVerifier.t.sol @@ -1,5 +1,5 @@ -// SPDX-License-Identifier: UNLICENSED -pragma solidity ^0.8.13; +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.20; import {Test, console} from "forge-std/Test.sol"; import {PBHVerifier} from "../src/PBHVerifier.sol";