This commit is contained in:
rymnc 2024-05-29 13:39:15 +05:30
parent 43ed082e34
commit 7120f2f990
No known key found for this signature in database
GPG Key ID: AAA088D5C68ECD34
3 changed files with 40 additions and 8 deletions

View File

@ -4,19 +4,30 @@ pragma solidity >=0.8.19 <=0.9.0;
import { WakuRlnV2 } from "../src/WakuRlnV2.sol";
import { PoseidonT3 } from "poseidon-solidity/PoseidonT3.sol";
import { LazyIMT } from "@zk-kit/imt.sol/LazyIMT.sol";
import {ERC1967Proxy} from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol";
import { BaseScript } from "./Base.s.sol";
import "forge-std/console.sol";
import { Upgrades, Options } from "openzeppelin-foundry-upgrades/Upgrades.sol";
import { DeploymentConfig } from "./DeploymentConfig.s.sol";
contract Deploy is BaseScript {
function run() public broadcast returns (WakuRlnV2 w) {
Options memory opts;
function run() public broadcast returns (WakuRlnV2 w, address impl) {
/*opts.unsafeAllow = "external-library-linking";*/
opts.unsafeSkipAllChecks = true;
/*opts.unsafeSkipAllChecks = true;
address proxy = Upgrades.deployTransparentProxy(
"WakuRlnV2.sol:WakuRlnV2", msg.sender, abi.encodeCall(WakuRlnV2.initialize, (msg.sender, 20)), opts
);
w = WakuRlnV2(proxy);*/
/*poseidonHasher = new PoseidonHasher();
address implementation = address(new WakuRlnRegistry());
bytes memory data = abi.encodeCall(WakuRlnRegistry.initialize, address(poseidonHasher));
address proxy = address(new ERC1967Proxy(implementation, data));
wakuRlnRegistry = WakuRlnRegistry(proxy);*/
impl = address(new WakuRlnV2());
bytes memory data = abi.encodeCall(WakuRlnV2.initialize, (msg.sender, 20));
address proxy = address(new ERC1967Proxy(impl, data));
w = WakuRlnV2(proxy);
}
}

View File

@ -4,8 +4,9 @@ pragma solidity 0.8.24;
import { LazyIMT, LazyIMTData } from "@zk-kit/imt.sol/LazyIMT.sol";
import { PoseidonT3 } from "poseidon-solidity/PoseidonT3.sol";
import { OwnableUpgradeable } from "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
import { Initializable } from "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import {OwnableUpgradeable} from "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
import {Initializable} from "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import {UUPSUpgradeable} from "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";
/// The tree is full
error FullTree();
@ -22,7 +23,7 @@ error InvalidUserMessageLimit(uint32 messageLimit);
/// Invalid pagination query
error InvalidPaginationQuery(uint256 startIndex, uint256 endIndex);
contract WakuRlnV2 is Initializable, OwnableUpgradeable {
contract WakuRlnV2 is Initializable, OwnableUpgradeable, UUPSUpgradeable {
/// @notice The Field
uint256 public constant Q =
21_888_242_871_839_275_222_246_405_745_257_275_088_548_364_400_416_034_343_698_204_186_575_808_495_617;
@ -76,8 +77,14 @@ contract WakuRlnV2 is Initializable, OwnableUpgradeable {
_;
}
/// @custom:oz-upgrades-unsafe-allow constructor
constructor() {
_disableInitializers();
}
function initialize(address initialOwner, uint32 maxMessageLimit) public initializer {
__Ownable_init(initialOwner);
__UUPSUpgradeable_init();
MAX_MESSAGE_LIMIT = maxMessageLimit;
SET_SIZE = uint32(1 << DEPTH);
deployedBlockNumber = uint32(block.number);
@ -85,6 +92,8 @@ contract WakuRlnV2 is Initializable, OwnableUpgradeable {
idCommitmentIndex = 0;
}
function _authorizeUpgrade(address newImplementation) internal override onlyOwner {}
/// @notice Checks if a commitment is valid
/// @param idCommitment The idCommitment of the member
/// @return true if the commitment is valid, false otherwise

View File

@ -14,13 +14,14 @@ contract WakuRlnV2Test is Test {
using stdStorage for StdStorage;
WakuRlnV2 internal w;
address internal impl;
DeploymentConfig internal deploymentConfig;
address internal deployer;
function setUp() public virtual {
Deploy deployment = new Deploy();
w = deployment.run();
(w, impl) = deployment.run();
}
function test__ValidRegistration__kats() external {
@ -137,7 +138,18 @@ contract WakuRlnV2Test is Test {
function test__InvalidRegistration__FullTree() external {
uint32 userMessageLimit = 2;
// we progress the tree to the last leaf
stdstore.target(address(w)).sig("idCommitmentIndex()").checked_write(1 << w.DEPTH());
/*| Name | Type | Slot | Offset | Bytes |
|---------------------|-----------------------------------------------------|------|--------|-------|
| MAX_MESSAGE_LIMIT | uint32 | 0 | 0 | 4 |
| SET_SIZE | uint32 | 0 | 4 | 4 |
| idCommitmentIndex | uint32 | 0 | 8 | 4 |
| memberInfo | mapping(uint256 => struct WakuRlnV2.MembershipInfo) | 1 | 0 | 32 |
| deployedBlockNumber | uint32 | 2 | 0 | 4 |
| imtData | struct LazyIMTData | 3 | 0 | 64 |*/
// we set MAX_MESSAGE_LIMIT to 20 (unaltered)
// we set SET_SIZE to 4294967295 (1 << 20) (unaltered)
// we set idCommitmentIndex to 4294967295 (1 << 20) (altered)
vm.store(address(w), bytes32(0), 0x0000000000000000000000000000000000000000ffffffffffffffff00000014);
vm.expectRevert(FullTree.selector);
w.register(1, userMessageLimit);
}