Skip to content

Commit f4211ab

Browse files
committed
Fixes after review
1 parent 016bb32 commit f4211ab

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

contracts/contracts/Depositor.sol

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ pragma solidity 0.8.23;
44
import {Address} from "@openzeppelin/contracts/utils/Address.sol";
55

66
library PoseidonUnit1L {
7-
function poseidon(uint256[1] calldata) public pure returns (uint256) {}
7+
function poseidon(bytes32[1] calldata) public pure returns (bytes32) {}
88
}
99

1010
/**
@@ -26,7 +26,7 @@ contract Depositor {
2626
/**
2727
* @notice Represents the minimum time (in seconds) that a deposit must be locked in the contract. Set to one hour.
2828
*/
29-
uint256 public constant HOUR = 60 * 60;
29+
uint256 public constant MIN_LOCK_TIME = 1 hours;
3030

3131
/**
3232
* @notice Struct to store details of each deposit.
@@ -84,9 +84,8 @@ contract Depositor {
8484

8585
/**
8686
* @notice Error thrown when a deposit is attempted with an amount of 0 ETH.
87-
* @param sentAmount The amount of ETH attempted to be deposited, expected to be greater than 0.
8887
*/
89-
error InsufficientDepositAmount(uint256 sentAmount);
88+
error ZeroDepositAmount();
9089

9190
/**
9291
* @notice Error thrown when a deposit with the given secret hash already exists.
@@ -134,9 +133,9 @@ contract Depositor {
134133
* @param lockTime_ The duration (in seconds) for which the deposit is locked and cannot be withdrawn.
135134
*/
136135
function deposit(address recipient_, bytes32 secretHash_, uint256 lockTime_) external payable {
137-
if (msg.value == 0) revert InsufficientDepositAmount(msg.value);
136+
if (msg.value == 0) revert ZeroDepositAmount();
138137
if (deposits[secretHash_].amount != 0) revert DepositAlreadyExists(secretHash_);
139-
if (lockTime_ < HOUR) revert LockTimeTooShort(lockTime_, HOUR);
138+
if (lockTime_ < MIN_LOCK_TIME) revert LockTimeTooShort(lockTime_, MIN_LOCK_TIME);
140139
if (recipient_ == address(0)) revert ZeroAddressNotAllowed();
141140

142141
deposits[secretHash_] = Deposit({
@@ -157,7 +156,7 @@ contract Depositor {
157156
* @param secret_ The prototype of the `secretHash` used in the deposit function.
158157
*/
159158
function withdraw(bytes32 secret_) external {
160-
bytes32 secretHash_ = bytes32(PoseidonUnit1L.poseidon([uint256(secret_)]));
159+
bytes32 secretHash_ = PoseidonUnit1L.poseidon([secret_]);
161160

162161
Deposit storage userDeposit = deposits[secretHash_];
163162

contracts/test/Depositor.test.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,10 @@ describe("Taprootized Atomic Swaps", () => {
9090
const secret = ethers.hexlify(ethers.randomBytes(32));
9191
const secretHash = poseidonHash(secret);
9292

93-
await expect(depositor.deposit(USER2.address, secretHash, LOCK_TIME, { value: 0 }))
94-
.to.be.revertedWithCustomError(depositor, "InsufficientDepositAmount")
95-
.withArgs(0);
93+
await expect(depositor.deposit(USER2.address, secretHash, LOCK_TIME, { value: 0 })).to.be.revertedWithCustomError(
94+
depositor,
95+
"ZeroDepositAmount"
96+
);
9697
});
9798

9899
it("should reject withdrawal with incorrect secret", async () => {

0 commit comments

Comments
 (0)