julien/lovepublic Fork
⑂ 7d97bbb
Commits
⬇ Clone ▾
git clone https://git.rickub.com/julien/love.git
git clone ssh://git@rickub.com/julien/love.git

Host key fingerprint (ed25519): SHA256:iycHnxEyq0Q7uyVpB7JlznP0G7JrTPXLYRcAU5CSLhc — verify it before your first connect.

Download ZIP

Merge 8-fix-secrethash-zero into main

rickub committed 2026-09-18T14:13:47Z Browse files
7d97bbb parent: e99639d
modified src/Love.sol +8 -0
@@ -74,6 +74,12 @@ contract Love is ERC20 {
7474 /// @param depositId The id that doesn't exist.
7575 error UnknownDeposit(uint256 depositId);
7676
77+ /// @notice Thrown when a privacy deposit is attempted with a zero `secretHash`.
78+ /// @dev `claim` uses `secretHash == bytes32(0)` as its "envelope doesn't
79+ /// exist" sentinel, so a zero hash would otherwise create an envelope
80+ /// that can never be claimed.
81+ error ZeroSecretHash();
82+
7783 /// @notice Thrown when a secret doesn't hash to the envelope's `secretHash`.
7884 /// @param depositId The envelope the wrong secret was tried against.
7985 error WrongSecret(uint256 depositId);
@@ -159,6 +165,8 @@ contract Love is ERC20 {
159165 /// @param wethAmount The wETH to lock, in wei.
160166 /// @return depositId The id this envelope was assigned.
161167 function deposit(bytes32 secretHash, uint256 wethAmount) external returns (uint256 depositId) {
168+ if (secretHash == bytes32(0)) revert ZeroSecretHash();
169+
162170 uint256 loveAmount = wethAmount * RATE;
163171
164172 WETH.safeTransferFrom(msg.sender, address(this), wethAmount);
@@ -74,6 +74,12 @@ contract Love is ERC20 {
74 /// @param depositId The id that doesn't exist.74 /// @param depositId The id that doesn't exist.
75 error UnknownDeposit(uint256 depositId);75 error UnknownDeposit(uint256 depositId);
76 76
77+ /// @notice Thrown when a privacy deposit is attempted with a zero `secretHash`.
78+ /// @dev `claim` uses `secretHash == bytes32(0)` as its "envelope doesn't
79+ /// exist" sentinel, so a zero hash would otherwise create an envelope
80+ /// that can never be claimed.
81+ error ZeroSecretHash();
82+
77 /// @notice Thrown when a secret doesn't hash to the envelope's `secretHash`.83 /// @notice Thrown when a secret doesn't hash to the envelope's `secretHash`.
78 /// @param depositId The envelope the wrong secret was tried against.84 /// @param depositId The envelope the wrong secret was tried against.
79 error WrongSecret(uint256 depositId);85 error WrongSecret(uint256 depositId);
@@ -159,6 +165,8 @@ contract Love is ERC20 {
159 /// @param wethAmount The wETH to lock, in wei.165 /// @param wethAmount The wETH to lock, in wei.
160 /// @return depositId The id this envelope was assigned.166 /// @return depositId The id this envelope was assigned.
161 function deposit(bytes32 secretHash, uint256 wethAmount) external returns (uint256 depositId) {167 function deposit(bytes32 secretHash, uint256 wethAmount) external returns (uint256 depositId) {
168+ if (secretHash == bytes32(0)) revert ZeroSecretHash();
169+
162 uint256 loveAmount = wethAmount * RATE;170 uint256 loveAmount = wethAmount * RATE;
163 171
164 WETH.safeTransferFrom(msg.sender, address(this), wethAmount);172 WETH.safeTransferFrom(msg.sender, address(this), wethAmount);
modified test/LoveEnvelope.t.sol +9 -0
@@ -102,6 +102,15 @@ contract LoveEnvelopeTest is Test, Fixtures {
102102 love.deposit(SECRET_HASH, 100 ether);
103103 }
104104
105+ function test_RevertWhen_SecretHashIsZero() public {
106+ vm.prank(alice);
107+ weth.approve(address(love), 1 ether);
108+
109+ vm.prank(alice);
110+ vm.expectRevert(Love.ZeroSecretHash.selector);
111+ love.deposit(bytes32(0), 1 ether);
112+ }
113+
105114 /*//////////////////////////////////////////////////////////////
106115 CLAIM
107116 //////////////////////////////////////////////////////////////*/
@@ -102,6 +102,15 @@ contract LoveEnvelopeTest is Test, Fixtures {
102 love.deposit(SECRET_HASH, 100 ether);102 love.deposit(SECRET_HASH, 100 ether);
103 }103 }
104 104
105+ function test_RevertWhen_SecretHashIsZero() public {
106+ vm.prank(alice);
107+ weth.approve(address(love), 1 ether);
108+
109+ vm.prank(alice);
110+ vm.expectRevert(Love.ZeroSecretHash.selector);
111+ love.deposit(bytes32(0), 1 ether);
112+ }
113+
105 /*//////////////////////////////////////////////////////////////114 /*//////////////////////////////////////////////////////////////
106 CLAIM115 CLAIM
107 //////////////////////////////////////////////////////////////*/116 //////////////////////////////////////////////////////////////*/