Skip to content

Commit 3c50a65

Browse files
authored
fix(host-contracts): bump ACL reinitializer version (#2107)
* fix(host-contracts): bump ACL reinitializer version * fix(host-contracts): remove legacy error ExpirationDateBeforeOneHour * refactor(host-contracts): replace ExpirationDateBeforeOneHour with weaker ExpirationDateInThePast check
1 parent 6a670a1 commit 3c50a65

File tree

10 files changed

+150
-118
lines changed

10 files changed

+150
-118
lines changed

host-contracts/contracts/ACL.sol

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

73-
/// @notice Returned if the requested expiration date for user decryption delegation is before the next hour.
74-
error ExpirationDateBeforeOneHour();
73+
/// @notice Returned if the requested expiration date for user decryption delegation is in the past.
74+
error ExpirationDateInThePast();
7575

7676
/// @notice Returned if the handlesList array is empty.
7777
error HandlesListIsEmpty();
@@ -143,7 +143,7 @@ contract ACL is
143143
uint256 private constant MAJOR_VERSION = 0;
144144

145145
/// @notice Minor version of the contract.
146-
uint256 private constant MINOR_VERSION = 2;
146+
uint256 private constant MINOR_VERSION = 3;
147147

148148
/// @notice Patch version of the contract.
149149
uint256 private constant PATCH_VERSION = 0;
@@ -156,7 +156,7 @@ contract ACL is
156156

157157
/// Constant used for making sure the version number used in the `reinitializer` modifier is
158158
/// identical between `initializeFromEmptyProxy` and the `reinitializeVX` method
159-
uint64 private constant REINITIALIZER_VERSION = 3;
159+
uint64 private constant REINITIALIZER_VERSION = 4;
160160

161161
/// keccak256(abi.encode(uint256(keccak256("fhevm.storage.ACL")) - 1)) & ~bytes32(uint256(0xff))
162162
bytes32 private constant ACLStorageLocation = 0xa688f31953c2015baaf8c0a488ee1ee22eb0e05273cc1fd31ea4cbee42febc00;
@@ -176,11 +176,11 @@ contract ACL is
176176
}
177177

178178
/**
179-
* @notice Re-initializes the contract from V1.
179+
* @notice Re-initializes the contract from V2.
180180
*/
181181
/// @custom:oz-upgrades-unsafe-allow missing-initializer-call
182182
/// @custom:oz-upgrades-validate-as-initializer
183-
function reinitializeV2() public virtual reinitializer(REINITIALIZER_VERSION) {}
183+
function reinitializeV3() public virtual reinitializer(REINITIALIZER_VERSION) {}
184184

185185
/**
186186
* @notice Allows the use of `handle` for the address `account`.
@@ -290,6 +290,9 @@ contract ACL is
290290
if (delegate == contractAddress) {
291291
revert DelegateCannotBeContractAddress(contractAddress);
292292
}
293+
if (expirationDate <= block.timestamp) {
294+
revert ExpirationDateInThePast();
295+
}
293296

294297
uint64 oldExpirationDate = userDecryptionDelegation.expirationDate;
295298
uint64 newExpirationDate = expirationDate;

host-contracts/docs/contract_selectors.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ ACL
5555
|----------+---------------------------------------------------------------------------+--------------------------------------------------------------------|
5656
| Function | proxiableUUID() | 0x52d1902d |
5757
|----------+---------------------------------------------------------------------------+--------------------------------------------------------------------|
58-
| Function | reinitializeV2() | 0xc4115874 |
58+
| Function | reinitializeV3() | 0xbac22bb8 |
5959
|----------+---------------------------------------------------------------------------+--------------------------------------------------------------------|
6060
| Function | renounceOwnership() | 0x715018a6 |
6161
|----------+---------------------------------------------------------------------------+--------------------------------------------------------------------|
@@ -113,7 +113,7 @@ ACL
113113
|----------+---------------------------------------------------------------------------+--------------------------------------------------------------------|
114114
| Error | ExpirationDateAlreadySetToSameValue(address,address,address,uint256) | 0x39a48202 |
115115
|----------+---------------------------------------------------------------------------+--------------------------------------------------------------------|
116-
| Error | ExpirationDateBeforeOneHour() | 0xcabc2529 |
116+
| Error | ExpirationDateInThePast() | 0x15515f1a |
117117
|----------+---------------------------------------------------------------------------+--------------------------------------------------------------------|
118118
| Error | FailedCall() | 0xd6bda275 |
119119
|----------+---------------------------------------------------------------------------+--------------------------------------------------------------------|

host-contracts/lib/FHE.sol

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9369,9 +9369,9 @@ library FHE {
93699369
/// - the ACL contract must not be paused.
93709370
/// Reverts via an {PausableUpgradeable-EnforcedPause} error otherwise.
93719371
///
9372-
/// - `expirationDate` must be at least 1 hour in the future.
9373-
/// i.e. `expirationDate >= block.timestamp + 1 hours`
9374-
/// Reverts with an {IACL-ExpirationDateBeforeOneHour} error otherwise.
9372+
/// - `expirationDate` must be strictly in the future.
9373+
/// i.e. `expirationDate > block.timestamp`
9374+
/// Reverts with an {IACL-ExpirationDateInThePast} error otherwise.
93759375
///
93769376
/// - `expirationDate` must differ from the current value.
93779377
/// Reverts with an {IACL-ExpirationDateAlreadySetToSameValue} error otherwise.

host-contracts/rust_bindings/src/acl.rs

Lines changed: 95 additions & 97 deletions
Large diffs are not rendered by default.

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

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ contract ACLTest is HostContractsDeployerTestUtils {
8585
* It checks that the version is correct, the owner/pauser are set to the expected addresses, and the fhevmExecutor address is correct.
8686
*/
8787
function test_PostProxyUpgradeCheck() public view {
88-
assertEq(acl.getVersion(), string(abi.encodePacked("ACL v0.2.0")));
88+
assertEq(acl.getVersion(), string(abi.encodePacked("ACL v0.3.0")));
8989
assertEq(acl.owner(), owner);
9090
assertEq(acl.isPauser(pauser), true);
9191
assertEq(acl.getFHEVMExecutorAddress(), fhevmExecutorAdd);
@@ -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
*/

host-contracts/test/fhevm-foundry/TestHostContractsDeployerTestUtils.t.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ contract TestHostContractsDeployerTestUtils is HostContractsDeployerTestUtils {
2424
assertEq(address(aclProxy), aclAdd, "ACL proxy address mismatch");
2525
assertNotEq(aclImplementation, address(0), "Implementation not deployed");
2626
assertEq(aclProxy.owner(), OWNER, "Owner mismatch");
27-
assertEq(aclProxy.getVersion(), "ACL v0.2.0", "Version mismatch");
27+
assertEq(aclProxy.getVersion(), "ACL v0.3.0", "Version mismatch");
2828
assertEq(_readImplementationSlot(aclAdd), aclImplementation, "Implementation slot mismatch");
2929
}
3030

host-contracts/test/upgrades/upgrades.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ describe('Upgrades', function () {
2727
});
2828
await acl.waitForDeployment();
2929
const ownerBef = await acl.owner();
30-
expect(await acl.getVersion()).to.equal('ACL v0.2.0');
30+
expect(await acl.getVersion()).to.equal('ACL v0.3.0');
3131
const acl2 = await upgrades.upgradeProxy(acl, this.aclFactoryUpgraded);
3232
await acl2.waitForDeployment();
3333
const ownerAft = await acl2.owner();
@@ -96,7 +96,7 @@ describe('Upgrades', function () {
9696
const origACLAdd = dotenv.parse(fs.readFileSync('addresses/.env.host')).ACL_CONTRACT_ADDRESS;
9797
const deployer = new ethers.Wallet(process.env.DEPLOYER_PRIVATE_KEY!).connect(ethers.provider);
9898
const acl = (await this.aclFactory.attach(origACLAdd, deployer)) as ACL;
99-
expect(await acl.getVersion()).to.equal('ACL v0.2.0');
99+
expect(await acl.getVersion()).to.equal('ACL v0.3.0');
100100
const newaclFactoryUpgraded = await ethers.getContractFactory('ACLUpgradedExample', deployer);
101101
const acl2 = (await upgrades.upgradeProxy(acl, newaclFactoryUpgraded)) as unknown as ACLUpgradedExample;
102102
await acl2.waitForDeployment();

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,9 +169,9 @@ library FHE {
169169
/// - the ACL contract must not be paused.
170170
/// Reverts via an {PausableUpgradeable-EnforcedPause} error otherwise.
171171
///
172-
/// - `expirationDate` must be at least 1 hour in the future.
173-
/// i.e. `expirationDate >= block.timestamp + 1 hours`
174-
/// Reverts with an {IACL-ExpirationDateBeforeOneHour} error otherwise.
172+
/// - `expirationDate` must be strictly in the future.
173+
/// i.e. `expirationDate > block.timestamp`
174+
/// Reverts with an {IACL-ExpirationDateInThePast} error otherwise.
175175
///
176176
/// - `expirationDate` must differ from the current value.
177177
/// Reverts with an {IACL-ExpirationDateAlreadySetToSameValue} error otherwise.

library-solidity/lib/FHE.sol

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9369,9 +9369,9 @@ library FHE {
93699369
/// - the ACL contract must not be paused.
93709370
/// Reverts via an {PausableUpgradeable-EnforcedPause} error otherwise.
93719371
///
9372-
/// - `expirationDate` must be at least 1 hour in the future.
9373-
/// i.e. `expirationDate >= block.timestamp + 1 hours`
9374-
/// Reverts with an {IACL-ExpirationDateBeforeOneHour} error otherwise.
9372+
/// - `expirationDate` must be strictly in the future.
9373+
/// i.e. `expirationDate > block.timestamp`
9374+
/// Reverts with an {IACL-ExpirationDateInThePast} error otherwise.
93759375
///
93769376
/// - `expirationDate` must differ from the current value.
93779377
/// Reverts with an {IACL-ExpirationDateAlreadySetToSameValue} error otherwise.

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)