Merge pull request #5 from waku-org/downstream-deployed-block-number
Downstream deployedBlockNumber to waku-rln-contract
This commit is contained in:
commit
3402f957dd
|
@ -1,7 +1,7 @@
|
|||
[submodule "lib/forge-std"]
|
||||
path = lib/forge-std
|
||||
url = https://github.com/foundry-rs/forge-std
|
||||
branch = v1.5.2
|
||||
branch = v1.6.0
|
||||
[submodule "lib/rln-contract"]
|
||||
path = lib/rln-contract
|
||||
url = https://github.com/vacp2p/rln-contract
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
pragma solidity 0.8.15;
|
||||
|
||||
import {IPoseidonHasher} from "rln-contract/PoseidonHasher.sol";
|
||||
import {RlnBase, DuplicateIdCommitment, FullTree} from "rln-contract/RlnBase.sol";
|
||||
import {RlnBase, DuplicateIdCommitment, FullTree, InvalidIdCommitment} from "rln-contract/RlnBase.sol";
|
||||
import {Ownable} from "openzeppelin-contracts/contracts/access/Ownable.sol";
|
||||
|
||||
error NotImplemented();
|
||||
|
@ -44,6 +44,7 @@ contract WakuRln is Ownable, RlnBase {
|
|||
}
|
||||
|
||||
function _validateRegistration(uint256 idCommitment) internal view override {
|
||||
if (!isValidCommitment(idCommitment)) revert InvalidIdCommitment(idCommitment);
|
||||
if (members[idCommitment] != 0) revert DuplicateIdCommitment();
|
||||
if (idCommitmentIndex >= SET_SIZE) revert FullTree();
|
||||
}
|
||||
|
|
|
@ -7,6 +7,4 @@ cache_path = 'cache_forge'
|
|||
|
||||
# 5667: Unused function parameter. Remove or comment out the variable name to silence this warning.
|
||||
# 5740: Unreachable code.
|
||||
ignored_error_codes = [5667, 5740]
|
||||
# setting this to allow expensive larger inserts during tests
|
||||
memory_limit = 100_000_000
|
||||
ignored_error_codes = [5667, 5740]
|
|
@ -1 +1 @@
|
|||
Subproject commit 2b58ecbcf3dfde7a75959dc7b4eb3d0670278de6
|
||||
Subproject commit 74cfb77e308dd188d2f58864aaf44963ae6b88b1
|
|
@ -1 +1 @@
|
|||
Subproject commit a092b934a6293203abbd4b9e3412db23ff59877e
|
||||
Subproject commit bd8403a74e327707afb70e60f582e2546e487891
|
|
@ -29,12 +29,14 @@ contract WakuRlnTest is Test {
|
|||
function test__Constants() public {
|
||||
assertEq(wakuRln.DEPTH(), DEPTH);
|
||||
assertEq(wakuRln.SET_SIZE(), SET_SIZE);
|
||||
assertEq(wakuRln.deployedBlockNumber(), block.number);
|
||||
}
|
||||
|
||||
function test__ValidRegistration(uint256[] calldata idCommitments) public {
|
||||
// Register a batch of commitments
|
||||
vm.assume(idCommitments.length < 10_000);
|
||||
vm.assume(noDuplicate(idCommitments));
|
||||
vm.assume(noInvalidCommitment(idCommitments, poseidon.Q()));
|
||||
wakuRln.register(idCommitments);
|
||||
}
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@ pragma solidity ^0.8.15;
|
|||
import "../contracts/WakuRlnRegistry.sol";
|
||||
import {PoseidonHasher} from "rln-contract/PoseidonHasher.sol";
|
||||
import {DuplicateIdCommitment, FullTree} from "rln-contract/RlnBase.sol";
|
||||
import {noDuplicate} from "./utils.sol";
|
||||
import {noDuplicate, noInvalidCommitment, isValidCommitment} from "./utils.sol";
|
||||
import "forge-std/Test.sol";
|
||||
import "forge-std/StdCheats.sol";
|
||||
|
||||
|
@ -37,12 +37,14 @@ contract WakuRlnRegistryTest is Test {
|
|||
}
|
||||
|
||||
function test__Register(uint256[] calldata commitments) public {
|
||||
vm.assume(noInvalidCommitment(commitments, poseidonHasher.Q()));
|
||||
vm.assume(noDuplicate(commitments));
|
||||
wakuRlnRegistry.newStorage();
|
||||
wakuRlnRegistry.register(commitments);
|
||||
}
|
||||
|
||||
function test__InvalidRegistration_Duplicate(uint256[] calldata commitments) public {
|
||||
vm.assume(noInvalidCommitment(commitments, poseidonHasher.Q()));
|
||||
vm.assume(!noDuplicate(commitments));
|
||||
wakuRlnRegistry.newStorage();
|
||||
vm.expectRevert(DuplicateIdCommitment.selector);
|
||||
|
@ -56,17 +58,20 @@ contract WakuRlnRegistryTest is Test {
|
|||
}
|
||||
|
||||
function test__SingleRegistration(uint256 commitment) public {
|
||||
vm.assume(isValidCommitment(commitment, poseidonHasher.Q()));
|
||||
wakuRlnRegistry.newStorage();
|
||||
wakuRlnRegistry.register(0, commitment);
|
||||
}
|
||||
|
||||
function test__InvalidSingleRegistration__NoStorageContract(uint256 commitment) public {
|
||||
wakuRlnRegistry.newStorage();
|
||||
vm.assume(isValidCommitment(commitment, poseidonHasher.Q()));
|
||||
vm.expectRevert(NoStorageContractAvailable.selector);
|
||||
wakuRlnRegistry.register(1, commitment);
|
||||
}
|
||||
|
||||
function test__InvalidSingleRegistration__Duplicate(uint256 commitment) public {
|
||||
vm.assume(isValidCommitment(commitment, poseidonHasher.Q()));
|
||||
wakuRlnRegistry.newStorage();
|
||||
wakuRlnRegistry.register(0, commitment);
|
||||
vm.expectRevert(DuplicateIdCommitment.selector);
|
||||
|
@ -74,29 +79,29 @@ contract WakuRlnRegistryTest is Test {
|
|||
}
|
||||
|
||||
function test__InvalidSingleRegistration__FullTree() public {
|
||||
vm.pauseGasMetering();
|
||||
wakuRlnRegistry.newStorage();
|
||||
WakuRln wakuRln = WakuRln(wakuRlnRegistry.storages(0));
|
||||
uint256 setSize = wakuRln.SET_SIZE();
|
||||
// setSize - 1 because RlnBase uses 1-indexing
|
||||
for (uint256 i = 0; i < setSize - 1; i++) {
|
||||
wakuRlnRegistry.register(0, i);
|
||||
}
|
||||
vm.resumeGasMetering();
|
||||
uint256[] memory commitments = new uint256[](1);
|
||||
|
||||
vm.mockCallRevert(
|
||||
address(wakuRln),
|
||||
abi.encodeWithSignature("register(uint256[])", commitments),
|
||||
abi.encodeWithSelector(FullTree.selector)
|
||||
);
|
||||
vm.expectRevert(FullTree.selector);
|
||||
wakuRlnRegistry.register(0, setSize);
|
||||
wakuRlnRegistry.register(0, commitments[0]);
|
||||
}
|
||||
|
||||
function test__InvalidRegistration__NoStorageContract() public {
|
||||
vm.pauseGasMetering();
|
||||
wakuRlnRegistry.newStorage();
|
||||
address storageContract = wakuRlnRegistry.storages(0);
|
||||
uint256 setSize = WakuRln(storageContract).SET_SIZE();
|
||||
WakuRln wakuRln = WakuRln(wakuRlnRegistry.storages(0));
|
||||
|
||||
uint256[] memory commitments = new uint256[](setSize);
|
||||
for (uint256 i = 1; i < setSize; i++) {
|
||||
commitments[i] = i;
|
||||
}
|
||||
uint256[] memory commitments = new uint256[](1);
|
||||
vm.mockCallRevert(
|
||||
address(wakuRln),
|
||||
abi.encodeWithSignature("register(uint256[])", commitments),
|
||||
abi.encodeWithSelector(FullTree.selector)
|
||||
);
|
||||
vm.expectRevert(NoStorageContractAvailable.selector);
|
||||
wakuRlnRegistry.register(commitments);
|
||||
}
|
||||
|
|
|
@ -12,3 +12,17 @@ function noDuplicate(uint256[] calldata ids) pure returns (bool) {
|
|||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
function noInvalidCommitment(uint256[] calldata ids, uint256 p) pure returns (bool) {
|
||||
uint256 len = ids.length;
|
||||
for (uint256 i = 0; i < len; i++) {
|
||||
if (!isValidCommitment(ids[i], p)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
function isValidCommitment(uint256 id, uint256 p) pure returns (bool) {
|
||||
return id < p && id != 0;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue