Skip to content

Commit 48220ae

Browse files
committed
chore: remove permit
1 parent b7e9a9b commit 48220ae

3 files changed

Lines changed: 0 additions & 137 deletions

File tree

src/Membership.sol

Lines changed: 0 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ pragma solidity 0.8.24;
44
import { IPriceCalculator } from "./IPriceCalculator.sol";
55
import { IERC20 } from "openzeppelin-contracts/contracts/token/ERC20/IERC20.sol";
66
import { SafeERC20 } from "openzeppelin-contracts/contracts/token/ERC20/utils/SafeERC20.sol";
7-
import { ERC20Permit } from "@openzeppelin/contracts/token/ERC20/extensions/ERC20Permit.sol";
87
import { Initializable } from "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
98

109
// The rate limit is outside the expected limits
@@ -209,63 +208,6 @@ abstract contract MembershipUpgradeable is Initializable {
209208
IERC20(token).safeTransferFrom(_sender, address(this), depositAmount);
210209
}
211210

212-
/// @dev acquire a membership and transfer the deposit to the contract
213-
/// Uses the RC20 Permit extension allowing approvals to be made via signatures, as defined in
214-
/// [EIP-2612](https://eips.ethereum.org/EIPS/eip-2612).
215-
/// @param _owner The address of the token owner who is giving permission and will own the membership.
216-
/// @param _deadline The timestamp until when the permit is valid.
217-
/// @param _v The recovery byte of the signature.
218-
/// @param _r Half of the ECDSA signature pair.
219-
/// @param _s Half of the ECDSA signature pair.
220-
/// @param _idCommitment the idCommitment of the new membership
221-
/// @param _rateLimit the membership rate limit
222-
/// @return index the index of the new membership in the membership set
223-
/// @return indexReused true if the index was reused, false otherwise
224-
function _acquireMembershipWithPermit(
225-
address _owner,
226-
uint256 _deadline,
227-
uint8 _v,
228-
bytes32 _r,
229-
bytes32 _s,
230-
uint256 _idCommitment,
231-
uint32 _rateLimit
232-
)
233-
internal
234-
returns (uint32 index, bool indexReused)
235-
{
236-
// Check if the rate limit is valid
237-
if (!isValidMembershipRateLimit(_rateLimit)) {
238-
revert InvalidMembershipRateLimit();
239-
}
240-
241-
currentTotalRateLimit += _rateLimit;
242-
243-
// Determine if we exceed the total rate limit
244-
if (currentTotalRateLimit > maxTotalRateLimit) {
245-
revert CannotExceedMaxTotalRateLimit();
246-
}
247-
248-
(address token, uint256 depositAmount) = priceCalculator.calculate(_rateLimit);
249-
250-
ERC20Permit(token).permit(_owner, address(this), depositAmount, _deadline, _v, _r, _s);
251-
252-
// Possibly reuse an index of an erased membership
253-
(index, indexReused) = _getFreeIndex();
254-
255-
memberships[_idCommitment] = MembershipInfo({
256-
holder: _owner,
257-
activeDuration: activeDurationForNewMemberships,
258-
gracePeriodStartTimestamp: block.timestamp + uint256(activeDurationForNewMemberships),
259-
gracePeriodDuration: gracePeriodDurationForNewMemberships,
260-
token: token,
261-
depositAmount: depositAmount,
262-
rateLimit: _rateLimit,
263-
index: index
264-
});
265-
266-
IERC20(token).safeTransferFrom(_owner, address(this), depositAmount);
267-
}
268-
269211
/// @notice Checks if a rate limit is within the allowed bounds
270212
/// @param rateLimit The rate limit
271213
/// @return true if the rate limit is within the allowed bounds, false otherwise

src/WakuRlnV2.sol

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -178,43 +178,6 @@ contract WakuRlnV2 is Initializable, OwnableUpgradeable, UUPSUpgradeable, Member
178178
emit MembershipRegistered(idCommitment, rateLimit, index);
179179
}
180180

181-
/// @notice Register a membership while erasing some expired memberships to reuse their rate limit.
182-
/// Uses the RC20 Permit extension allowing approvals to be made via signatures, as defined in
183-
/// [EIP-2612](https://eips.ethereum.org/EIPS/eip-2612).
184-
/// @param owner The address of the token owner who is giving permission and will own the membership.
185-
/// @param deadline The timestamp until when the permit is valid.
186-
/// @param v The recovery byte of the signature.
187-
/// @param r Half of the ECDSA signature pair.
188-
/// @param s Half of the ECDSA signature pair.
189-
/// @param idCommitment The idCommitment of the new membership
190-
/// @param rateLimit The rate limit of the new membership
191-
/// @param idCommitmentsToErase The list of idCommitments of expired memberships to erase
192-
function registerWithPermit(
193-
address owner,
194-
uint256 deadline,
195-
uint8 v,
196-
bytes32 r,
197-
bytes32 s,
198-
uint256 idCommitment,
199-
uint32 rateLimit,
200-
uint256[] calldata idCommitmentsToErase
201-
)
202-
external
203-
onlyValidIdCommitment(idCommitment)
204-
noDuplicateMembership(idCommitment)
205-
membershipSetNotFull
206-
{
207-
// erase memberships without overwriting membership set data to zero (save gas)
208-
_eraseMemberships(idCommitmentsToErase, false);
209-
210-
(uint32 index, bool indexReused) =
211-
_acquireMembershipWithPermit(owner, deadline, v, r, s, idCommitment, rateLimit);
212-
213-
_upsertInTree(idCommitment, rateLimit, index, indexReused);
214-
215-
emit MembershipRegistered(idCommitment, rateLimit, index);
216-
}
217-
218181
/// @dev Register a membership (internal function)
219182
/// @param idCommitment The idCommitment of the membership
220183
/// @param rateLimit The rate limit of the membership

test/WakuRlnV2.t.sol

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -122,48 +122,6 @@ contract WakuRlnV2Test is Test {
122122
assertEq(w.currentTotalRateLimit(), membershipRateLimit);
123123
}
124124

125-
function test__ValidRegistrationWithPermit() external {
126-
vm.pauseGasMetering();
127-
uint256 idCommitment = 2;
128-
uint32 membershipRateLimit = w.minMembershipRateLimit();
129-
(, uint256 price) = w.priceCalculator().calculate(membershipRateLimit);
130-
131-
// Creating an owner for a membership (Alice)
132-
uint256 alicePrivK = 0xA11CE;
133-
address aliceAddr = vm.addr(alicePrivK);
134-
135-
// Minting some tokens so Alice can register a membership
136-
token.mint(aliceAddr, price);
137-
138-
// Prepare the permit parameters
139-
bytes32 permitHash = keccak256(
140-
abi.encode(
141-
keccak256("Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline)"),
142-
aliceAddr, // Owner of the membership
143-
address(w), // Spender (The rln proxy contract)
144-
price,
145-
token.nonces(aliceAddr),
146-
block.timestamp + 1 hours // Deadline
147-
)
148-
);
149-
150-
// Sign the permit hash using the owner's private key
151-
(uint8 v, bytes32 r, bytes32 s) =
152-
vm.sign(alicePrivK, ECDSA.toTypedDataHash(token.DOMAIN_SEPARATOR(), permitHash));
153-
154-
vm.resumeGasMetering();
155-
156-
// Call the function on-chain using the generated signature
157-
w.registerWithPermit(
158-
aliceAddr, block.timestamp + 1 hours, v, r, s, idCommitment, membershipRateLimit, noIdCommitmentsToErase
159-
);
160-
161-
(,,,, uint32 fetchedMembershipRateLimit,, address holder,) = w.memberships(idCommitment);
162-
assertEq(fetchedMembershipRateLimit, membershipRateLimit);
163-
assertEq(holder, aliceAddr);
164-
assertEq(token.balanceOf(address(w)), price);
165-
}
166-
167125
function test__LinearPriceCalculation(uint32 membershipRateLimit) external view {
168126
IPriceCalculator priceCalculator = w.priceCalculator();
169127
uint256 pricePerMessagePerPeriod = LinearPriceCalculator(address(priceCalculator)).pricePerMessagePerEpoch();

0 commit comments

Comments
 (0)