chore: use deployed block number (#27)
* chore: add deployedBlockNumber to the constructor * fix: use uint32 instead of uint256 for deployedBlockNumber
This commit is contained in:
parent
d899a0ca85
commit
bd8403a74e
|
@ -70,6 +70,9 @@ abstract contract RlnBase {
|
||||||
/// @notice The groth16 verifier contract
|
/// @notice The groth16 verifier contract
|
||||||
IVerifier public immutable verifier;
|
IVerifier public immutable verifier;
|
||||||
|
|
||||||
|
/// @notice the deployed block number
|
||||||
|
uint32 public immutable deployedBlockNumber;
|
||||||
|
|
||||||
/// Emitted when a new member is added to the set
|
/// Emitted when a new member is added to the set
|
||||||
/// @param idCommitment The idCommitment of the member
|
/// @param idCommitment The idCommitment of the member
|
||||||
/// @param index The index of the member in the set
|
/// @param index The index of the member in the set
|
||||||
|
@ -91,6 +94,7 @@ abstract contract RlnBase {
|
||||||
SET_SIZE = 1 << depth;
|
SET_SIZE = 1 << depth;
|
||||||
poseidonHasher = PoseidonHasher(_poseidonHasher);
|
poseidonHasher = PoseidonHasher(_poseidonHasher);
|
||||||
verifier = IVerifier(_verifier);
|
verifier = IVerifier(_verifier);
|
||||||
|
deployedBlockNumber = uint32(block.number);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Allows a user to register as a member
|
/// Allows a user to register as a member
|
||||||
|
|
|
@ -21,7 +21,7 @@ Hashes the input using the Poseidon hash function, n = 2, second input is the co
|
||||||
#### Parameters
|
#### Parameters
|
||||||
|
|
||||||
| Name | Type | Description |
|
| Name | Type | Description |
|
||||||
| ---- | ---- | ----------- |
|
| ----- | ------- | ----------------- |
|
||||||
| input | uint256 | The input to hash |
|
| input | uint256 | The input to hash |
|
||||||
|
|
||||||
## PoseidonHasher
|
## PoseidonHasher
|
||||||
|
@ -835,10 +835,10 @@ Hashes the input using the Poseidon hash function, n = 2, second input is the co
|
||||||
#### Parameters
|
#### Parameters
|
||||||
|
|
||||||
| Name | Type | Description |
|
| Name | Type | Description |
|
||||||
| ---- | ---- | ----------- |
|
| ----- | ------- | ----------------- |
|
||||||
| input | uint256 | The input to hash |
|
| input | uint256 | The input to hash |
|
||||||
|
|
||||||
### _hash
|
### \_hash
|
||||||
|
|
||||||
```solidity
|
```solidity
|
||||||
function _hash(uint256 input) internal pure returns (uint256 result)
|
function _hash(uint256 input) internal pure returns (uint256 result)
|
||||||
|
@ -852,7 +852,7 @@ function _hash(uint256 input) internal pure returns (uint256 result)
|
||||||
constructor(uint256 membershipDeposit, uint256 depth, address _poseidonHasher, address _verifier) public
|
constructor(uint256 membershipDeposit, uint256 depth, address _poseidonHasher, address _verifier) public
|
||||||
```
|
```
|
||||||
|
|
||||||
### _validateRegistration
|
### \_validateRegistration
|
||||||
|
|
||||||
```solidity
|
```solidity
|
||||||
function _validateRegistration(uint256 idCommitment) internal pure
|
function _validateRegistration(uint256 idCommitment) internal pure
|
||||||
|
@ -860,7 +860,7 @@ function _validateRegistration(uint256 idCommitment) internal pure
|
||||||
|
|
||||||
_Inheriting contracts MUST override this function_
|
_Inheriting contracts MUST override this function_
|
||||||
|
|
||||||
### _validateSlash
|
### \_validateSlash
|
||||||
|
|
||||||
```solidity
|
```solidity
|
||||||
function _validateSlash(uint256 idCommitment, address payable receiver, uint256[8] proof) internal pure
|
function _validateSlash(uint256 idCommitment, address payable receiver, uint256[8] proof) internal pure
|
||||||
|
@ -885,7 +885,7 @@ Invalid deposit amount
|
||||||
### Parameters
|
### Parameters
|
||||||
|
|
||||||
| Name | Type | Description |
|
| Name | Type | Description |
|
||||||
| ---- | ---- | ----------- |
|
| -------- | ------- | --------------------------- |
|
||||||
| required | uint256 | The required deposit amount |
|
| required | uint256 | The required deposit amount |
|
||||||
| provided | uint256 | The provided deposit amount |
|
| provided | uint256 | The provided deposit amount |
|
||||||
|
|
||||||
|
@ -1037,6 +1037,14 @@ contract IVerifier verifier
|
||||||
|
|
||||||
The groth16 verifier contract
|
The groth16 verifier contract
|
||||||
|
|
||||||
|
### deployedBlockNumber
|
||||||
|
|
||||||
|
```solidity
|
||||||
|
uint32 deployedBlockNumber
|
||||||
|
```
|
||||||
|
|
||||||
|
the deployed block number
|
||||||
|
|
||||||
### MemberRegistered
|
### MemberRegistered
|
||||||
|
|
||||||
```solidity
|
```solidity
|
||||||
|
@ -1048,7 +1056,7 @@ Emitted when a new member is added to the set
|
||||||
#### Parameters
|
#### Parameters
|
||||||
|
|
||||||
| Name | Type | Description |
|
| Name | Type | Description |
|
||||||
| ---- | ---- | ----------- |
|
| ------------ | ------- | ---------------------------------- |
|
||||||
| idCommitment | uint256 | The idCommitment of the member |
|
| idCommitment | uint256 | The idCommitment of the member |
|
||||||
| index | uint256 | The index of the member in the set |
|
| index | uint256 | The index of the member in the set |
|
||||||
|
|
||||||
|
@ -1063,7 +1071,7 @@ Emitted when a member is removed from the set
|
||||||
#### Parameters
|
#### Parameters
|
||||||
|
|
||||||
| Name | Type | Description |
|
| Name | Type | Description |
|
||||||
| ---- | ---- | ----------- |
|
| ------------ | ------- | ---------------------------------- |
|
||||||
| idCommitment | uint256 | The idCommitment of the member |
|
| idCommitment | uint256 | The idCommitment of the member |
|
||||||
| index | uint256 | The index of the member in the set |
|
| index | uint256 | The index of the member in the set |
|
||||||
|
|
||||||
|
@ -1090,10 +1098,10 @@ Allows a user to register as a member
|
||||||
#### Parameters
|
#### Parameters
|
||||||
|
|
||||||
| Name | Type | Description |
|
| Name | Type | Description |
|
||||||
| ---- | ---- | ----------- |
|
| ------------ | ------- | ------------------------------ |
|
||||||
| idCommitment | uint256 | The idCommitment of the member |
|
| idCommitment | uint256 | The idCommitment of the member |
|
||||||
|
|
||||||
### _register
|
### \_register
|
||||||
|
|
||||||
```solidity
|
```solidity
|
||||||
function _register(uint256 idCommitment, uint256 stake) internal virtual
|
function _register(uint256 idCommitment, uint256 stake) internal virtual
|
||||||
|
@ -1104,11 +1112,11 @@ Registers a member
|
||||||
#### Parameters
|
#### Parameters
|
||||||
|
|
||||||
| Name | Type | Description |
|
| Name | Type | Description |
|
||||||
| ---- | ---- | ----------- |
|
| ------------ | ------- | -------------------------------------- |
|
||||||
| idCommitment | uint256 | The idCommitment of the member |
|
| idCommitment | uint256 | The idCommitment of the member |
|
||||||
| stake | uint256 | The amount of eth staked by the member |
|
| stake | uint256 | The amount of eth staked by the member |
|
||||||
|
|
||||||
### _validateRegistration
|
### \_validateRegistration
|
||||||
|
|
||||||
```solidity
|
```solidity
|
||||||
function _validateRegistration(uint256 idCommitment) internal view virtual
|
function _validateRegistration(uint256 idCommitment) internal view virtual
|
||||||
|
@ -1127,12 +1135,12 @@ _Allows a user to slash a member_
|
||||||
#### Parameters
|
#### Parameters
|
||||||
|
|
||||||
| Name | Type | Description |
|
| Name | Type | Description |
|
||||||
| ---- | ---- | ----------- |
|
| ------------ | --------------- | ------------------------------ |
|
||||||
| idCommitment | uint256 | The idCommitment of the member |
|
| idCommitment | uint256 | The idCommitment of the member |
|
||||||
| receiver | address payable | |
|
| receiver | address payable | |
|
||||||
| proof | uint256[8] | |
|
| proof | uint256[8] | |
|
||||||
|
|
||||||
### _slash
|
### \_slash
|
||||||
|
|
||||||
```solidity
|
```solidity
|
||||||
function _slash(uint256 idCommitment, address payable receiver, uint256[8] proof) internal virtual
|
function _slash(uint256 idCommitment, address payable receiver, uint256[8] proof) internal virtual
|
||||||
|
@ -1144,12 +1152,12 @@ stake to the receiver's available withdrawal balance_
|
||||||
#### Parameters
|
#### Parameters
|
||||||
|
|
||||||
| Name | Type | Description |
|
| Name | Type | Description |
|
||||||
| ---- | ---- | ----------- |
|
| ------------ | --------------- | -------------------------------- |
|
||||||
| idCommitment | uint256 | The idCommitment of the member |
|
| idCommitment | uint256 | The idCommitment of the member |
|
||||||
| receiver | address payable | The address to receive the funds |
|
| receiver | address payable | The address to receive the funds |
|
||||||
| proof | uint256[8] | |
|
| proof | uint256[8] | |
|
||||||
|
|
||||||
### _validateSlash
|
### \_validateSlash
|
||||||
|
|
||||||
```solidity
|
```solidity
|
||||||
function _validateSlash(uint256 idCommitment, address payable receiver, uint256[8] proof) internal view virtual
|
function _validateSlash(uint256 idCommitment, address payable receiver, uint256[8] proof) internal view virtual
|
||||||
|
@ -1175,7 +1183,7 @@ NOTE: The variant of Poseidon we use accepts only 1 input, assume n=2, and the s
|
||||||
#### Parameters
|
#### Parameters
|
||||||
|
|
||||||
| Name | Type | Description |
|
| Name | Type | Description |
|
||||||
| ---- | ---- | ----------- |
|
| ----- | ------- | ----------------- |
|
||||||
| input | uint256 | The value to hash |
|
| input | uint256 | The value to hash |
|
||||||
|
|
||||||
### isValidCommitment
|
### isValidCommitment
|
||||||
|
@ -1184,7 +1192,7 @@ NOTE: The variant of Poseidon we use accepts only 1 input, assume n=2, and the s
|
||||||
function isValidCommitment(uint256 idCommitment) public view returns (bool)
|
function isValidCommitment(uint256 idCommitment) public view returns (bool)
|
||||||
```
|
```
|
||||||
|
|
||||||
### _verifyProof
|
### \_verifyProof
|
||||||
|
|
||||||
```solidity
|
```solidity
|
||||||
function _verifyProof(uint256 idCommitment, address receiver, uint256[8] proof) internal view virtual returns (bool)
|
function _verifyProof(uint256 idCommitment, address receiver, uint256[8] proof) internal view virtual returns (bool)
|
||||||
|
@ -1221,7 +1229,7 @@ function P1() internal pure returns (struct Pairing.G1Point)
|
||||||
#### Return Values
|
#### Return Values
|
||||||
|
|
||||||
| Name | Type | Description |
|
| Name | Type | Description |
|
||||||
| ---- | ---- | ----------- |
|
| ---- | ---------------------- | ------------------- |
|
||||||
| [0] | struct Pairing.G1Point | the generator of G1 |
|
| [0] | struct Pairing.G1Point | the generator of G1 |
|
||||||
|
|
||||||
### P2
|
### P2
|
||||||
|
@ -1233,7 +1241,7 @@ function P2() internal pure returns (struct Pairing.G2Point)
|
||||||
#### Return Values
|
#### Return Values
|
||||||
|
|
||||||
| Name | Type | Description |
|
| Name | Type | Description |
|
||||||
| ---- | ---- | ----------- |
|
| ---- | ---------------------- | ------------------- |
|
||||||
| [0] | struct Pairing.G2Point | the generator of G2 |
|
| [0] | struct Pairing.G2Point | the generator of G2 |
|
||||||
|
|
||||||
### negate
|
### negate
|
||||||
|
@ -1245,7 +1253,7 @@ function negate(struct Pairing.G1Point p) internal pure returns (struct Pairing.
|
||||||
#### Return Values
|
#### Return Values
|
||||||
|
|
||||||
| Name | Type | Description |
|
| Name | Type | Description |
|
||||||
| ---- | ---- | ----------- |
|
| ---- | ---------------------- | -------------------------------------------------------------- |
|
||||||
| r | struct Pairing.G1Point | the negation of p, i.e. p.addition(p.negate()) should be zero. |
|
| r | struct Pairing.G1Point | the negation of p, i.e. p.addition(p.negate()) should be zero. |
|
||||||
|
|
||||||
### addition
|
### addition
|
||||||
|
@ -1257,7 +1265,7 @@ function addition(struct Pairing.G1Point p1, struct Pairing.G1Point p2) internal
|
||||||
#### Return Values
|
#### Return Values
|
||||||
|
|
||||||
| Name | Type | Description |
|
| Name | Type | Description |
|
||||||
| ---- | ---- | ----------- |
|
| ---- | ---------------------- | --------------------------- |
|
||||||
| r | struct Pairing.G1Point | the sum of two points of G1 |
|
| r | struct Pairing.G1Point | the sum of two points of G1 |
|
||||||
|
|
||||||
### scalar_mul
|
### scalar_mul
|
||||||
|
@ -1269,7 +1277,7 @@ function scalar_mul(struct Pairing.G1Point p, uint256 s) internal view returns (
|
||||||
#### Return Values
|
#### Return Values
|
||||||
|
|
||||||
| Name | Type | Description |
|
| Name | Type | Description |
|
||||||
| ---- | ---- | ----------- |
|
| ---- | ---------------------- | --------------------------------------------------------------------------------------------------------------------------- |
|
||||||
| r | struct Pairing.G1Point | the product of a point on G1 and a scalar, i.e. p == p.scalar_mul(1) and p.addition(p) == p.scalar_mul(2) for all points p. |
|
| r | struct Pairing.G1Point | the product of a point on G1 and a scalar, i.e. p == p.scalar_mul(1) and p.addition(p) == p.scalar_mul(2) for all points p. |
|
||||||
|
|
||||||
### pairing
|
### pairing
|
||||||
|
@ -1281,8 +1289,8 @@ function pairing(struct Pairing.G1Point[] p1, struct Pairing.G2Point[] p2) inter
|
||||||
#### Return Values
|
#### Return Values
|
||||||
|
|
||||||
| Name | Type | Description |
|
| Name | Type | Description |
|
||||||
| ---- | ---- | ----------- |
|
| ---- | ---- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||||
| [0] | bool | the result of computing the pairing check e(p1[0], p2[0]) * .... * e(p1[n], p2[n]) == 1 For example pairing([P1(), P1().negate()], [P2(), P2()]) should return true. |
|
| [0] | bool | the result of computing the pairing check e(p1[0], p2[0]) _ .... _ e(p1[n], p2[n]) == 1 For example pairing([P1(), P1().negate()], [P2(), P2()]) should return true. |
|
||||||
|
|
||||||
### pairingProd2
|
### pairingProd2
|
||||||
|
|
||||||
|
@ -1353,6 +1361,5 @@ function verifyProof(uint256[2] a, uint256[2][2] b, uint256[2] c, uint256[2] inp
|
||||||
#### Return Values
|
#### Return Values
|
||||||
|
|
||||||
| Name | Type | Description |
|
| Name | Type | Description |
|
||||||
| ---- | ---- | ----------- |
|
| ---- | ---- | --------------------------- |
|
||||||
| r | bool | bool true if proof is valid |
|
| r | bool | bool true if proof is valid |
|
||||||
|
|
||||||
|
|
|
@ -34,6 +34,7 @@ contract RlnTest is Test {
|
||||||
assertEq(rln.MEMBERSHIP_DEPOSIT(), MEMBERSHIP_DEPOSIT);
|
assertEq(rln.MEMBERSHIP_DEPOSIT(), MEMBERSHIP_DEPOSIT);
|
||||||
assertEq(rln.DEPTH(), DEPTH);
|
assertEq(rln.DEPTH(), DEPTH);
|
||||||
assertEq(rln.SET_SIZE(), SET_SIZE);
|
assertEq(rln.SET_SIZE(), SET_SIZE);
|
||||||
|
assertEq(rln.deployedBlockNumber(), 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
function test__ValidRegistration(uint256 idCommitment) public {
|
function test__ValidRegistration(uint256 idCommitment) public {
|
||||||
|
|
Loading…
Reference in New Issue