Skip to content

Commit

Permalink
feat: Ownable2StepUpgradeable to OwnableUpgradeable
Browse files Browse the repository at this point in the history
This allows the contract to transfer ownership to address 0x000...000 as defined in waku-org/specs#34: `At some point, the _Owner_ SHOULD renounce their privileges, and the contract MUST become immutable`. The problem with `Ownable2StepUpgradeable` is that it requires accepting the ownership transfer, which is not possible with address 0x0
  • Loading branch information
richard-ramos committed Oct 7, 2024
1 parent 79fd7ec commit 3789d53
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 8 deletions.
6 changes: 3 additions & 3 deletions src/LinearPriceCalculator.sol
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.24;

import { Ownable2Step } from "openzeppelin-contracts/contracts/access/Ownable2Step.sol";
import { Ownable } from "openzeppelin-contracts/contracts/access/Ownable.sol";
import { IPriceCalculator } from "./IPriceCalculator.sol";

/// Address 0x0000...0000 was used instead of an ERC20 token address
error OnlyTokensAllowed();

/// @title Linear Price Calculator to determine the price to acquire a membership
contract LinearPriceCalculator is IPriceCalculator, Ownable2Step {
contract LinearPriceCalculator is IPriceCalculator, Ownable {
/// @notice Address of the ERC20 token accepted by this contract.
address public token;

/// @notice The price per message per epoch
uint256 public pricePerMessagePerEpoch;

constructor(address _token, uint256 _pricePerMessagePerEpoch) Ownable2Step() {
constructor(address _token, uint256 _pricePerMessagePerEpoch) Ownable() {
_setTokenAndPrice(_token, _pricePerMessagePerEpoch);
}

Expand Down
4 changes: 2 additions & 2 deletions src/WakuRlnV2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ pragma solidity 0.8.24;
import { LazyIMT, LazyIMTData } from "@zk-kit/imt.sol/LazyIMT.sol";
import { PoseidonT3 } from "poseidon-solidity/PoseidonT3.sol";

import { Ownable2StepUpgradeable } from "@openzeppelin/contracts-upgradeable/access/Ownable2StepUpgradeable.sol";
import { OwnableUpgradeable } from "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
import { Initializable } from "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import { UUPSUpgradeable } from "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";

Expand All @@ -20,7 +20,7 @@ error InvalidIdCommitment(uint256 idCommitment);
/// Invalid pagination query
error InvalidPaginationQuery(uint256 startIndex, uint256 endIndex);

contract WakuRlnV2 is Initializable, Ownable2StepUpgradeable, UUPSUpgradeable, MembershipUpgradeable {
contract WakuRlnV2 is Initializable, OwnableUpgradeable, UUPSUpgradeable, MembershipUpgradeable {
/// @notice The Field
uint256 public constant Q =
21_888_242_871_839_275_222_246_405_745_257_275_088_548_364_400_416_034_343_698_204_186_575_808_495_617;
Expand Down
5 changes: 2 additions & 3 deletions test/WakuRlnV2.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -668,8 +668,7 @@ contract WakuRlnV2Test is Test {

/*| Name | Type | Slot | Offset | Bytes |
|---------------------|-----------------------------------------------------|------|--------|-------|
| nextFreeIndex | uint32 | 256 | 0 | 4 | */

| nextFreeIndex | uint32 | 206 | 0 | 4 | */
/*
Pro tip: to easily find the storage slot of a variable, without having to calculate the storage layout
based on the variable declaration, set the variable to an easily grepable value like 0xDEADBEEF, and then
Expand All @@ -687,7 +686,7 @@ contract WakuRlnV2Test is Test {
*/

// we set nextFreeIndex to 4294967295 (1 << 20) = 0x00100000
vm.store(address(w), bytes32(uint256(256)), 0x0000000000000000000000000000000000000000000000000000000000100000);
vm.store(address(w), bytes32(uint256(206)), 0x0000000000000000000000000000000000000000000000000000000000100000);
token.approve(address(w), price);
vm.expectRevert(bytes("Membership set is full"));
w.register(1, membershipRateLimit);
Expand Down

0 comments on commit 3789d53

Please sign in to comment.