Skip to content

Commit

Permalink
chore: patch foundry template to main branch
Browse files Browse the repository at this point in the history
  • Loading branch information
rymnc committed Jan 11, 2024
1 parent a647a84 commit 8c50b13
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 250 deletions.
80 changes: 0 additions & 80 deletions deployments/11155111/latest.json

This file was deleted.

54 changes: 10 additions & 44 deletions deployments/1442/latest.json

Large diffs are not rendered by default.

46 changes: 1 addition & 45 deletions script/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -67,53 +67,9 @@ if [ "$contract_name" = "rln" ]; then
fi


forge script script/Deploy.s.sol:Deploy --chain $chain_name --rpc-url $rpc_url --private-key "$PRIVATE_KEY" --broadcast -v
forge script script/Deploy.s.sol:Deploy --chain $chain_name --rpc-url $rpc_url --private-key "$PRIVATE_KEY" --broadcast --verify
echo "Deployed Rln contracts, Now verifying"

# Get the PoseidonT3 contract address from ./broadcast/Deploy.s.sol/$chain_id/run-latest.json
poseidon_t3_name=$(cat ./broadcast/Deploy.s.sol/$chain_id/run-latest.json | jq -r '.["transactions"][0]["contractName"]')
poseidon_t3_address=$(cat ./broadcast/Deploy.s.sol/$chain_id/run-latest.json | jq -r '.["transactions"][0]["contractAddress"]')

echo "Verifying $poseidon_t3_name library"
forge verify-contract $poseidon_t3_address \
--watch \
--chain $chain_name \
$poseidon_t3_name

# Get the BinaryIMT contract address from ./broadcast/Deploy.s.sol/$chain_id/run-latest.json
binary_imt_name=$(cat ./broadcast/Deploy.s.sol/$chain_id/run-latest.json | jq -r '.["transactions"][1]["contractName"]')
binary_imt_address=$(cat ./broadcast/Deploy.s.sol/$chain_id/run-latest.json | jq -r '.["transactions"][1]["contractAddress"]')

echo "Verifying $binary_imt_name library"
forge verify-contract $binary_imt_address \
--libraries "poseidon-solidity/PoseidonT3.sol:$poseidon_t3_name:$poseidon_t3_address" \
--watch \
--chain $chain_name \
$binary_imt_name

# Get the Verifier contract address from ./broadcast/Deploy.s.sol/$chain_id/run-latest.json
verifier_name=$(cat ./broadcast/Deploy.s.sol/$chain_id/run-latest.json | jq -r '.["transactions"][2]["contractName"]')
verifier_address=$(cat ./broadcast/Deploy.s.sol/$chain_id/run-latest.json | jq -r '.["transactions"][2]["contractAddress"]')

echo "Verifying $verifier_name contract"
forge verify-contract $verifier_address \
--watch \
--chain $chain_name \
$verifier_name

# Get the Rln contract address from ./broadcast/Deploy.s.sol/$chain_id/run-latest.json
rln_name=$(cat ./broadcast/Deploy.s.sol/$chain_id/run-latest.json | jq -r '.["transactions"][3]["contractName"]')
rln_address=$(cat ./broadcast/Deploy.s.sol/$chain_id/run-latest.json | jq -r '.["transactions"][3]["contractAddress"]')

echo "Verifying $rln_name contract"
forge verify-contract $rln_address \
--libraries "poseidon-solidity/PoseidonT3.sol:$poseidon_t3_name:$poseidon_t3_address" \
--libraries "@zk-kit/imt.sol/BinaryIMT.sol:$binary_imt_name:$binary_imt_address" \
--watch \
--chain $chain_name \
$rln_name \
--constructor-args $(cast abi-encode "constructor(uint256,uint256,address)" 0 20 "$verifier_address")

echo "Verified $rln_name contract, now dumping the artifacts to ./deployments/$chain_id/latest.json"

# Dump the artifacts to ./deployments/$chain_id/latest.json
Expand Down
10 changes: 0 additions & 10 deletions src/RlnBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
pragma solidity ^0.8.19;

import { IVerifier } from "./IVerifier.sol";
import { BinaryIMT, BinaryIMTData } from "@zk-kit/imt.sol/BinaryIMT.sol";

/// The tree is full
error FullTree();
Expand Down Expand Up @@ -83,9 +82,6 @@ abstract contract RlnBase {
/// @notice the deployed block number
uint32 public immutable deployedBlockNumber;

/// @notice the Incremental Merkle Tree
BinaryIMTData public imtData;

/// Emitted when a new member is added to the set
/// @param idCommitment The idCommitment of the member
/// @param index The index of the member in the set
Expand All @@ -107,7 +103,6 @@ abstract contract RlnBase {
SET_SIZE = 1 << depth;
verifier = IVerifier(_verifier);
deployedBlockNumber = uint32(block.number);
BinaryIMT.initWithDefaultZeroes(imtData, 20);
}

/// Allows a user to register as a member
Expand All @@ -130,7 +125,6 @@ abstract contract RlnBase {
members[idCommitment] = idCommitmentIndex;
indexToCommitment[idCommitmentIndex] = idCommitment;
memberExists[idCommitment] = true;
BinaryIMT.insert(imtData, idCommitment);
stakedAmounts[idCommitment] = stake;

emit MemberRegistered(idCommitment, idCommitmentIndex);
Expand Down Expand Up @@ -236,10 +230,6 @@ abstract contract RlnBase {
);
}

function root() external view returns (uint256) {
return imtData.root;
}

function getCommitments(uint256 startIndex, uint256 endIndex) public view returns (uint256[] memory) {
if (startIndex >= endIndex) revert InvalidPaginationQuery(startIndex, endIndex);
if (endIndex > idCommitmentIndex) revert InvalidPaginationQuery(startIndex, endIndex);
Expand Down
71 changes: 0 additions & 71 deletions test/Rln.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -198,75 +198,4 @@ contract RlnTest is Test {
rln.withdraw();
assertEq(rln.withdrawalBalance(to), 0);
}

function test__root() public {
uint256[] memory idCommitments = new uint256[](10);
idCommitments[0] =
19_143_711_682_366_759_980_911_001_457_853_255_795_836_264_632_723_844_153_354_310_748_778_748_156_460;
idCommitments[1] =
16_984_765_328_852_711_772_291_441_487_727_981_184_905_800_779_020_079_168_989_152_080_434_188_364_678;
idCommitments[2] =
10_972_315_136_095_845_343_447_418_815_139_813_428_649_316_683_283_020_632_475_608_655_814_722_712_541;
idCommitments[3] =
2_709_631_781_045_191_277_266_130_708_832_884_002_577_134_582_503_944_059_038_971_337_978_087_532_997;
idCommitments[4] =
8_255_654_132_980_945_447_086_418_574_686_169_461_187_805_238_257_784_695_584_517_016_324_877_809_505;
idCommitments[5] =
20_291_701_150_251_695_209_910_387_548_168_084_091_751_201_746_043_024_067_531_503_187_703_236_470_983;
idCommitments[6] =
11_817_872_986_033_932_471_261_438_074_921_403_500_882_957_864_164_537_515_599_299_873_089_437_746_577;
idCommitments[7] =
18_475_838_919_635_792_169_148_272_767_721_284_591_038_756_730_004_222_133_003_018_558_598_315_558_783;
idCommitments[8] =
10_612_118_277_928_165_031_660_389_522_171_737_855_229_037_400_929_675_201_853_245_490_188_277_695_983;
idCommitments[9] =
17_318_633_845_296_358_766_427_229_711_888_486_415_250_435_256_643_711_009_388_405_482_885_762_601_797;

vm.pauseGasMetering();
for (uint256 i = 0; i < idCommitments.length; i++) {
rln.register{ value: MEMBERSHIP_DEPOSIT }(idCommitments[i]);
}
vm.resumeGasMetering();

assertEq(
rln.root(),
5_210_724_218_081_541_877_101_688_952_118_136_930_297_124_697_603_087_561_558_225_712_176_057_209_122
);
}

function test__paginationCommitments() public {
uint256[] memory idCommitments = new uint256[](10);
idCommitments[0] =
19_143_711_682_366_759_980_911_001_457_853_255_795_836_264_632_723_844_153_354_310_748_778_748_156_460;
idCommitments[1] =
16_984_765_328_852_711_772_291_441_487_727_981_184_905_800_779_020_079_168_989_152_080_434_188_364_678;
idCommitments[2] =
10_972_315_136_095_845_343_447_418_815_139_813_428_649_316_683_283_020_632_475_608_655_814_722_712_541;
idCommitments[3] =
2_709_631_781_045_191_277_266_130_708_832_884_002_577_134_582_503_944_059_038_971_337_978_087_532_997;
idCommitments[4] =
8_255_654_132_980_945_447_086_418_574_686_169_461_187_805_238_257_784_695_584_517_016_324_877_809_505;
idCommitments[5] =
20_291_701_150_251_695_209_910_387_548_168_084_091_751_201_746_043_024_067_531_503_187_703_236_470_983;
idCommitments[6] =
11_817_872_986_033_932_471_261_438_074_921_403_500_882_957_864_164_537_515_599_299_873_089_437_746_577;
idCommitments[7] =
18_475_838_919_635_792_169_148_272_767_721_284_591_038_756_730_004_222_133_003_018_558_598_315_558_783;
idCommitments[8] =
10_612_118_277_928_165_031_660_389_522_171_737_855_229_037_400_929_675_201_853_245_490_188_277_695_983;
idCommitments[9] =
17_318_633_845_296_358_766_427_229_711_888_486_415_250_435_256_643_711_009_388_405_482_885_762_601_797;

vm.pauseGasMetering();
for (uint256 i = 0; i < idCommitments.length; i++) {
rln.register{ value: MEMBERSHIP_DEPOSIT }(idCommitments[i]);
}
vm.resumeGasMetering();

uint256[] memory commitments = rln.getCommitments(0, 10);
assertEq(commitments.length, 10);
for (uint256 i = 0; i < commitments.length; i++) {
assertEq(commitments[i], idCommitments[i]);
}
}
}

0 comments on commit 8c50b13

Please sign in to comment.