Skip to content

Commit 3bd7a19

Browse files
committed
Use oz-upgrades-unsafe-allow-reachable, update snapshots
1 parent 281cdeb commit 3bd7a19

File tree

8 files changed

+213
-202
lines changed

8 files changed

+213
-202
lines changed

packages/core/solidity/src/account.test.ts.md

Lines changed: 187 additions & 187 deletions
Large diffs are not rendered by default.
46 Bytes
Binary file not shown.

packages/core/solidity/src/account.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { defineFunctions } from './utils/define-functions';
44
import { printContract } from './print';
55
import { defaults as commonDefaults, withCommonDefaults, type CommonOptions } from './common-options';
66
import { setInfo } from './set-info';
7-
import { addSigner, signerArgs, signerFunctions, signers, type SignerOptions } from './signer';
7+
import { addLockingConstructorAllowReachable, addSigner, signerArgs, signerFunctions, signers, type SignerOptions } from './signer';
88
import { setUpgradeableAccount } from './set-upgradeable';
99

1010
export const defaults: Required<AccountOptions> = {
@@ -184,8 +184,7 @@ function addERC7579Modules(c: ContractBuilder, opts: AccountOptions): void {
184184
function addSignerInitializer(c: ContractBuilder, opts: AccountOptions): void {
185185
if (opts.upgradeable) {
186186
if (!opts.signer) {
187-
c.addConstructorComment('/// @custom:oz-upgrades-unsafe-allow constructor');
188-
c.addConstructorCode(`_disableInitializers();`);
187+
addLockingConstructorAllowReachable(c);
189188
}
190189
return; // Initializer added in signer.ts
191190
}
@@ -196,11 +195,10 @@ function addSignerInitializer(c: ContractBuilder, opts: AccountOptions): void {
196195
path: `@openzeppelin/${opts.upgradeable ? 'contracts-upgradeable' : 'contracts'}/proxy/utils/Initializable.sol`,
197196
});
198197

199-
// Add locking constructor
200-
c.addConstructorComment('/// @custom:oz-upgrades-unsafe-allow constructor');
201-
c.addConstructorCode('// Accounts are typically deployed and initialized as clones during their first user op,');
202-
c.addConstructorCode('// therefore, initializers are disabled for the implementation contract');
203-
c.addConstructorCode(`_disableInitializers();`);
198+
addLockingConstructorAllowReachable(c, [
199+
'// Accounts are typically deployed and initialized as clones during their first user op,',
200+
'// therefore, initializers are disabled for the implementation contract'
201+
]);
204202

205203
const fn = { name: 'initialize', kind: 'public' as const, args: signerArgs[opts.signer] };
206204
c.addModifier('initializer', fn);

packages/core/solidity/src/signer.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,7 @@ export function addSigner(c: ContractBuilder, signer: SignerOptions, upgradeable
3535
name: 'Initializable',
3636
path: '@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol',
3737
});
38-
// Add locking constructor
39-
c.addConstructorComment('/// @custom:oz-upgrades-unsafe-allow constructor');
40-
c.addConstructorCode(`_disableInitializers();`);
38+
addLockingConstructorAllowReachable(c);
4139

4240
const fn = { name: 'initialize', kind: 'public' as const, args: signerArgs[signer] };
4341
c.addModifier('initializer', fn);
@@ -61,6 +59,19 @@ export function addSigner(c: ContractBuilder, signer: SignerOptions, upgradeable
6159
}
6260
}
6361

62+
/**
63+
* Adds a locking constructor that disables initializers and annotates it to allow reachable constructors during Upgrades Plugins validations,
64+
* which includes constructors in parent contracts.
65+
*
66+
* @param c The contract builder.
67+
* @param bodyComments Optional comments to add to the constructor body, before disabling initializers.
68+
*/
69+
export function addLockingConstructorAllowReachable(c: ContractBuilder, bodyComments?: string[]): void {
70+
c.addConstructorComment('/// @custom:oz-upgrades-unsafe-allow-reachable constructor');
71+
bodyComments?.forEach(comment => c.addConstructorCode(comment));
72+
c.addConstructorCode(`_disableInitializers();`);
73+
}
74+
6475
export const signers = {
6576
ERC7702: {
6677
name: 'SignerERC7702',

packages/core/solidity/src/zip-foundry.test.ts.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1273,9 +1273,11 @@ Generated by [AVA](https://avajs.dev).
12731273
import {Initializable} from "@openzeppelin/contracts/proxy/utils/Initializable.sol";␊
12741274
import {SignerECDSA} from "@openzeppelin/contracts/utils/cryptography/signers/SignerECDSA.sol";␊
12751275
1276-
/// @custom:oz-upgrades-unsafe-allow constructor␊
12771276
contract MyAccount is Initializable, Account, EIP712, ERC7739, SignerECDSA, ERC721Holder, ERC1155Holder {␊
1277+
/// @custom:oz-upgrades-unsafe-allow-reachable constructor␊
12781278
constructor(address signer) EIP712("My Account", "1") SignerECDSA(signer) {␊
1279+
// Accounts are typically deployed and initialized as clones during their first user op,␊
1280+
// therefore, initializers are disabled for the implementation contract␊
12791281
_disableInitializers();␊
12801282
}␊
12811283
@@ -1429,8 +1431,8 @@ Generated by [AVA](https://avajs.dev).
14291431
import {SignerECDSAUpgradeable} from "@openzeppelin/contracts-upgradeable/utils/cryptography/signers/SignerECDSAUpgradeable.sol";␊
14301432
import {UUPSUpgradeable} from "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";␊
14311433
1432-
/// @custom:oz-upgrades-unsafe-allow constructor␊
14331434
contract MyAccount is Initializable, Account, EIP712, ERC7739, SignerECDSAUpgradeable, ERC721Holder, ERC1155Holder, UUPSUpgradeable {␊
1435+
/// @custom:oz-upgrades-unsafe-allow-reachable constructor␊
14341436
constructor() EIP712("My Account", "1") {␊
14351437
_disableInitializers();␊
14361438
}␊
79 Bytes
Binary file not shown.

packages/core/solidity/src/zip-hardhat.test.ts.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,7 @@ Generated by [AVA](https://avajs.dev).
503503
import {SignerECDSA} from "@openzeppelin/contracts/utils/cryptography/signers/SignerECDSA.sol";␊
504504
505505
contract MyAccount is Initializable, Account, EIP712, ERC7739, SignerECDSA, ERC721Holder, ERC1155Holder {␊
506-
/// @custom:oz-upgrades-unsafe-allow constructor␊
506+
/// @custom:oz-upgrades-unsafe-allow-reachable constructor␊
507507
constructor(address signer) EIP712("My Account", "1") SignerECDSA(signer) {␊
508508
// Accounts are typically deployed and initialized as clones during their first user op,␊
509509
// therefore, initializers are disabled for the implementation contract␊
@@ -593,7 +593,7 @@ Generated by [AVA](https://avajs.dev).
593593
import {UUPSUpgradeable} from "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";␊
594594
595595
contract MyAccount is Initializable, Account, EIP712, ERC7739, SignerECDSAUpgradeable, ERC721Holder, ERC1155Holder, UUPSUpgradeable {␊
596-
/// @custom:oz-upgrades-unsafe-allow constructor␊
596+
/// @custom:oz-upgrades-unsafe-allow-reachable constructor␊
597597
constructor() EIP712("My Account", "1") {␊
598598
_disableInitializers();␊
599599
}␊
15 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)