mirror of
https://github.com/logos-messaging/waku-rlnv1-contract.git
synced 2026-01-02 14:23:09 +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));
|
||||
}
|
||||
|
||||
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
|
||||
while (true) {
|
||||
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();
|
||||
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();
|
||||
// optimize the gas used below
|
||||
uint256[] memory commitments = new uint256[](1);
|
||||
@ -81,6 +81,7 @@ contract WakuRlnRegistry is Ownable {
|
||||
}
|
||||
|
||||
function forceProgress() external onlyOwner onlyUsableStorage {
|
||||
if (storages[usingStorageIndex + 1] == address(0)) revert NoStorageContractAvailable();
|
||||
usingStorageIndex += 1;
|
||||
}
|
||||
}
|
||||
|
||||
@ -37,7 +37,6 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
|
||||
solcInput: extendedArtifact.solcInput,
|
||||
devdoc: extendedArtifact.devdoc,
|
||||
};
|
||||
console.log(d);
|
||||
deployments.save(`WakuRlnStorage_${indexOfStorageToBeDeployed}`, d);
|
||||
};
|
||||
|
||||
|
||||
@ -181,19 +181,19 @@ function newStorage() external
|
||||
### register
|
||||
|
||||
```solidity
|
||||
function register(uint256[] commitments) external payable
|
||||
function register(uint256[] commitments) external
|
||||
```
|
||||
|
||||
### register
|
||||
|
||||
```solidity
|
||||
function register(uint16 storageIndex, uint256[] commitments) external payable
|
||||
function register(uint16 storageIndex, uint256[] commitments) external
|
||||
```
|
||||
|
||||
### register
|
||||
|
||||
```solidity
|
||||
function register(uint16 storageIndex, uint256 commitment) external payable
|
||||
function register(uint16 storageIndex, uint256 commitment) external
|
||||
```
|
||||
|
||||
### forceProgress
|
||||
|
||||
@ -52,9 +52,11 @@ contract WakuRlnRegistryTest is Test {
|
||||
}
|
||||
|
||||
function test__forceProgression() public {
|
||||
wakuRlnRegistry.newStorage();
|
||||
wakuRlnRegistry.newStorage();
|
||||
wakuRlnRegistry.forceProgress();
|
||||
require(wakuRlnRegistry.usingStorageIndex() == 1);
|
||||
assertEq(wakuRlnRegistry.usingStorageIndex(), 1);
|
||||
assertEq(wakuRlnRegistry.nextStorageIndex(), 2);
|
||||
}
|
||||
|
||||
function test__SingleRegistration(uint256 commitment) public {
|
||||
@ -105,4 +107,11 @@ contract WakuRlnRegistryTest is Test {
|
||||
vm.expectRevert(NoStorageContractAvailable.selector);
|
||||
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