Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
0xForerunner committed Dec 12, 2024
1 parent 7af6d9f commit cc3d03a
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 56 deletions.
17 changes: 17 additions & 0 deletions pbh-verifier/Dockerfile
Original file line number Diff line number Diff line change
@@ -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 []
18 changes: 18 additions & 0 deletions pbh-verifier/LICENSE.md
Original file line number Diff line number Diff line change
@@ -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.
19 changes: 0 additions & 19 deletions pbh-verifier/script/Counter.s.sol.bak

This file was deleted.

37 changes: 8 additions & 29 deletions pbh-verifier/src/PBHVerifier.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand All @@ -124,4 +104,3 @@ contract PBHVerifier {
emit PBH(nullifierHash);
}
}

2 changes: 1 addition & 1 deletion pbh-verifier/src/helpers/ByteHasher.sol
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
5 changes: 2 additions & 3 deletions pbh-verifier/src/helpers/PBHExternalNullifier.sol
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.10;
pragma solidity ^0.8.20;

import "@BokkyPooBahsDateTimeLibrary/BokkyPooBahsDateTimeLibrary.sol";

/// @title PBHExternalNullifierLib
/// @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
Expand All @@ -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);
}

Expand Down
4 changes: 2 additions & 2 deletions pbh-verifier/test/PBHExternalNullifier.t.sol
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -113,4 +113,4 @@ contract PBHExternalNullifierLibTest is Test {
vm.expectRevert(PBHExternalNullifier.InvalidPbhNonce.selector);
PBHExternalNullifier.verify(encoded, MAX_PBH_PER_MONTH);
}
}
}
4 changes: 2 additions & 2 deletions pbh-verifier/test/PBHVerifier.t.sol
Original file line number Diff line number Diff line change
@@ -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";
Expand Down

0 comments on commit cc3d03a

Please sign in to comment.