Skip to content

Commit a0b1ed7

Browse files
committed
refactor(host-contracts): replace ExpirationDateBeforeOneHour with weaker ExpirationDateInThePast check
1 parent 46da6ae commit a0b1ed7

File tree

8 files changed

+174
-5
lines changed

8 files changed

+174
-5
lines changed

host-contracts/contracts/ACL.sol

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ contract ACL is
7070
uint256 expirationDate
7171
);
7272

73+
/// @notice Returned if the requested expiration date for user decryption delegation is in the past.
74+
error ExpirationDateInThePast();
75+
7376
/// @notice Returned if the handlesList array is empty.
7477
error HandlesListIsEmpty();
7578

@@ -287,6 +290,9 @@ contract ACL is
287290
if (delegate == contractAddress) {
288291
revert DelegateCannotBeContractAddress(contractAddress);
289292
}
293+
if (expirationDate <= block.timestamp) {
294+
revert ExpirationDateInThePast();
295+
}
290296

291297
uint64 oldExpirationDate = userDecryptionDelegation.expirationDate;
292298
uint64 newExpirationDate = expirationDate;

host-contracts/docs/contract_selectors.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,8 @@ ACL
113113
|----------+---------------------------------------------------------------------------+--------------------------------------------------------------------|
114114
| Error | ExpirationDateAlreadySetToSameValue(address,address,address,uint256) | 0x39a48202 |
115115
|----------+---------------------------------------------------------------------------+--------------------------------------------------------------------|
116+
| Error | ExpirationDateInThePast() | 0x15515f1a |
117+
|----------+---------------------------------------------------------------------------+--------------------------------------------------------------------|
116118
| Error | FailedCall() | 0xd6bda275 |
117119
|----------+---------------------------------------------------------------------------+--------------------------------------------------------------------|
118120
| Error | HandlesListIsEmpty() | 0x70bd1996 |

host-contracts/lib/FHE.sol

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9369,6 +9369,10 @@ library FHE {
93699369
/// - the ACL contract must not be paused.
93709370
/// Reverts via an {PausableUpgradeable-EnforcedPause} error otherwise.
93719371
///
9372+
/// - `expirationDate` must be strictly in the future.
9373+
/// i.e. `expirationDate > block.timestamp`
9374+
/// Reverts with an {IACL-ExpirationDateInThePast} error otherwise.
9375+
///
93729376
/// - `expirationDate` must differ from the current value.
93739377
/// Reverts with an {IACL-ExpirationDateAlreadySetToSameValue} error otherwise.
93749378
///

host-contracts/rust_bindings/src/acl.rs

Lines changed: 123 additions & 5 deletions
Large diffs are not rendered by default.

host-contracts/test/acl/acl.t.sol

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,25 @@ contract ACLTest is HostContractsDeployerTestUtils {
306306
acl.delegateForUserDecryption(delegate, contractAddress, expirationDate);
307307
}
308308

309+
/**
310+
* @dev Tests that the sender cannot delegate for user decryption with expiration date in the past.
311+
*/
312+
function test_CannotDelegateForUserDecryptionWithExpirationDateInThePast(
313+
address sender,
314+
address delegate,
315+
address contractAddress
316+
) public {
317+
vm.assume(sender != contractAddress);
318+
vm.assume(sender != delegate);
319+
vm.assume(delegate != contractAddress);
320+
321+
uint64 expirationDate = uint64(block.timestamp);
322+
323+
vm.prank(sender);
324+
vm.expectRevert(ACL.ExpirationDateInThePast.selector);
325+
acl.delegateForUserDecryption(delegate, contractAddress, expirationDate);
326+
}
327+
309328
/**
310329
* @dev Tests that the sender cannot delegate to itself as the contract address.
311330
*/

library-solidity/codegen/src/templates/FHE.sol-template

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,10 @@ library FHE {
169169
/// - the ACL contract must not be paused.
170170
/// Reverts via an {PausableUpgradeable-EnforcedPause} error otherwise.
171171
///
172+
/// - `expirationDate` must be strictly in the future.
173+
/// i.e. `expirationDate > block.timestamp`
174+
/// Reverts with an {IACL-ExpirationDateInThePast} error otherwise.
175+
///
172176
/// - `expirationDate` must differ from the current value.
173177
/// Reverts with an {IACL-ExpirationDateAlreadySetToSameValue} error otherwise.
174178
///

library-solidity/lib/FHE.sol

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9369,6 +9369,10 @@ library FHE {
93699369
/// - the ACL contract must not be paused.
93709370
/// Reverts via an {PausableUpgradeable-EnforcedPause} error otherwise.
93719371
///
9372+
/// - `expirationDate` must be strictly in the future.
9373+
/// i.e. `expirationDate > block.timestamp`
9374+
/// Reverts with an {IACL-ExpirationDateInThePast} error otherwise.
9375+
///
93729376
/// - `expirationDate` must differ from the current value.
93739377
/// Reverts with an {IACL-ExpirationDateAlreadySetToSameValue} error otherwise.
93749378
///

library-solidity/test/FHEDelegation.t.sol

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,18 @@ contract FHEDelegationTest is HostContractsDeployerTestUtils {
252252
adapter.delegateUserDecryption(contractContext, contractContext, expirationDate);
253253
}
254254

255+
function testFuzz_DelegateUserDecryption_RevertsWhenExpiryInThePast(
256+
uint256 expirationDate,
257+
address delegate,
258+
address contractContext
259+
) public {
260+
_assumeDelegateAndContext(delegate, contractContext);
261+
uint64 boundedExpiry = uint64(bound(expirationDate, 0, block.timestamp));
262+
263+
vm.expectRevert(ACL.ExpirationDateInThePast.selector);
264+
adapter.delegateUserDecryption(delegate, contractContext, boundedExpiry);
265+
}
266+
255267
function testFuzz_DelegateUserDecryption_RevertsOnSameBlockReplay(
256268
uint256 expirationDate,
257269
address delegate,

0 commit comments

Comments
 (0)