Skip to content

Commit 39fe8a7

Browse files
PatStilesJuArce
andauthored
feat(audit): Use block timestamp instead of block number. (#1085)
Co-authored-by: JuArce <[email protected]>
1 parent 54c3aa3 commit 39fe8a7

File tree

3 files changed

+17
-14
lines changed

3 files changed

+17
-14
lines changed

contracts/scripts/anvil/state/alignedlayer-deployed-anvil-state.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

contracts/src/core/BatcherPaymentService.sol

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@ contract BatcherPaymentService is
1919
{
2020
using ECDSA for bytes32;
2121

22-
// CONSTANTS
23-
uint256 public constant UNLOCK_BLOCK_COUNT = 100;
22+
// CONSTANTS = 100 Blocks * 12 second block time.
23+
uint256 public constant UNLOCK_BLOCK_TIME = 3600 seconds;
2424

2525
// EVENTS
2626
event PaymentReceived(address indexed sender, uint256 amount);
2727
event FundsWithdrawn(address indexed recipient, uint256 amount);
2828
event BalanceLocked(address indexed user);
29-
event BalanceUnlocked(address indexed user, uint256 unlockBlock);
29+
event BalanceUnlocked(address indexed user, uint256 unlockBlockTime);
3030
event TaskCreated(bytes32 indexed batchMerkleRoot, uint256 feePerProof);
3131

3232
// ERRORS
@@ -40,7 +40,7 @@ contract BatcherPaymentService is
4040
error UserHasNoFundsToUnlock(address user); // b38340cf
4141
error UserHasNoFundsToLock(address user); // 6cc12bc2
4242
error PayerInsufficientBalance(uint256 balance, uint256 amount); // 21c3d50f
43-
error FundsLocked(uint256 unlockBlock, uint256 currentBlock); // bedc4e5a
43+
error FundsLocked(uint256 unlockBlockTime, uint256 currentBlockTime); // bedc4e5a
4444
error InvalidSignature(); // 8baa579f
4545
error InvalidNonce(uint256 expected, uint256 actual); // 06427aeb
4646
error InvalidMaxFee(uint256 maxFee, uint256 actualFee); // f59adf4a
@@ -96,7 +96,7 @@ contract BatcherPaymentService is
9696
// PAYABLE FUNCTIONS
9797
receive() external payable {
9898
userData[msg.sender].balance += msg.value;
99-
userData[msg.sender].unlockBlock = 0;
99+
userData[msg.sender].unlockBlockTime = 0;
100100
emit PaymentReceived(msg.sender, msg.value);
101101
}
102102

@@ -167,15 +167,17 @@ contract BatcherPaymentService is
167167
revert UserHasNoFundsToUnlock(msg.sender);
168168
}
169169

170-
userData[msg.sender].unlockBlock = block.number + UNLOCK_BLOCK_COUNT;
171-
emit BalanceUnlocked(msg.sender, userData[msg.sender].unlockBlock);
170+
userData[msg.sender].unlockBlockTime =
171+
block.timestamp +
172+
UNLOCK_BLOCK_TIME;
173+
emit BalanceUnlocked(msg.sender, userData[msg.sender].unlockBlockTime);
172174
}
173175

174176
function lock() external whenNotPaused {
175177
if (userData[msg.sender].balance == 0) {
176178
revert UserHasNoFundsToLock(msg.sender);
177179
}
178-
userData[msg.sender].unlockBlock = 0;
180+
userData[msg.sender].unlockBlockTime = 0;
179181
emit BalanceLocked(msg.sender);
180182
}
181183

@@ -186,13 +188,14 @@ contract BatcherPaymentService is
186188
}
187189

188190
if (
189-
senderData.unlockBlock == 0 || senderData.unlockBlock > block.number
191+
senderData.unlockBlockTime == 0 ||
192+
senderData.unlockBlockTime > block.timestamp
190193
) {
191-
revert FundsLocked(senderData.unlockBlock, block.number);
194+
revert FundsLocked(senderData.unlockBlockTime, block.timestamp);
192195
}
193196

194197
senderData.balance -= amount;
195-
senderData.unlockBlock = 0;
198+
senderData.unlockBlockTime = 0;
196199
emit BalanceLocked(msg.sender);
197200
payable(msg.sender).transfer(amount);
198201
emit FundsWithdrawn(msg.sender, amount);
@@ -322,6 +325,6 @@ contract BatcherPaymentService is
322325
}
323326

324327
function user_unlock_block(address account) public view returns (uint256) {
325-
return userData[account].unlockBlock;
328+
return userData[account].unlockBlockTime;
326329
}
327330
}

contracts/src/core/BatcherPaymentServiceStorage.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ abstract contract BatcherPaymentServiceStorage {
1010

1111
struct UserInfo {
1212
uint256 balance;
13-
uint256 unlockBlock;
13+
uint256 unlockBlockTime;
1414
uint256 nonce;
1515
}
1616

0 commit comments

Comments
 (0)