Browse Source

Update remappings.txt for upgradeable contracts and set up submodule (#4639)

Co-authored-by: Hadrien Croubois <hadrien.croubois@gmail.com>
Co-authored-by: Ernesto García <ernestognw@gmail.com>
Francisco 2 years ago
parent
commit
abba0d047a

+ 4 - 0
.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

+ 5 - 6
.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
 

+ 2 - 0
.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 }}

+ 1 - 0
.gitignore

@@ -63,6 +63,7 @@ contracts-exposed
 
 # Foundry
 /out
+/cache_forge
 
 # Certora
 .certora*

+ 0 - 2
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

+ 0 - 2
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 {
     /**

+ 0 - 2
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 {
     /**

+ 0 - 2
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) {

+ 0 - 2
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 {
     /**

+ 0 - 2
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 {
     /**

+ 7 - 0
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

+ 12 - 1
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;
+}

+ 21 - 8
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",

+ 3 - 2
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",

+ 15 - 5
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"

+ 8 - 0
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