From 3c44548f07acafd91c3f718dcafe607a998ed8c6 Mon Sep 17 00:00:00 2001 From: 0xKitsune <0xkitsune@protonmail.com> Date: Fri, 10 Jan 2025 09:26:46 -0500 Subject: [PATCH 1/2] minor cleanup --- contracts/src/PBH4337Module.sol | 14 ++++++++ contracts/src/PBHEntryPointImplV1.sol | 44 ++++++++++++------------ contracts/src/PBHSignatureAggregator.sol | 22 +++++++++--- 3 files changed, 53 insertions(+), 27 deletions(-) diff --git a/contracts/src/PBH4337Module.sol b/contracts/src/PBH4337Module.sol index cd1428d5..ff9de9c0 100644 --- a/contracts/src/PBH4337Module.sol +++ b/contracts/src/PBH4337Module.sol @@ -9,17 +9,27 @@ import {ISafe} from "@4337/interfaces/Safe.sol"; import {SafeModuleSignatures} from "./lib/SafeModuleSignatures.sol"; contract PBHSafe4337Module is Safe4337Module { + /////////////////////////////////////////////////////////////////////////////// + /// STATE VARIABLES /// + ////////////////////////////////////////////////////////////////////////////// + /// @notice The length of an ECDSA signature. uint256 internal constant ECDSA_SIGNATURE_LENGTH = 65; + /// @notice The length of the timestamp bytes. /// @dev 6 bytes each for validAfter and validUntil. uint256 internal constant TIMESTAMP_BYTES = 12; + /// @notice The length of the encoded proof data. uint256 internal constant ENCODED_PROOF_BYTES = 352; /// @notice The PBH Signature Aggregator address. address public immutable PBH_SIGNATURE_AGGREGATOR; + /////////////////////////////////////////////////////////////////////////////// + /// ERRORS /// + ////////////////////////////////////////////////////////////////////////////// + /// @notice The PBH Nonce Key. /// @dev This key is used to identify a PBH user operation. uint192 public immutable PBH_NONCE_KEY; @@ -33,6 +43,10 @@ contract PBHSafe4337Module is Safe4337Module { /// @notice Thrown when the PBH Nonce Key is not initialized. error UninitializedNonceKey(); + /////////////////////////////////////////////////////////////////////////////// + /// FUNCTIONS /// + /////////////////////////////////////////////////////////////////////////////// + constructor(address entryPoint, address _pbhSignatureAggregator, uint192 _pbhNonceKey) Safe4337Module(entryPoint) { require(_pbhSignatureAggregator != address(0), AddressZero()); require(entryPoint != address(0), AddressZero()); diff --git a/contracts/src/PBHEntryPointImplV1.sol b/contracts/src/PBHEntryPointImplV1.sol index 500ec8da..69ab3892 100644 --- a/contracts/src/PBHEntryPointImplV1.sol +++ b/contracts/src/PBHEntryPointImplV1.sol @@ -61,6 +61,28 @@ contract PBHEntryPointImplV1 is IPBHEntryPoint, WorldIDImpl, ReentrancyGuardTran uint256 pbhGasLimit ); + /// @notice Emitted once for each successful PBH verification. + /// + /// @param sender The sender of this particular transaction or UserOp. + /// @param signalHash Signal hash associated with the PBHPayload. + /// @param payload The zero-knowledge proof that demonstrates the claimer is registered with World ID. + event PBH(address indexed sender, uint256 indexed signalHash, PBHPayload payload); + + /// @notice Emitted when the World ID address is set. + /// + /// @param worldId The World ID instance that will be used for verifying proofs. + event WorldIdSet(address indexed worldId); + + /// @notice Emitted when the number of PBH transactions allowed per month is set. + /// + /// @param numPbhPerMonth The number of allowed PBH transactions per month. + event NumPbhPerMonthSet(uint8 indexed numPbhPerMonth); + + /// @notice Emitted when setting the PBH gas limit. + /// + /// @param pbhGasLimit The gas limit for a PBH multicall transaction. + event PBHGasLimitSet(uint256 indexed pbhGasLimit); + /////////////////////////////////////////////////////////////////////////////// /// ERRORS /// ////////////////////////////////////////////////////////////////////////////// @@ -86,28 +108,6 @@ contract PBHEntryPointImplV1 is IPBHEntryPoint, WorldIDImpl, ReentrancyGuardTran /// @notice Thrown when setting the gas limit for a PBH multicall to 0 error InvalidPBHGasLimit(uint256 gasLimit); - /// @notice Emitted once for each successful PBH verification. - /// - /// @param sender The sender of this particular transaction or UserOp. - /// @param signalHash Signal hash associated with the PBHPayload. - /// @param payload The zero-knowledge proof that demonstrates the claimer is registered with World ID. - event PBH(address indexed sender, uint256 indexed signalHash, PBHPayload payload); - - /// @notice Emitted when the World ID address is set. - /// - /// @param worldId The World ID instance that will be used for verifying proofs. - event WorldIdSet(address indexed worldId); - - /// @notice Emitted when the number of PBH transactions allowed per month is set. - /// - /// @param numPbhPerMonth The number of allowed PBH transactions per month. - event NumPbhPerMonthSet(uint8 indexed numPbhPerMonth); - - /// @notice Emitted when setting the PBH gas limit. - /// - /// @param pbhGasLimit The gas limit for a PBH multicall transaction. - event PBHGasLimitSet(uint256 indexed pbhGasLimit); - /////////////////////////////////////////////////////////////////////////////// /// FUNCTIONS /// /////////////////////////////////////////////////////////////////////////////// diff --git a/contracts/src/PBHSignatureAggregator.sol b/contracts/src/PBHSignatureAggregator.sol index 4b55d69a..701a48a4 100644 --- a/contracts/src/PBHSignatureAggregator.sol +++ b/contracts/src/PBHSignatureAggregator.sol @@ -18,6 +18,20 @@ import {SafeModuleSignatures} from "./lib/SafeModuleSignatures.sol"; contract PBHSignatureAggregator is IAggregator { using ByteHasher for bytes; + /////////////////////////////////////////////////////////////////////////////// + /// STATE VARIABLES /// + ////////////////////////////////////////////////////////////////////////////// + + /// @notice The PBHVerifier contract. + IPBHEntryPoint public immutable pbhEntryPoint; + + /// @notice The WorldID contract. + IWorldID public immutable worldID; + + /////////////////////////////////////////////////////////////////////////////// + /// ERRORS /// + ////////////////////////////////////////////////////////////////////////////// + /// @notice Thrown when the Hash of the UserOperations is not /// in transient storage of the `PBHVerifier`. error InvalidUserOperations(); @@ -28,11 +42,9 @@ contract PBHSignatureAggregator is IAggregator { /// @notice Thrown when a zero address is passed as the PBHEntryPoint. error AddressZero(); - /// @notice The PBHVerifier contract. - IPBHEntryPoint public immutable pbhEntryPoint; - - /// @notice The WorldID contract. - IWorldID public immutable worldID; + /////////////////////////////////////////////////////////////////////////////// + /// FUNCTIONS /// + /////////////////////////////////////////////////////////////////////////////// constructor(address _pbhEntryPoint, address _worldID) { require(_pbhEntryPoint != address(0), AddressZero()); From 5b70cded5beb2a35ffaa58e47bbc53439d6d657b Mon Sep 17 00:00:00 2001 From: 0xKitsune <0xkitsune@protonmail.com> Date: Fri, 10 Jan 2025 10:23:40 -0500 Subject: [PATCH 2/2] move PBH_NONCE_KEY to state variables --- contracts/src/PBH4337Module.sol | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/contracts/src/PBH4337Module.sol b/contracts/src/PBH4337Module.sol index ff9de9c0..3f2e509d 100644 --- a/contracts/src/PBH4337Module.sol +++ b/contracts/src/PBH4337Module.sol @@ -26,14 +26,14 @@ contract PBHSafe4337Module is Safe4337Module { /// @notice The PBH Signature Aggregator address. address public immutable PBH_SIGNATURE_AGGREGATOR; - /////////////////////////////////////////////////////////////////////////////// - /// ERRORS /// - ////////////////////////////////////////////////////////////////////////////// - /// @notice The PBH Nonce Key. /// @dev This key is used to identify a PBH user operation. uint192 public immutable PBH_NONCE_KEY; + /////////////////////////////////////////////////////////////////////////////// + /// ERRORS /// + ////////////////////////////////////////////////////////////////////////////// + /// @notice Thrown when the proof size is invalid. error InvalidProofSize();