-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: constraint on bn254 values #26
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,12 +37,14 @@ contract RlnTest is Test { | |
} | ||
|
||
function test__ValidRegistration(uint256 idCommitment) public { | ||
vm.assume(rln.isValidCommitment(idCommitment)); | ||
rln.register{value: MEMBERSHIP_DEPOSIT}(idCommitment); | ||
assertEq(rln.stakedAmounts(idCommitment), MEMBERSHIP_DEPOSIT); | ||
assertEq(rln.members(idCommitment), 1); | ||
} | ||
|
||
function test__InvalidRegistration__DuplicateCommitment(uint256 idCommitment) public { | ||
vm.assume(rln.isValidCommitment(idCommitment)); | ||
rln.register{value: MEMBERSHIP_DEPOSIT}(idCommitment); | ||
assertEq(rln.stakedAmounts(idCommitment), MEMBERSHIP_DEPOSIT); | ||
assertEq(rln.members(idCommitment), 1); | ||
|
@@ -51,26 +53,26 @@ contract RlnTest is Test { | |
} | ||
|
||
function test__InvalidRegistration__InsufficientDeposit(uint256 idCommitment) public { | ||
vm.assume(rln.isValidCommitment(idCommitment)); | ||
uint256 badDepositAmount = MEMBERSHIP_DEPOSIT - 1; | ||
vm.expectRevert(abi.encodeWithSelector(InsufficientDeposit.selector, MEMBERSHIP_DEPOSIT, badDepositAmount)); | ||
rln.register{value: badDepositAmount}(idCommitment); | ||
} | ||
|
||
function test__InvalidRegistration__FullSet(uint256 idCommitmentSeed) public { | ||
vm.assume(idCommitmentSeed < 2 ** 255 - SET_SIZE); | ||
function test__InvalidRegistration__FullSet() public { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just for me to understand: why did we move away from a fuzz test here? Has anything changed with regards to the seed that we can't/aren't relying on it anymore? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. technically we are not testing any logic here, we're just checking if an error is thrown based on the size of the tree - thats why we dont need to fuzz id commitments here |
||
Rln tempRln = new Rln( | ||
MEMBERSHIP_DEPOSIT, | ||
2, | ||
address(rln.poseidonHasher()), | ||
address(rln.verifier()) | ||
); | ||
uint256 setSize = tempRln.SET_SIZE() - 1; | ||
for (uint256 i = 0; i < setSize; i++) { | ||
tempRln.register{value: MEMBERSHIP_DEPOSIT}(idCommitmentSeed + i); | ||
for (uint256 i = 1; i <= setSize; i++) { | ||
tempRln.register{value: MEMBERSHIP_DEPOSIT}(i); | ||
} | ||
assertEq(tempRln.idCommitmentIndex(), 4); | ||
vm.expectRevert(FullTree.selector); | ||
tempRln.register{value: MEMBERSHIP_DEPOSIT}(idCommitmentSeed + setSize); | ||
tempRln.register{value: MEMBERSHIP_DEPOSIT}(setSize + 1); | ||
} | ||
|
||
function test__ValidSlash(uint256 idCommitment, address payable to) public { | ||
|
@@ -79,6 +81,7 @@ contract RlnTest is Test { | |
assumePayable(to); | ||
assumeNotPrecompile(to); | ||
vm.assume(to != address(0)); | ||
vm.assume(rln.isValidCommitment(idCommitment)); | ||
|
||
rln.register{value: MEMBERSHIP_DEPOSIT}(idCommitment); | ||
assertEq(rln.stakedAmounts(idCommitment), MEMBERSHIP_DEPOSIT); | ||
|
@@ -110,6 +113,7 @@ contract RlnTest is Test { | |
} | ||
|
||
function test__InvalidSlash__InvalidIdCommitment(uint256 idCommitment) public { | ||
vm.assume(rln.isValidCommitment(idCommitment)); | ||
0x-r4bbit marked this conversation as resolved.
Show resolved
Hide resolved
|
||
vm.expectRevert(abi.encodeWithSelector(MemberNotRegistered.selector, idCommitment)); | ||
rln.slash(idCommitment, payable(address(this)), zeroedProof); | ||
} | ||
|
@@ -120,6 +124,7 @@ contract RlnTest is Test { | |
assumePayable(to); | ||
assumeNotPrecompile(to); | ||
vm.assume(to != address(0)); | ||
vm.assume(rln.isValidCommitment(idCommitment)); | ||
|
||
rln.register{value: MEMBERSHIP_DEPOSIT}(idCommitment); | ||
assertEq(rln.stakedAmounts(idCommitment), MEMBERSHIP_DEPOSIT); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why exactly has this been changed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because it was earlier the order of the field, i.e
p = 21888242871839275222246405745257275088548364400416034343698204186575808495617
, and no number in the field can exceed it. switched it out to make sure people dont get confused about it