From abba0d047a24c8feaadf35589ea81a433c86ec0a Mon Sep 17 00:00:00 2001 From: Francisco Date: Mon, 2 Oct 2023 15:41:18 -0300 Subject: [PATCH] Update remappings.txt for upgradeable contracts and set up submodule (#4639) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Hadrien Croubois Co-authored-by: Ernesto GarcĂ­a --- .github/actions/setup/action.yml | 4 +++ .github/workflows/checks.yml | 11 ++++--- .github/workflows/upgradeable.yml | 2 ++ .gitignore | 1 + contracts/proxy/utils/UUPSUpgradeable.sol | 2 -- .../token/ERC1155/utils/ERC1155Holder.sol | 2 -- contracts/token/ERC721/utils/ERC721Holder.sol | 2 -- contracts/utils/Context.sol | 2 -- contracts/utils/Multicall.sol | 2 -- contracts/utils/introspection/ERC165.sol | 2 -- foundry.toml | 7 +++++ hardhat.config.js | 13 ++++++++- package-lock.json | 29 ++++++++++++++----- package.json | 5 ++-- scripts/upgradeable/transpile-onto.sh | 20 +++++++++---- scripts/upgradeable/upgradeable.patch | 8 +++++ 16 files changed, 78 insertions(+), 34 deletions(-) diff --git a/.github/actions/setup/action.yml b/.github/actions/setup/action.yml index 3154e9931..cab1188ac 100644 --- a/.github/actions/setup/action.yml +++ b/.github/actions/setup/action.yml @@ -15,3 +15,7 @@ runs: run: npm ci shell: bash if: steps.cache.outputs.cache-hit != 'true' + - name: Install Foundry + uses: foundry-rs/foundry-toolchain@v1 + with: + version: nightly diff --git a/.github/workflows/checks.yml b/.github/workflows/checks.yml index 3e7cba120..5b32bdb1d 100644 --- a/.github/workflows/checks.yml +++ b/.github/workflows/checks.yml @@ -57,8 +57,9 @@ jobs: - name: Set up environment uses: ./.github/actions/setup - name: Copy non-upgradeable contracts as dependency - run: - cp -rnT contracts node_modules/@openzeppelin/contracts + run: | + mkdir -p lib/openzeppelin-contracts + cp -rnT contracts lib/openzeppelin-contracts/contracts - name: Transpile to upgradeable run: bash scripts/upgradeable/transpile.sh - name: Run tests @@ -78,10 +79,8 @@ jobs: - uses: actions/checkout@v4 with: submodules: recursive - - name: Install Foundry - uses: foundry-rs/foundry-toolchain@v1 - with: - version: nightly + - name: Set up environment + uses: ./.github/actions/setup - name: Run tests run: forge test -vv diff --git a/.github/workflows/upgradeable.yml b/.github/workflows/upgradeable.yml index acbd71166..46bf15a4e 100644 --- a/.github/workflows/upgradeable.yml +++ b/.github/workflows/upgradeable.yml @@ -29,4 +29,6 @@ jobs: - run: bash scripts/git-user-config.sh - name: Transpile to upgradeable run: bash scripts/upgradeable/transpile-onto.sh ${{ github.ref_name }} origin/${{ github.ref_name }} + env: + SUBMODULE_REMOTE: https://github.com/${{ github.repository }}.git - run: git push origin ${{ github.ref_name }} diff --git a/.gitignore b/.gitignore index 2aac74485..a6caa9fc7 100644 --- a/.gitignore +++ b/.gitignore @@ -63,6 +63,7 @@ contracts-exposed # Foundry /out +/cache_forge # Certora .certora* diff --git a/contracts/proxy/utils/UUPSUpgradeable.sol b/contracts/proxy/utils/UUPSUpgradeable.sol index 045d6a326..f08e61c1e 100644 --- a/contracts/proxy/utils/UUPSUpgradeable.sol +++ b/contracts/proxy/utils/UUPSUpgradeable.sol @@ -15,8 +15,6 @@ import {ERC1967Utils} from "../ERC1967/ERC1967Utils.sol"; * `UUPSUpgradeable` with a custom implementation of upgrades. * * The {_authorizeUpgrade} function must be overridden to include access restriction to the upgrade mechanism. - * - * @custom:stateless */ abstract contract UUPSUpgradeable is IERC1822Proxiable { /// @custom:oz-upgrades-unsafe-allow state-variable-immutable diff --git a/contracts/token/ERC1155/utils/ERC1155Holder.sol b/contracts/token/ERC1155/utils/ERC1155Holder.sol index 6f353aa59..7c8d470e0 100644 --- a/contracts/token/ERC1155/utils/ERC1155Holder.sol +++ b/contracts/token/ERC1155/utils/ERC1155Holder.sol @@ -11,8 +11,6 @@ import {IERC1155Receiver} from "../IERC1155Receiver.sol"; * * IMPORTANT: When inheriting this contract, you must include a way to use the received tokens, otherwise they will be * stuck. - * - * @custom:stateless */ abstract contract ERC1155Holder is ERC165, IERC1155Receiver { /** diff --git a/contracts/token/ERC721/utils/ERC721Holder.sol b/contracts/token/ERC721/utils/ERC721Holder.sol index a7c4b03b5..4ffd16146 100644 --- a/contracts/token/ERC721/utils/ERC721Holder.sol +++ b/contracts/token/ERC721/utils/ERC721Holder.sol @@ -11,8 +11,6 @@ import {IERC721Receiver} from "../IERC721Receiver.sol"; * Accepts all token transfers. * Make sure the contract is able to use its token with {IERC721-safeTransferFrom}, {IERC721-approve} or * {IERC721-setApprovalForAll}. - * - * @custom:stateless */ abstract contract ERC721Holder is IERC721Receiver { /** diff --git a/contracts/utils/Context.sol b/contracts/utils/Context.sol index 8a74f2487..25e115925 100644 --- a/contracts/utils/Context.sol +++ b/contracts/utils/Context.sol @@ -12,8 +12,6 @@ pragma solidity ^0.8.20; * is concerned). * * This contract is only required for intermediate, library-like contracts. - * - * @custom:stateless */ abstract contract Context { function _msgSender() internal view virtual returns (address) { diff --git a/contracts/utils/Multicall.sol b/contracts/utils/Multicall.sol index aa23e635b..a9a3d3acf 100644 --- a/contracts/utils/Multicall.sol +++ b/contracts/utils/Multicall.sol @@ -7,8 +7,6 @@ import {Address} from "./Address.sol"; /** * @dev Provides a function to batch together multiple calls in a single external call. - * - * @custom:stateless */ abstract contract Multicall { /** diff --git a/contracts/utils/introspection/ERC165.sol b/contracts/utils/introspection/ERC165.sol index 1963a257d..71c8e4a4f 100644 --- a/contracts/utils/introspection/ERC165.sol +++ b/contracts/utils/introspection/ERC165.sol @@ -16,8 +16,6 @@ import {IERC165} from "./IERC165.sol"; * return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId); * } * ``` - * - * @custom:stateless */ abstract contract ERC165 is IERC165 { /** diff --git a/foundry.toml b/foundry.toml index d0aa4ea39..859f210cf 100644 --- a/foundry.toml +++ b/foundry.toml @@ -1,3 +1,10 @@ +[profile.default] +src = 'contracts' +out = 'out' +libs = ['node_modules', 'lib'] +test = 'test' +cache_path = 'cache_forge' + [fuzz] runs = 10000 max_test_rejects = 150000 diff --git a/hardhat.config.js b/hardhat.config.js index aca9d7273..f5d9527b3 100644 --- a/hardhat.config.js +++ b/hardhat.config.js @@ -8,6 +8,8 @@ const fs = require('fs'); const path = require('path'); +const proc = require('child_process'); + const argv = require('yargs/yargs')() .env('') .options({ @@ -37,6 +39,11 @@ const argv = require('yargs/yargs')() type: 'boolean', default: false, }, + foundry: { + alias: 'hasFoundry', + type: 'boolean', + default: hasFoundry(), + }, compiler: { alias: 'compileVersion', type: 'string', @@ -51,8 +58,8 @@ const argv = require('yargs/yargs')() require('@nomiclabs/hardhat-truffle5'); require('hardhat-ignore-warnings'); require('hardhat-exposed'); - require('solidity-docgen'); +argv.foundry && require('@nomicfoundation/hardhat-foundry'); for (const f of fs.readdirSync(path.join(__dirname, 'hardhat'))) { require(path.join(__dirname, 'hardhat', f)); @@ -114,3 +121,7 @@ if (argv.coverage) { require('solidity-coverage'); module.exports.networks.hardhat.initialBaseFeePerGas = 0; } + +function hasFoundry() { + return proc.spawnSync('forge', ['-V'], { stdio: 'ignore' }).error === undefined; +} diff --git a/package-lock.json b/package-lock.json index 3e1d9bded..30d6561d9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13,12 +13,13 @@ "@changesets/cli": "^2.26.0", "@changesets/pre": "^1.0.14", "@changesets/read": "^0.5.9", + "@nomicfoundation/hardhat-foundry": "^1.1.1", "@nomicfoundation/hardhat-network-helpers": "^1.0.3", "@nomiclabs/hardhat-truffle5": "^2.0.5", "@nomiclabs/hardhat-web3": "^2.0.0", "@openzeppelin/docs-utils": "^0.1.4", "@openzeppelin/test-helpers": "^0.5.13", - "@openzeppelin/upgrade-safe-transpiler": "^0.3.30", + "@openzeppelin/upgrade-safe-transpiler": "^0.3.32", "@openzeppelin/upgrades-core": "^1.20.6", "array.prototype.at": "^1.1.1", "chai": "^4.2.0", @@ -30,7 +31,7 @@ "glob": "^10.3.5", "graphlib": "^2.1.8", "hardhat": "^2.9.1", - "hardhat-exposed": "^0.3.12-1", + "hardhat-exposed": "^0.3.13", "hardhat-gas-reporter": "^1.0.9", "hardhat-ignore-warnings": "^0.2.0", "keccak256": "^1.0.2", @@ -2012,6 +2013,18 @@ "node": ">=14" } }, + "node_modules/@nomicfoundation/hardhat-foundry": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/@nomicfoundation/hardhat-foundry/-/hardhat-foundry-1.1.1.tgz", + "integrity": "sha512-cXGCBHAiXas9Pg9MhMOpBVQCkWRYoRFG7GJJAph+sdQsfd22iRs5U5Vs9XmpGEQd1yEvYISQZMeE68Nxj65iUQ==", + "dev": true, + "dependencies": { + "chalk": "^2.4.2" + }, + "peerDependencies": { + "hardhat": "^2.17.2" + } + }, "node_modules/@nomicfoundation/hardhat-network-helpers": { "version": "1.0.9", "resolved": "https://registry.npmjs.org/@nomicfoundation/hardhat-network-helpers/-/hardhat-network-helpers-1.0.9.tgz", @@ -2409,9 +2422,9 @@ } }, "node_modules/@openzeppelin/upgrade-safe-transpiler": { - "version": "0.3.30", - "resolved": "https://registry.npmjs.org/@openzeppelin/upgrade-safe-transpiler/-/upgrade-safe-transpiler-0.3.30.tgz", - "integrity": "sha512-nkJ4r+W+FUp0eAvE18uHh/smwD1NS3KLAGJ59+Vgmx3VlCvCDNaS0rTJ1FpwxDYD3J0Whx0ZVtHz2ySq4YsnNQ==", + "version": "0.3.32", + "resolved": "https://registry.npmjs.org/@openzeppelin/upgrade-safe-transpiler/-/upgrade-safe-transpiler-0.3.32.tgz", + "integrity": "sha512-ypgj6MXXcDG0dOuMwENXt0H4atCtCsPgpDgWZYewb2egfUCMpj6d2GO4pcNZgdn1zYsmUHfm5ZA/Nga/8qkdKA==", "dev": true, "dependencies": { "ajv": "^8.0.0", @@ -8252,9 +8265,9 @@ } }, "node_modules/hardhat-exposed": { - "version": "0.3.12-1", - "resolved": "https://registry.npmjs.org/hardhat-exposed/-/hardhat-exposed-0.3.12-1.tgz", - "integrity": "sha512-hDhh+wC6usu/OPT4v6hi+JdBxZJDgi6gVAw/45ApY7rgODCqpan7+8GuVwOtu0YK/9wPN9Y065MzAVFqJtylgA==", + "version": "0.3.13", + "resolved": "https://registry.npmjs.org/hardhat-exposed/-/hardhat-exposed-0.3.13.tgz", + "integrity": "sha512-hY2qCYSi2wD2ChZ0WP0oEPS4zlZ2vGaLOVXvfosGcy6mNeQ+pWsxTge35tTumCHwCzk/dYxLZq+KW0Z5t08yDA==", "dev": true, "dependencies": { "micromatch": "^4.0.4", diff --git a/package.json b/package.json index 3a53270a5..f2e8acfad 100644 --- a/package.json +++ b/package.json @@ -53,12 +53,13 @@ "@changesets/cli": "^2.26.0", "@changesets/pre": "^1.0.14", "@changesets/read": "^0.5.9", + "@nomicfoundation/hardhat-foundry": "^1.1.1", "@nomicfoundation/hardhat-network-helpers": "^1.0.3", "@nomiclabs/hardhat-truffle5": "^2.0.5", "@nomiclabs/hardhat-web3": "^2.0.0", "@openzeppelin/docs-utils": "^0.1.4", "@openzeppelin/test-helpers": "^0.5.13", - "@openzeppelin/upgrade-safe-transpiler": "^0.3.30", + "@openzeppelin/upgrade-safe-transpiler": "^0.3.32", "@openzeppelin/upgrades-core": "^1.20.6", "array.prototype.at": "^1.1.1", "chai": "^4.2.0", @@ -70,7 +71,7 @@ "glob": "^10.3.5", "graphlib": "^2.1.8", "hardhat": "^2.9.1", - "hardhat-exposed": "^0.3.12-1", + "hardhat-exposed": "^0.3.13", "hardhat-gas-reporter": "^1.0.9", "hardhat-ignore-warnings": "^0.2.0", "keccak256": "^1.0.2", diff --git a/scripts/upgradeable/transpile-onto.sh b/scripts/upgradeable/transpile-onto.sh index a966a9b9a..b8508f0c2 100644 --- a/scripts/upgradeable/transpile-onto.sh +++ b/scripts/upgradeable/transpile-onto.sh @@ -15,7 +15,7 @@ base="${2-}" bash scripts/upgradeable/transpile.sh commit="$(git rev-parse --short HEAD)" -branch="$(git rev-parse --abbrev-ref HEAD)" +start_branch="$(git rev-parse --abbrev-ref HEAD)" git add contracts @@ -36,9 +36,19 @@ else fi fi -# commit if there are changes to commit -if ! git diff --quiet --cached; then - git commit -m "Transpile $commit" +# abort if there are no changes to commit at this point +if git diff --quiet --cached; then + exit fi -git checkout "$branch" +if [[ -v SUBMODULE_REMOTE ]]; then + lib=lib/openzeppelin-contracts + git submodule add -b "${base#origin/}" "$SUBMODULE_REMOTE" "$lib" + git -C "$lib" checkout "$commit" + git add "$lib" +fi + +git commit -m "Transpile $commit" + +# return to original branch +git checkout "$start_branch" diff --git a/scripts/upgradeable/upgradeable.patch b/scripts/upgradeable/upgradeable.patch index f25710cde..522f82ca4 100644 --- a/scripts/upgradeable/upgradeable.patch +++ b/scripts/upgradeable/upgradeable.patch @@ -319,6 +319,14 @@ index 3a1617c09..97e59c2d9 100644 }, "keywords": [ "solidity", +diff --git a/remappings.txt b/remappings.txt +index 304d1386a..a1cd63bee 100644 +--- a/remappings.txt ++++ b/remappings.txt +@@ -1 +1,2 @@ +-@openzeppelin/contracts/=contracts/ ++@openzeppelin/contracts-upgradeable/=contracts/ ++@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/ diff --git a/test/utils/cryptography/EIP712.test.js b/test/utils/cryptography/EIP712.test.js index faf01f1a3..b25171a56 100644 --- a/test/utils/cryptography/EIP712.test.js