diff --git a/contracts/mocks/import.sol b/contracts/mocks/import.sol index eacd205a..e98aca54 100644 --- a/contracts/mocks/import.sol +++ b/contracts/mocks/import.sol @@ -2,7 +2,9 @@ pragma solidity ^0.8.31; -// This file forces the compilation of contracts that are only used (as artifacts) in tests. +// This file lists the dependencies that the tests deploy. Hardhat 3 only emits artifacts for compilation roots, so +// these contracts get no artifact of their own. Importing them by name (with `exposed.imports`) makes the exposed +// plugin generate their `$`-prefixed versions, which are roots: the tests deploy these. // forge-lint: disable-start(unused-import) import {AccessManager} from "@openzeppelin/contracts/access/manager/AccessManager.sol"; import {ERC721} from "@openzeppelin/contracts/token/ERC721/ERC721.sol"; @@ -10,4 +12,8 @@ import {ERC1155} from "@openzeppelin/contracts/token/ERC1155/ERC1155.sol"; import {AccountERC7913Mock} from "@openzeppelin/contracts/mocks/account/AccountMock.sol"; import {ERC20Reentrant} from "@openzeppelin/contracts/mocks/token/ERC20Reentrant.sol"; import {Create2} from "@openzeppelin/contracts/utils/Create2.sol"; +import {CallReceiverMock} from "@openzeppelin/contracts/mocks/CallReceiverMock.sol"; +import {UpgradeableBeacon} from "@openzeppelin/contracts/proxy/beacon/UpgradeableBeacon.sol"; +import {ERC7913P256Verifier} from "@openzeppelin/contracts/utils/cryptography/verifiers/ERC7913P256Verifier.sol"; +import {ERC7913RSAVerifier} from "@openzeppelin/contracts/utils/cryptography/verifiers/ERC7913RSAVerifier.sol"; // forge-lint: disable-end(unused-import) diff --git a/contracts/mocks/utils/cryptography/ECDSAOwnedDKIMRegistryMock.sol b/contracts/mocks/utils/cryptography/ECDSAOwnedDKIMRegistryMock.sol new file mode 100644 index 00000000..42f38173 --- /dev/null +++ b/contracts/mocks/utils/cryptography/ECDSAOwnedDKIMRegistryMock.sol @@ -0,0 +1,9 @@ +// SPDX-License-Identifier: MIT + +pragma solidity ^0.8.20; + +import {ECDSAOwnedDKIMRegistry} from "@zk-email/email-tx-builder/src/utils/ECDSAOwnedDKIMRegistry.sol"; + +// Hardhat 3 only emits artifacts for contracts declared in a compilation root. The exposed version of +// `ECDSAOwnedDKIMRegistry` can't be used instead: its constructor runs the initializer, so `initialize` can't be called. +contract ECDSAOwnedDKIMRegistryMock is ECDSAOwnedDKIMRegistry {} diff --git a/hardhat.config.ts b/hardhat.config.ts index 04f89f0c..3a1398a4 100644 --- a/hardhat.config.ts +++ b/hardhat.config.ts @@ -29,9 +29,9 @@ const argv = await yargs() // `remappings.txt` points `@openzeppelin/contracts` to the submodule, which is what Foundry (and projects that install // this repository with `forge install`) need. Hardhat must instead resolve it through `node_modules`, as an npm -// package, for `npmFilesToBuild` to accept its files and for every dependency to share a single copy (the -// `zk-email-verify` submodule resolves `@openzeppelin/contracts` through npm). These remappings take precedence over -// the ones of `remappings.txt` for Hardhat only. +// package, so that every dependency shares a single copy (the `zk-email-verify` submodule resolves +// `@openzeppelin/contracts` through npm). These remappings take precedence over the ones of `remappings.txt` for +// Hardhat only. const hardhatRemappings = [ '@openzeppelin/contracts/=node_modules/@openzeppelin/contracts/contracts/', 'lib/@openzeppelin-contracts-upgradeable/contracts/:@openzeppelin/contracts/=node_modules/@openzeppelin/contracts/contracts/', @@ -55,11 +55,7 @@ export default defineConfig({ hardhatRemappingsPlugin(hardhatRemappings), ], paths: { - // `ECDSAOwnedDKIMRegistry` is needed (as-is, not exposed) by the tests. It lives in a submodule reached through a - // remappings.txt entry, so it is a project file that no compilation root imports by name: `npmFilesToBuild` cannot - // reach it (HHE901), and being imported is not enough for Hardhat 3 to emit an artifact. Building its directory as - // a source directory is what makes those artifacts appear. - sources: [argv.src, 'lib/email-tx-builder/packages/contracts/src/utils'], + sources: argv.src, }, solidity: { version: argv.compiler, @@ -68,15 +64,6 @@ export default defineConfig({ // files, which points `@openzeppelin/contracts` to a nested copy. The last entry of `remappings.txt` (and of // `hardhatRemappings`) uses a more specific context so that the submodule uses the same copy as the rest of the // project. (Comments are not allowed in `remappings.txt` as Foundry rejects them.) - // - // Dependencies that the tests deploy directly. Hardhat 3 only emits artifacts for compilation roots, so importing - // them from a solidity file (the old `contracts/mocks/import.sol` trick) is not enough anymore. - npmFilesToBuild: [ - '@openzeppelin/contracts/mocks/CallReceiverMock.sol', - '@openzeppelin/contracts/proxy/beacon/UpgradeableBeacon.sol', - '@openzeppelin/contracts/utils/cryptography/verifiers/ERC7913P256Verifier.sol', - '@openzeppelin/contracts/utils/cryptography/verifiers/ERC7913RSAVerifier.sol', - ], settings: { optimizer: { enabled: true, diff --git a/scripts/upgradeable/upgradeable.patch b/scripts/upgradeable/upgradeable.patch index e9268d2f..be044c28 100644 --- a/scripts/upgradeable/upgradeable.patch +++ b/scripts/upgradeable/upgradeable.patch @@ -14,8 +14,23 @@ index dbce31e2..074338a3 100644 ## Overview This repository contains contracts and libraries in the following categories: +diff --git a/contracts/mocks/utils/cryptography/ECDSAOwnedDKIMRegistryMock.sol b/contracts/mocks/utils/cryptography/ECDSAOwnedDKIMRegistryMock.sol +deleted file mode 100644 +index 42f38173..00000000 +--- a/contracts/mocks/utils/cryptography/ECDSAOwnedDKIMRegistryMock.sol ++++ /dev/null +@@ -1,9 +0,0 @@ +-// SPDX-License-Identifier: MIT +- +-pragma solidity ^0.8.20; +- +-import {ECDSAOwnedDKIMRegistry} from "@zk-email/email-tx-builder/src/utils/ECDSAOwnedDKIMRegistry.sol"; +- +-// Hardhat 3 only emits artifacts for contracts declared in a compilation root. The exposed version of +-// `ECDSAOwnedDKIMRegistry` can't be used instead: its constructor runs the initializer, so `initialize` can't be called. +-contract ECDSAOwnedDKIMRegistryMock is ECDSAOwnedDKIMRegistry {} diff --git a/hardhat.config.ts b/hardhat.config.ts -index 04f89f0c..bb081161 100644 +index 3a1398a4..20f84513 100644 --- a/hardhat.config.ts +++ b/hardhat.config.ts @@ -35,6 +35,7 @@ const argv = await yargs() @@ -26,16 +41,16 @@ index 04f89f0c..bb081161 100644 ]; // Configuration -@@ -59,7 +60,7 @@ export default defineConfig({ - // remappings.txt entry, so it is a project file that no compilation root imports by name: `npmFilesToBuild` cannot - // reach it (HHE901), and being imported is not enough for Hardhat 3 to emit an artifact. Building its directory as - // a source directory is what makes those artifacts appear. -- sources: [argv.src, 'lib/email-tx-builder/packages/contracts/src/utils'], -+ sources: [argv.src, 'lib/openzeppelin-community-contracts/contracts', 'lib/email-tx-builder/packages/contracts/src/utils'], +@@ -55,7 +56,7 @@ export default defineConfig({ + hardhatRemappingsPlugin(hardhatRemappings), + ], + paths: { +- sources: argv.src, ++ sources: [argv.src, 'lib/openzeppelin-community-contracts/contracts'], }, solidity: { version: argv.compiler, -@@ -127,7 +128,7 @@ export default defineConfig({ +@@ -114,7 +115,7 @@ export default defineConfig({ exposed: { imports: true, initializers: true, diff --git a/test/account/AccountERC7913.test.js b/test/account/AccountERC7913.test.js index bec6a49a..68184e10 100644 --- a/test/account/AccountERC7913.test.js +++ b/test/account/AccountERC7913.test.js @@ -33,10 +33,10 @@ const signerZKEmail = new NonNativeSigner( async function fixture() { // EOAs and environment const [admin, beneficiary, other] = await ethers.getSigners(); - const target = await ethers.deployContract('CallReceiverMock'); + const target = await ethers.deployContract('$CallReceiverMock'); // DKIM Registry for ZKEmail - const dkim = await ethers.deployContract('ECDSAOwnedDKIMRegistry'); + const dkim = await ethers.deployContract('ECDSAOwnedDKIMRegistryMock'); await dkim.initialize(admin, admin); await dkim .SET_PREFIX() diff --git a/test/account/AccountZKEmail.test.js b/test/account/AccountZKEmail.test.js index 6b884dba..23177eef 100644 --- a/test/account/AccountZKEmail.test.js +++ b/test/account/AccountZKEmail.test.js @@ -26,10 +26,10 @@ const SIGN_HASH_COMMAND = 'signHash'; async function fixture() { // EOAs and environment const [admin, beneficiary, other] = await ethers.getSigners(); - const target = await ethers.deployContract('CallReceiverMock'); + const target = await ethers.deployContract('$CallReceiverMock'); // Registry - const dkim = await ethers.deployContract('ECDSAOwnedDKIMRegistry'); + const dkim = await ethers.deployContract('ECDSAOwnedDKIMRegistryMock'); await dkim.initialize(admin, admin); await dkim .SET_PREFIX() diff --git a/test/account/RoleAccountFactory.test.js b/test/account/RoleAccountFactory.test.js index 2c7bc07e..6cde5bd2 100644 --- a/test/account/RoleAccountFactory.test.js +++ b/test/account/RoleAccountFactory.test.js @@ -173,7 +173,7 @@ describe('RoleAccountFactory', function () { describe('ERC-7821 execution', function () { beforeEach(async function () { - this.target = await ethers.deployContract('CallReceiverMock'); + this.target = await ethers.deployContract('$CallReceiverMock'); this.mode = encodeMode({ callType: CALL_TYPE_BATCH }); this.data = encodeBatch([this.target, 0n, this.target.interface.encodeFunctionData('mockFunction')]); }); diff --git a/test/account/modules/ERC7579DelayedExecutor.test.js b/test/account/modules/ERC7579DelayedExecutor.test.js index 32faefc5..ea3de6db 100644 --- a/test/account/modules/ERC7579DelayedExecutor.test.js +++ b/test/account/modules/ERC7579DelayedExecutor.test.js @@ -23,7 +23,7 @@ async function fixture() { // Deploy ERC-7579 validator module const mock = await ethers.deployContract('$ERC7579DelayedExecutorMock'); - const target = await ethers.deployContract('CallReceiverMock'); + const target = await ethers.deployContract('$CallReceiverMock'); // ERC-4337 env const helper = new ERC4337Helper(connection); diff --git a/test/account/modules/ERC7579Executor.test.js b/test/account/modules/ERC7579Executor.test.js index 90a1ecbc..bbdae89c 100644 --- a/test/account/modules/ERC7579Executor.test.js +++ b/test/account/modules/ERC7579Executor.test.js @@ -20,7 +20,7 @@ const { async function fixture() { // Deploy ERC-7579 validator module const mock = await ethers.deployContract('$ERC7579ExecutorMock'); - const target = await ethers.deployContract('CallReceiverMock'); + const target = await ethers.deployContract('$CallReceiverMock'); // ERC-4337 env const helper = new ERC4337Helper(connection); diff --git a/test/account/modules/ERC7579Multisig.test.js b/test/account/modules/ERC7579Multisig.test.js index b1ba6f31..363d4895 100644 --- a/test/account/modules/ERC7579Multisig.test.js +++ b/test/account/modules/ERC7579Multisig.test.js @@ -28,7 +28,7 @@ const signerECDSA4 = ethers.Wallet.createRandom(); // Unauthorized signer async function fixture() { // Deploy ERC-7579 multisig module const mock = await ethers.deployContract('$ERC7579MultisigExecutorMock', ['MultisigExecutor', '1']); - const target = await ethers.deployContract('CallReceiverMock'); + const target = await ethers.deployContract('$CallReceiverMock'); // ERC-4337 env const helper = new ERC4337Helper(connection); diff --git a/test/account/modules/ERC7579MultisigStorage.test.js b/test/account/modules/ERC7579MultisigStorage.test.js index 459b5c4c..624c537b 100644 --- a/test/account/modules/ERC7579MultisigStorage.test.js +++ b/test/account/modules/ERC7579MultisigStorage.test.js @@ -27,7 +27,7 @@ const signerECDSA4 = ethers.Wallet.createRandom(); // Unauthorized signer async function fixture() { // Deploy ERC-7579 multisig storage module const mock = await ethers.deployContract('$ERC7579MultisigStorageExecutorMock', ['MultisigStorageExecutor', '1']); - const target = await ethers.deployContract('CallReceiverMock'); + const target = await ethers.deployContract('$CallReceiverMock'); // ERC-4337 env const helper = new ERC4337Helper(connection); diff --git a/test/account/modules/ERC7579MultisigWeighted.test.js b/test/account/modules/ERC7579MultisigWeighted.test.js index 54c2b88b..5730c2ef 100644 --- a/test/account/modules/ERC7579MultisigWeighted.test.js +++ b/test/account/modules/ERC7579MultisigWeighted.test.js @@ -28,7 +28,7 @@ const signerECDSA4 = ethers.Wallet.createRandom(); // Unauthorized signer async function fixture() { // Deploy ERC-7579 multisig weighted module const mock = await ethers.deployContract('$ERC7579MultisigWeightedExecutorMock', ['MultisigWeightedExecutor', '1']); - const target = await ethers.deployContract('CallReceiverMock'); + const target = await ethers.deployContract('$CallReceiverMock'); // ERC-4337 env const helper = new ERC4337Helper(connection); diff --git a/test/account/modules/ERC7579SelectorExecutor.test.js b/test/account/modules/ERC7579SelectorExecutor.test.js index c02df8df..6230a2df 100644 --- a/test/account/modules/ERC7579SelectorExecutor.test.js +++ b/test/account/modules/ERC7579SelectorExecutor.test.js @@ -20,7 +20,7 @@ const { async function fixture() { // Deploy ERC-7579 selector executor module const mock = await ethers.deployContract('$ERC7579SelectorExecutor'); - const target = await ethers.deployContract('CallReceiverMock'); + const target = await ethers.deployContract('$CallReceiverMock'); // ERC-4337 env const helper = new ERC4337Helper(connection); diff --git a/test/account/modules/ERC7579SignatureValidator.test.js b/test/account/modules/ERC7579SignatureValidator.test.js index 6a81da2c..c8a6c9ab 100644 --- a/test/account/modules/ERC7579SignatureValidator.test.js +++ b/test/account/modules/ERC7579SignatureValidator.test.js @@ -25,8 +25,8 @@ async function fixture() { const mock = await ethers.deployContract('$ERC7579Signature'); // ERC-7913 verifiers - const verifierP256 = await ethers.deployContract('ERC7913P256Verifier'); - const verifierRSA = await ethers.deployContract('ERC7913RSAVerifier'); + const verifierP256 = await ethers.deployContract('$ERC7913P256Verifier'); + const verifierRSA = await ethers.deployContract('$ERC7913RSAVerifier'); // ERC-4337 env const helper = new ERC4337Helper(connection); diff --git a/test/proxy/HybridProxy.test.js b/test/proxy/HybridProxy.test.js index 27c8aafa..849e9fc0 100644 --- a/test/proxy/HybridProxy.test.js +++ b/test/proxy/HybridProxy.test.js @@ -12,7 +12,7 @@ async function fixture() { const implementation1 = await ethers.deployContract('UpgradeableImplementationMock', [1]); const implementation2 = await ethers.deployContract('UpgradeableImplementationMock', [2]); const implementation3 = await ethers.deployContract('UpgradeableImplementationMock', [3]); - const beacon = await ethers.deployContract('UpgradeableBeacon', [implementation1, admin]); + const beacon = await ethers.deployContract('$UpgradeableBeacon', [implementation1, admin]); const proxy = await ethers .deployContract('HybridProxy', [beacon, '0x']) .then(({ target }) => implementation1.attach(target)); diff --git a/test/utils/cryptography/ZKEmailUtils.test.js b/test/utils/cryptography/ZKEmailUtils.test.js index 6cddcad7..51f57200 100644 --- a/test/utils/cryptography/ZKEmailUtils.test.js +++ b/test/utils/cryptography/ZKEmailUtils.test.js @@ -23,7 +23,7 @@ async function fixture() { const [admin, other, ...accounts] = await ethers.getSigners(); // Registry - const dkim = await ethers.deployContract('ECDSAOwnedDKIMRegistry'); + const dkim = await ethers.deployContract('ECDSAOwnedDKIMRegistryMock'); await dkim.initialize(admin, admin); await dkim .SET_PREFIX()