From dc2a1393ef6967e6413d59403faee092690c1ff1 Mon Sep 17 00:00:00 2001 From: Richard Ramos Date: Tue, 9 Aug 2022 14:00:08 -0400 Subject: [PATCH] Fix: access the pubkey array length once --- contracts/Rln.sol | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/contracts/Rln.sol b/contracts/Rln.sol index c6494a4..e566153 100644 --- a/contracts/Rln.sol +++ b/contracts/Rln.sol @@ -33,9 +33,10 @@ contract RLN { } function registerBatch(uint256[] calldata pubkeys) external payable { - require(pubkeyIndex + pubkeys.length <= SET_SIZE, "RLN, registerBatch: set is full"); - require(msg.value == MEMBERSHIP_DEPOSIT * pubkeys.length, "RLN, registerBatch: membership deposit is not satisfied"); - for (uint256 i = 0; i < pubkeys.length; i++) { + uint256 pubkeylen = pubkeys.length; + require(pubkeyIndex + pubkeylen <= SET_SIZE, "RLN, registerBatch: set is full"); + require(msg.value == MEMBERSHIP_DEPOSIT * pubkeylen, "RLN, registerBatch: membership deposit is not satisfied"); + for (uint256 i = 0; i < pubkeylen; i++) { _register(pubkeys[i]); } }