mirror of
https://github.com/logos-messaging/waku-rlnv1-contract.git
synced 2026-01-06 00:03:08 +00:00
Merge pull request #6 from waku-org/fix-bugs
fix: forceProgression led to an invalid state, bricking the contract
This commit is contained in:
commit
19ef5bad32
@ -48,7 +48,7 @@ contract WakuRlnRegistry is Ownable {
|
|||||||
_insertIntoStorageMap(address(newStorageContract));
|
_insertIntoStorageMap(address(newStorageContract));
|
||||||
}
|
}
|
||||||
|
|
||||||
function register(uint256[] calldata commitments) external payable onlyUsableStorage {
|
function register(uint256[] calldata commitments) external onlyUsableStorage {
|
||||||
// iteratively check if the storage contract is full, and increment the usingStorageIndex if it is
|
// iteratively check if the storage contract is full, and increment the usingStorageIndex if it is
|
||||||
while (true) {
|
while (true) {
|
||||||
try WakuRln(storages[usingStorageIndex]).register(commitments) {
|
try WakuRln(storages[usingStorageIndex]).register(commitments) {
|
||||||
@ -67,12 +67,12 @@ contract WakuRlnRegistry is Ownable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function register(uint16 storageIndex, uint256[] calldata commitments) external payable {
|
function register(uint16 storageIndex, uint256[] calldata commitments) external {
|
||||||
if (storageIndex >= nextStorageIndex) revert NoStorageContractAvailable();
|
if (storageIndex >= nextStorageIndex) revert NoStorageContractAvailable();
|
||||||
WakuRln(storages[storageIndex]).register(commitments);
|
WakuRln(storages[storageIndex]).register(commitments);
|
||||||
}
|
}
|
||||||
|
|
||||||
function register(uint16 storageIndex, uint256 commitment) external payable {
|
function register(uint16 storageIndex, uint256 commitment) external {
|
||||||
if (storageIndex >= nextStorageIndex) revert NoStorageContractAvailable();
|
if (storageIndex >= nextStorageIndex) revert NoStorageContractAvailable();
|
||||||
// optimize the gas used below
|
// optimize the gas used below
|
||||||
uint256[] memory commitments = new uint256[](1);
|
uint256[] memory commitments = new uint256[](1);
|
||||||
@ -81,6 +81,7 @@ contract WakuRlnRegistry is Ownable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function forceProgress() external onlyOwner onlyUsableStorage {
|
function forceProgress() external onlyOwner onlyUsableStorage {
|
||||||
|
if (storages[usingStorageIndex + 1] == address(0)) revert NoStorageContractAvailable();
|
||||||
usingStorageIndex += 1;
|
usingStorageIndex += 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -37,7 +37,6 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
|
|||||||
solcInput: extendedArtifact.solcInput,
|
solcInput: extendedArtifact.solcInput,
|
||||||
devdoc: extendedArtifact.devdoc,
|
devdoc: extendedArtifact.devdoc,
|
||||||
};
|
};
|
||||||
console.log(d);
|
|
||||||
deployments.save(`WakuRlnStorage_${indexOfStorageToBeDeployed}`, d);
|
deployments.save(`WakuRlnStorage_${indexOfStorageToBeDeployed}`, d);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -181,19 +181,19 @@ function newStorage() external
|
|||||||
### register
|
### register
|
||||||
|
|
||||||
```solidity
|
```solidity
|
||||||
function register(uint256[] commitments) external payable
|
function register(uint256[] commitments) external
|
||||||
```
|
```
|
||||||
|
|
||||||
### register
|
### register
|
||||||
|
|
||||||
```solidity
|
```solidity
|
||||||
function register(uint16 storageIndex, uint256[] commitments) external payable
|
function register(uint16 storageIndex, uint256[] commitments) external
|
||||||
```
|
```
|
||||||
|
|
||||||
### register
|
### register
|
||||||
|
|
||||||
```solidity
|
```solidity
|
||||||
function register(uint16 storageIndex, uint256 commitment) external payable
|
function register(uint16 storageIndex, uint256 commitment) external
|
||||||
```
|
```
|
||||||
|
|
||||||
### forceProgress
|
### forceProgress
|
||||||
|
|||||||
@ -52,9 +52,11 @@ contract WakuRlnRegistryTest is Test {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function test__forceProgression() public {
|
function test__forceProgression() public {
|
||||||
|
wakuRlnRegistry.newStorage();
|
||||||
wakuRlnRegistry.newStorage();
|
wakuRlnRegistry.newStorage();
|
||||||
wakuRlnRegistry.forceProgress();
|
wakuRlnRegistry.forceProgress();
|
||||||
require(wakuRlnRegistry.usingStorageIndex() == 1);
|
assertEq(wakuRlnRegistry.usingStorageIndex(), 1);
|
||||||
|
assertEq(wakuRlnRegistry.nextStorageIndex(), 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
function test__SingleRegistration(uint256 commitment) public {
|
function test__SingleRegistration(uint256 commitment) public {
|
||||||
@ -105,4 +107,11 @@ contract WakuRlnRegistryTest is Test {
|
|||||||
vm.expectRevert(NoStorageContractAvailable.selector);
|
vm.expectRevert(NoStorageContractAvailable.selector);
|
||||||
wakuRlnRegistry.register(commitments);
|
wakuRlnRegistry.register(commitments);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function test__forceProgression__NoStorageContract() public {
|
||||||
|
vm.expectRevert(NoStorageContractAvailable.selector);
|
||||||
|
wakuRlnRegistry.forceProgress();
|
||||||
|
assertEq(wakuRlnRegistry.usingStorageIndex(), 0);
|
||||||
|
assertEq(wakuRlnRegistry.nextStorageIndex(), 0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user