Skip to content

Commit 96a3312

Browse files
authored
Merge pull request #14 from privacy-scaling-explorations/feat/aggregation
Standardization for aggregation module
2 parents 3851bbc + fd66efc commit 96a3312

22 files changed

+952
-704
lines changed

packages/contracts/contracts/src/AdvancedChecker.sol

+9-6
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,22 @@
22
pragma solidity ^0.8.20;
33

44
import {IAdvancedChecker, Check, CheckStatus} from "./interfaces/IAdvancedChecker.sol";
5+
import {Checker} from "./Checker.sol";
56

67
/// @title AdvancedChecker.
78
/// @notice Multi-phase validation checker with pre, main, and post checks.
89
/// @dev Base contract for implementing complex validation logic with configurable check phases.
9-
abstract contract AdvancedChecker is IAdvancedChecker {
10+
abstract contract AdvancedChecker is IAdvancedChecker, Checker {
11+
constructor(address[] memory _verifiers) Checker(_verifiers) {}
12+
1013
/// @notice Entry point for validation checks.
1114
/// @param subject Address to validate.
1215
/// @param evidence Validation data.
1316
/// @param checkType Type of check (PRE, MAIN, POST).
1417
/// @return checked Validation result.
1518
function check(
1619
address subject,
17-
bytes memory evidence,
20+
bytes[] calldata evidence,
1821
Check checkType
1922
) external view override returns (bool checked) {
2023
return _check(subject, evidence, checkType);
@@ -26,7 +29,7 @@ abstract contract AdvancedChecker is IAdvancedChecker {
2629
/// @param evidence Validation data.
2730
/// @param checkType Check type to perform.
2831
/// @return checked Validation result.
29-
function _check(address subject, bytes memory evidence, Check checkType) internal view returns (bool checked) {
32+
function _check(address subject, bytes[] calldata evidence, Check checkType) internal view returns (bool checked) {
3033
if (checkType == Check.PRE) {
3134
return _checkPre(subject, evidence);
3235
}
@@ -43,19 +46,19 @@ abstract contract AdvancedChecker is IAdvancedChecker {
4346
/// @param subject Address to validate.
4447
/// @param evidence Validation data.
4548
/// @return checked Validation result.
46-
function _checkPre(address subject, bytes memory evidence) internal view virtual returns (bool checked) {}
49+
function _checkPre(address subject, bytes[] calldata evidence) internal view virtual returns (bool checked) {}
4750

4851
/// @notice Main validation implementation.
4952
/// @dev Override to implement main check logic.
5053
/// @param subject Address to validate.
5154
/// @param evidence Validation data.
5255
/// @return checked Validation result.
53-
function _checkMain(address subject, bytes memory evidence) internal view virtual returns (bool checked) {}
56+
function _checkMain(address subject, bytes[] calldata evidence) internal view virtual returns (bool checked) {}
5457

5558
/// @notice Post-condition validation implementation.
5659
/// @dev Override to implement post-check logic.
5760
/// @param subject Address to validate.
5861
/// @param evidence Validation data.
5962
/// @return checked Validation result.
60-
function _checkPost(address subject, bytes memory evidence) internal view virtual returns (bool checked) {}
63+
function _checkPost(address subject, bytes[] calldata evidence) internal view virtual returns (bool checked) {}
6164
}

packages/contracts/contracts/src/AdvancedPolicy.sol

+2-2
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ abstract contract AdvancedPolicy is IAdvancedPolicy, Policy {
4343
/// @param subject Address to validate.
4444
/// @param evidence Validation data.
4545
/// @param checkType Type of check (PRE, MAIN, POST).
46-
function enforce(address subject, bytes calldata evidence, Check checkType) external override onlyTarget {
46+
function enforce(address subject, bytes[] calldata evidence, Check checkType) external override onlyTarget {
4747
_enforce(subject, evidence, checkType);
4848
}
4949

@@ -59,7 +59,7 @@ abstract contract AdvancedPolicy is IAdvancedPolicy, Policy {
5959
/// @custom:throws PreCheckNotEnforced If PRE check is required but not done.
6060
/// @custom:throws MainCheckNotEnforced If MAIN check is required but not done.
6161
/// @custom:throws MainCheckAlreadyEnforced If multiple MAIN checks not allowed.
62-
function _enforce(address subject, bytes calldata evidence, Check checkType) internal {
62+
function _enforce(address subject, bytes[] calldata evidence, Check checkType) internal {
6363
if (!ADVANCED_CHECKER.check(subject, evidence, checkType)) {
6464
revert UnsuccessfulCheck();
6565
}

packages/contracts/contracts/src/BaseChecker.sol

+6-3
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,21 @@
22
pragma solidity ^0.8.20;
33

44
import {IBaseChecker} from "./interfaces/IBaseChecker.sol";
5+
import {Checker} from "./Checker.sol";
56

67
/// @title BaseChecker
78
/// @notice Abstract base contract for implementing validation checks.
89
/// @dev Provides a standardized interface for implementing custom validation logic
910
/// through the internal _check method.
10-
abstract contract BaseChecker is IBaseChecker {
11+
abstract contract BaseChecker is Checker, IBaseChecker {
12+
constructor(address[] memory _verifiers) Checker(_verifiers) {}
13+
1114
/// @notice Validates evidence for a given subject address.
1215
/// @dev External view function that delegates to internal _check implementation.
1316
/// @param subject Address to validate.
1417
/// @param evidence Custom validation data.
1518
/// @return checked Boolean indicating if the check passed.
16-
function check(address subject, bytes memory evidence) external view override returns (bool checked) {
19+
function check(address subject, bytes[] calldata evidence) external view override returns (bool checked) {
1720
return _check(subject, evidence);
1821
}
1922

@@ -22,5 +25,5 @@ abstract contract BaseChecker is IBaseChecker {
2225
/// @param subject Address to validate.
2326
/// @param evidence Custom validation data.
2427
/// @return checked Boolean indicating if the check passed.
25-
function _check(address subject, bytes memory evidence) internal view virtual returns (bool checked) {}
28+
function _check(address subject, bytes[] calldata evidence) internal view virtual returns (bool checked) {}
2629
}

packages/contracts/contracts/src/BasePolicy.sol

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ abstract contract BasePolicy is Policy, IBasePolicy {
3535
/// @custom:throws AlreadyEnforced if check was previously enforced.
3636
/// @custom:throws UnsuccessfulCheck if the check fails.
3737
/// @custom:emits Enforced when check succeeds.
38-
function enforce(address subject, bytes calldata evidence) external override onlyTarget {
38+
function enforce(address subject, bytes[] calldata evidence) external override onlyTarget {
3939
_enforce(subject, evidence);
4040
}
4141

@@ -45,7 +45,7 @@ abstract contract BasePolicy is Policy, IBasePolicy {
4545
/// @param evidence Additional data required for verification.
4646
/// @custom:throws AlreadyEnforced if already enforced for this subject.
4747
/// @custom:throws UnsuccessfulCheck if BASE_CHECKER.check returns false.
48-
function _enforce(address subject, bytes calldata evidence) internal {
48+
function _enforce(address subject, bytes[] memory evidence) internal {
4949
bool checked = BASE_CHECKER.check(subject, evidence);
5050

5151
if (enforced[msg.sender][subject]) revert AlreadyEnforced();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// SPDX-License-Identifier: MIT
2+
pragma solidity ^0.8.20;
3+
4+
import {IChecker} from "./interfaces/IChecker.sol";
5+
6+
/// @title Checker
7+
/// @notice Abstract base contract for implementing attribute verification logic.
8+
/// @dev Provides infrastructure to orchestrate third-party verifiers for single checks.
9+
abstract contract Checker is IChecker {
10+
/// @notice Array of third-party contract addresses used for verification.
11+
/// @dev Can include existing and already deployed Checkers, NFTs, MACI polls, and/or any other contract
12+
/// that provides evidence verification. These contracts should already be deployed and operational.
13+
address[] internal verifiers;
14+
15+
/// @notice Initializes the Checker with an optional list of third-party verification contracts.
16+
/// @param _verifiers Array of addresses for existing verification contracts.
17+
/// @dev Each address should point to a deployed contract that will be consulted during verification.
18+
/// This array can remain empty if there's no reliance on external verifiers.
19+
constructor(address[] memory _verifiers) {
20+
verifiers = _verifiers;
21+
}
22+
23+
/// @notice Retrieves the verifier address at a specific index.
24+
/// @param index The index of the verifier in the array.
25+
/// @return The address of the verifier at the specified index.
26+
/// @custom:throws VerifierNotFound if no address have been specified at given index.
27+
function getVerifierAtIndex(uint256 index) external view returns (address) {
28+
return _getVerifierAtIndex(index);
29+
}
30+
31+
/// @notice Internal implementation of verifier address retrieval at a specific index.
32+
/// @param index The index of the verifier in the array.
33+
/// @return The address of the verifier at the specified index.
34+
/// @custom:throws VerifierNotFound if no address have been specified at given index.
35+
function _getVerifierAtIndex(uint256 index) internal view returns (address) {
36+
if (index >= verifiers.length) revert VerifierNotFound();
37+
38+
return verifiers[index];
39+
}
40+
}

packages/contracts/contracts/src/interfaces/IAdvancedChecker.sol

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// SPDX-License-Identifier: MIT
22
pragma solidity ^0.8.20;
33

4+
import {IChecker} from "./IChecker.sol";
5+
46
/// @title Check.
57
/// @notice Defines validation phases in the AdvancedChecker system.
68
/// @custom:values PRE - Pre-condition validation.
@@ -26,11 +28,11 @@ struct CheckStatus {
2628
/// @title IAdvancedChecker.
2729
/// @notice Defines multi-phase validation system interface.
2830
/// @dev Implement this for custom validation logic with pre/main/post checks.
29-
interface IAdvancedChecker {
31+
interface IAdvancedChecker is IChecker {
3032
/// @notice Validates subject against specified check type.
3133
/// @param subject Address to validate.
3234
/// @param evidence Validation data.
3335
/// @param checkType Check phase to execute.
3436
/// @return checked True if validation passes.
35-
function check(address subject, bytes calldata evidence, Check checkType) external view returns (bool checked);
37+
function check(address subject, bytes[] calldata evidence, Check checkType) external view returns (bool checked);
3638
}

packages/contracts/contracts/src/interfaces/IAdvancedPolicy.sol

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@ interface IAdvancedPolicy is IPolicy {
2727
/// @param target Protected contract address.
2828
/// @param evidence Validation data.
2929
/// @param checkType Type of check performed.
30-
event Enforced(address indexed subject, address indexed target, bytes evidence, Check checkType);
30+
event Enforced(address indexed subject, address indexed target, bytes[] evidence, Check checkType);
3131

3232
/// @notice Enforces validation check on subject.
3333
/// @dev Delegates to appropriate check method based on checkType.
3434
/// @param subject Address to validate.
3535
/// @param evidence Validation data.
3636
/// @param checkType Check phase to execute.
37-
function enforce(address subject, bytes calldata evidence, Check checkType) external;
37+
function enforce(address subject, bytes[] calldata evidence, Check checkType) external;
3838
}
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
// SPDX-License-Identifier: MIT
22
pragma solidity ^0.8.20;
33

4+
import {IChecker} from "./IChecker.sol";
5+
46
/// @title IBaseChecker.
57
/// @notice Defines base validation functionality.
6-
interface IBaseChecker {
8+
interface IBaseChecker is IChecker {
79
/// @notice Validates subject against evidence.
810
/// @param subject Address to validate.
911
/// @param evidence Validation data.
1012
/// @return checked True if validation passes.
11-
function check(address subject, bytes calldata evidence) external view returns (bool checked);
13+
function check(address subject, bytes[] calldata evidence) external view returns (bool checked);
1214
}

packages/contracts/contracts/src/interfaces/IBasePolicy.sol

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ interface IBasePolicy is IPolicy {
1010
/// @param subject Address that passed validation.
1111
/// @param target Protected contract address.
1212
/// @param evidence Validation data.
13-
event Enforced(address indexed subject, address indexed target, bytes evidence);
13+
event Enforced(address indexed subject, address indexed target, bytes[] evidence);
1414

1515
/// @notice Enforces validation check on subject.
1616
/// @param subject Address to validate.
1717
/// @param evidence Validation data.
18-
function enforce(address subject, bytes calldata evidence) external;
18+
function enforce(address subject, bytes[] calldata evidence) external;
1919
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// SPDX-License-Identifier: MIT
2+
pragma solidity ^0.8.20;
3+
4+
/// @title IChecker
5+
/// @notice Core checker interface for attribute verification functionalities.
6+
interface IChecker {
7+
/// @notice Core error conditions.
8+
error VerifierNotFound();
9+
10+
/// @notice Retrieves the verifier address at a specific index.
11+
/// @param index The index of the verifier in the array.
12+
/// @return The address of the verifier at the specified index.
13+
/// @custom:throws VerifierNotFound if no address have been specified at given index.
14+
function getVerifierAtIndex(uint256 index) external view returns (address);
15+
}

0 commit comments

Comments
 (0)