diff --git a/.eslintignore b/.eslintignore index a401ad257..7a8060399 100644 --- a/.eslintignore +++ b/.eslintignore @@ -4,6 +4,5 @@ artifacts cache constants coverage -lib/murky -lib/openzeppelin-contracts +lib order-validator/test \ No newline at end of file diff --git a/.github/actions/forge-precompile/action.yml b/.github/actions/forge-precompile/action.yml new file mode 100644 index 000000000..eaf325440 --- /dev/null +++ b/.github/actions/forge-precompile/action.yml @@ -0,0 +1,49 @@ +name: Restore or build precompiled Forge artifacts +description: >- + Restore the reference (via_ir = false) and optimized (via_ir = true) builds + from the cache, and compile whichever is missing. A cache outage costs a + rebuild instead of failing the job. + +inputs: + cache-key: + description: The key computed by the forge-build job. + required: true + save: + description: Whether to save the build to the cache after compiling it. + required: false + default: "false" + +runs: + using: composite + steps: + - name: Restore precompiled artifacts + id: restore + uses: actions/cache/restore@v6 + with: + path: | + reference-out + reference-cache + optimized-out + optimized-cache + key: ${{ inputs.cache-key }} + + - name: Precompile reference using 0.8.24 and via-ir=false + if: steps.restore.outputs.cache-hit != 'true' + shell: bash + run: FOUNDRY_PROFILE=reference forge build + + - name: Precompile optimized using 0.8.24 and via-ir=true + if: steps.restore.outputs.cache-hit != 'true' + shell: bash + run: FOUNDRY_PROFILE=optimized forge build + + - name: Save precompiled artifacts + if: inputs.save == 'true' && steps.restore.outputs.cache-hit != 'true' + uses: actions/cache/save@v6 + with: + path: | + reference-out + reference-cache + optimized-out + optimized-cache + key: ${{ inputs.cache-key }} diff --git a/.github/actions/setup-foundry/action.yml b/.github/actions/setup-foundry/action.yml new file mode 100644 index 000000000..e1f9d3bd4 --- /dev/null +++ b/.github/actions/setup-foundry/action.yml @@ -0,0 +1,37 @@ +name: Set up Foundry +description: >- + Install a pinned Foundry version, reusing a cached copy so a GitHub releases + outage doesn't fail the job. + +inputs: + version: + description: The Foundry version to install, such as v1.9.0. + required: true + +runs: + using: composite + steps: + - name: Restore Foundry + id: cache + uses: actions/cache@v6 + with: + # foundryup installs the binaries under versions/ and links them + # from bin/, so both are cached. + path: | + ~/.foundry/bin + ~/.foundry/versions + key: foundry-install-${{ runner.os }}-${{ inputs.version }} + + - name: Install Foundry + if: steps.cache.outputs.cache-hit != 'true' + uses: foundry-rs/foundry-toolchain@dba66c27052e63476d886f22216e119ba7e615bf # v1.9.2 + with: + version: ${{ inputs.version }} + + - name: Add Foundry to PATH + shell: bash + run: echo "$HOME/.foundry/bin" >>"$GITHUB_PATH" + + - name: Print Foundry version + shell: bash + run: forge --version diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml deleted file mode 100644 index 76fc280cf..000000000 --- a/.github/workflows/docs.yml +++ /dev/null @@ -1,22 +0,0 @@ -name: Publish Docs to Central Repository -on: - release: - types: [created] -jobs: - build: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - name: Copy developer docs to repository - if: github.ref == 'refs/heads/main' - uses: nkoppel/push-files-to-another-repository@v1.1.1 - env: - API_TOKEN_GITHUB: ${{ secrets.API_TOKEN_GITHUB }} - with: - source-files: "docs/" - destination-username: "ProjectOpenSea" - destination-repository: "developer-docs" - destination-directory: "seaport" - destination-branch: "main" - commit-username: "ProjectOpenSea-seaport" - commit-message: "Latest docs from seaport" \ No newline at end of file diff --git a/.github/workflows/stale.yml b/.github/workflows/stale.yml index a864f4dbe..ea039630e 100644 --- a/.github/workflows/stale.yml +++ b/.github/workflows/stale.yml @@ -3,11 +3,17 @@ on: schedule: - cron: "0 0 * * *" +permissions: + actions: write # actions/stale keeps its state in the Actions cache + issues: write + pull-requests: write + jobs: stale: runs-on: ubuntu-latest + timeout-minutes: 10 steps: - - uses: actions/stale@v8 + - uses: actions/stale@v11 with: repo-token: ${{ secrets.GITHUB_TOKEN }} stale-issue-message: "This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 14 days if no further activity occurs. Thank you for your contributions. If you believe this was a mistake, please comment." diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 484ffab24..82021b43f 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -7,243 +7,226 @@ on: pull_request: types: [opened, reopened, synchronize] +# A new push to a pull request cancels its older run. Every other run gets +# its own group, so no run on a branch or tag is cancelled while it waits. concurrency: - group: ${{github.workflow}}-${{github.ref}} + group: ${{ github.workflow }}-${{ github.event_name == 'pull_request' && github.ref || github.run_id }} cancel-in-progress: true +permissions: + contents: read + +env: + FOUNDRY_VERSION: v1.9.0 + jobs: build: name: Build Artifacts runs-on: ubuntu-latest - - strategy: - matrix: - node-version: [18.15.0] - + timeout-minutes: 15 steps: - - uses: actions/checkout@v5 + - uses: actions/checkout@v7 - name: Use Node.js - uses: actions/setup-node@v3 + uses: actions/setup-node@v7 with: - node-version: ${{ matrix.node-version }} - cache: "yarn" - - run: yarn install + node-version-file: .nvmrc + cache: yarn + - run: yarn install --frozen-lockfile - run: yarn build lint: name: Run Linters runs-on: ubuntu-latest - - strategy: - matrix: - node-version: [18.15.0] - + timeout-minutes: 15 steps: - - uses: actions/checkout@v5 + - uses: actions/checkout@v7 - name: Use Node.js - uses: actions/setup-node@v3 + uses: actions/setup-node@v7 with: - node-version: ${{ matrix.node-version }} - cache: "yarn" - - run: yarn install + node-version-file: .nvmrc + cache: yarn + - run: yarn install --frozen-lockfile - run: yarn lint:check test: name: Run Tests runs-on: ubuntu-latest - - strategy: - matrix: - node-version: [18.15.0] - + timeout-minutes: 20 steps: - - uses: actions/checkout@v5 + - uses: actions/checkout@v7 - name: Use Node.js - uses: actions/setup-node@v3 + uses: actions/setup-node@v7 with: - node-version: ${{ matrix.node-version }} - cache: "yarn" - - run: yarn install + node-version-file: .nvmrc + cache: yarn + - run: yarn install --frozen-lockfile - run: yarn build - run: yarn test reference-test: name: Run Reference Tests runs-on: ubuntu-latest - - strategy: - matrix: - node-version: [18.15.0] - + timeout-minutes: 20 env: REFERENCE: true - steps: - - uses: actions/checkout@v5 + - uses: actions/checkout@v7 - name: Use Node.js - uses: actions/setup-node@v3 + uses: actions/setup-node@v7 with: - node-version: ${{ matrix.node-version }} - cache: "yarn" - - run: yarn install + node-version-file: .nvmrc + cache: yarn + - run: yarn install --frozen-lockfile - run: yarn build - run: yarn build:ref - run: yarn test:ref + reference-coverage: + name: Run Reference Coverage Tests + runs-on: ubuntu-latest + timeout-minutes: 20 + env: + REFERENCE: true + steps: + - uses: actions/checkout@v7 + - name: Use Node.js + uses: actions/setup-node@v7 + with: + node-version-file: .nvmrc + cache: yarn + - run: yarn install --frozen-lockfile + - run: yarn build + - run: yarn build:ref + - run: yarn coverage:ref + - uses: codecov/codecov-action@303a32d7a59b442fa8d48b6a1cc6825c09c847a5 # v7.1.1 + with: + files: ./coverage/lcov.info + flags: reference + token: ${{ secrets.CODECOV_TOKEN }} + + # Compiles the reference (via_ir = false) and optimized (via_ir = true) + # profiles once and caches them. The Forge test jobs restore that cache + # instead of each spending several minutes rebuilding, and rebuild only if + # the cache is unavailable. + forge-build: + name: Build Forge Artifacts + runs-on: ubuntu-latest + timeout-minutes: 20 + outputs: + cache-key: ${{ steps.key.outputs.cache-key }} + steps: + - uses: actions/checkout@v7 + with: + submodules: recursive + + - uses: ./.github/actions/setup-foundry + with: + version: ${{ env.FOUNDRY_VERSION }} + + # The key covers every input of the two builds: the Foundry version, + # compiler settings and remappings, sources, the build steps, and each + # submodule commit (hashFiles can't see gitlinks). If an input is + # missing, a stale build could satisfy the deployed bytecode check. + - name: Compute cache key + id: key + run: | + submodules=$(git submodule status --recursive | sha256sum | cut -c1-16) + echo "cache-key=forge-precompiled-${{ env.FOUNDRY_VERSION }}-${{ hashFiles('foundry.toml', 'remappings.txt', 'contracts/**', 'reference/**', '.github/actions/**') }}-${submodules}" >> "$GITHUB_OUTPUT" + + - uses: ./.github/actions/forge-precompile + with: + cache-key: ${{ steps.key.outputs.cache-key }} + save: "true" + forge: - name: Run Forge Tests (via_ir = true; fuzz_runs = 5000) + name: Run Forge Tests (via_ir = true) + needs: forge-build runs-on: ubuntu-latest timeout-minutes: 30 steps: - - uses: actions/checkout@v5 + - uses: actions/checkout@v7 with: submodules: recursive - - name: Install Foundry - uses: foundry-rs/foundry-toolchain@v1 + - uses: ./.github/actions/setup-foundry with: - version: v1.4.4 + version: ${{ env.FOUNDRY_VERSION }} - - name: Install forge dependencies - run: forge install - - - name: Precompile reference using 0.8.24 and via-ir=false - run: FOUNDRY_PROFILE=reference forge build + - uses: ./.github/actions/forge-precompile + with: + cache-key: ${{ needs.forge-build.outputs.cache-key }} - - name: Precompile optimized using 0.8.24 and via-ir=true - run: FOUNDRY_PROFILE=optimized forge build + - name: Check the build matches deployed Seaport 1.6 + run: FOUNDRY_PROFILE=test forge test --match-path test/foundry/DeployedBytecode.t.sol -vvv - name: Run tests run: FOUNDRY_PROFILE=test forge test -vvv forge-ref: - name: Run Forge Reference Tests (via_ir = false; fuzz_runs = 5000) + name: Run Forge Reference Tests (via_ir = false) + needs: forge-build runs-on: ubuntu-latest timeout-minutes: 30 steps: - - uses: actions/checkout@v5 + - uses: actions/checkout@v7 with: submodules: recursive - - name: Install Foundry - uses: foundry-rs/foundry-toolchain@v1 + - uses: ./.github/actions/setup-foundry with: - version: v1.4.4 - - - name: Install forge dependencies - run: forge install - - - name: Precompile reference using 0.8.24 and via-ir=false - run: FOUNDRY_PROFILE=reference forge build + version: ${{ env.FOUNDRY_VERSION }} - - name: Precompile optimized using 0.8.24 and via-ir=true - run: FOUNDRY_PROFILE=optimized forge build + - uses: ./.github/actions/forge-precompile + with: + cache-key: ${{ needs.forge-build.outputs.cache-key }} - name: Run reference tests run: FOUNDRY_PROFILE=reference MOAT_PROFILE=reference forge test -vvv - + forge-offerers: - name: Run Contract Offerer Forge Tests (via_ir = false; fuzz_runs = 1000) + name: Run Contract Offerer Forge Tests (via_ir = false) + needs: forge-build runs-on: ubuntu-latest + timeout-minutes: 20 steps: - - uses: actions/checkout@v5 + - uses: actions/checkout@v7 with: submodules: recursive - - name: Install Foundry - uses: foundry-rs/foundry-toolchain@v1 + - uses: ./.github/actions/setup-foundry with: - version: v1.4.4 - - - name: Install forge dependencies - run: forge install - - - name: Precompile reference using 0.8.24 and via-ir=false - run: FOUNDRY_PROFILE=reference forge build + version: ${{ env.FOUNDRY_VERSION }} - - name: Precompile optimized using 0.8.24 and via-ir=true - run: FOUNDRY_PROFILE=optimized forge build + - uses: ./.github/actions/forge-precompile + with: + cache-key: ${{ needs.forge-build.outputs.cache-key }} - name: Run tests run: FOUNDRY_PROFILE=offerers forge test -vvv forge-coverage: name: Run Forge Coverage report on tests + needs: forge-build runs-on: ubuntu-latest + timeout-minutes: 30 steps: - - uses: actions/checkout@v5 + - uses: actions/checkout@v7 with: submodules: recursive - - name: Install Foundry - uses: foundry-rs/foundry-toolchain@v1 + - uses: ./.github/actions/setup-foundry with: - version: v1.4.4 - - - name: Install forge dependencies - run: forge install - - - name: Precompile reference using 0.8.24 and via-ir=false - run: FOUNDRY_PROFILE=reference forge build + version: ${{ env.FOUNDRY_VERSION }} - - name: Precompile optimized using 0.8.24 and via-ir=true - run: FOUNDRY_PROFILE=optimized forge build + - uses: ./.github/actions/forge-precompile + with: + cache-key: ${{ needs.forge-build.outputs.cache-key }} - name: Run coverage with lcov output run: FOUNDRY_PROFILE=default SEAPORT_COVERAGE=true forge coverage --report lcov - - uses: codecov/codecov-action@v3 + - uses: codecov/codecov-action@303a32d7a59b442fa8d48b6a1cc6825c09c847a5 # v7.1.1 with: files: ./lcov.info flags: foundry - -# TODO: work out how to run legacy coverage (also how to run against core) -# coverage: -# name: Run Coverage Tests -# runs-on: ubuntu-latest -# -# strategy: -# matrix: -# node-version: [18.15.0] -# -# steps: -# - uses: actions/checkout@v5 -# - name: Use Node.js -# uses: actions/setup-node@v3 -# with: -# node-version: ${{ matrix.node-version }} -# cache: "yarn" -# - run: yarn install -# - run: yarn build -# - run: yarn coverage -# - uses: codecov/codecov-action@v3 -# with: -# files: ./coverage/lcov.info -# flags: production - - reference-coverage: - name: Run Reference Coverage Tests - runs-on: ubuntu-latest - - strategy: - matrix: - node-version: [18.15.0] - - env: - REFERENCE: true - - steps: - - uses: actions/checkout@v5 - - name: Use Node.js - uses: actions/setup-node@v3 - with: - node-version: ${{ matrix.node-version }} - cache: "yarn" - - run: yarn install - - run: yarn build - - run: yarn build:ref - - run: yarn coverage:ref - - uses: codecov/codecov-action@v3 - with: - files: ./coverage/lcov.info - flags: reference + token: ${{ secrets.CODECOV_TOKEN }} diff --git a/.gitignore b/.gitignore index 94b5da0e1..3e3bd23a3 100644 --- a/.gitignore +++ b/.gitignore @@ -16,6 +16,8 @@ hh-cache-ref/ cache out reference-out +reference-cache +optimized-cache optimized-out reference-working offerers-out diff --git a/.gitmodules b/.gitmodules index ee0bf3c83..2cab7fbfd 100644 --- a/.gitmodules +++ b/.gitmodules @@ -16,9 +16,6 @@ [submodule "lib/solarray"] path = lib/solarray url = https://github.com/emo-eth/solarray -[submodule "lib/ds-test"] - path = lib/ds-test - url = https://github.com/dapphub/ds-test [submodule "lib/seaport-types"] path = lib/seaport-types url = https://github.com/projectopensea/seaport-types diff --git a/.nvmrc b/.nvmrc index b8c9fdcbe..6f4247a62 100644 --- a/.nvmrc +++ b/.nvmrc @@ -1 +1 @@ -16.15.1 \ No newline at end of file +26 diff --git a/README.md b/README.md index a59ba6dfe..6860bcb4a 100644 --- a/README.md +++ b/README.md @@ -806,7 +806,7 @@ For a more thorough flowchart see [Seaport diagram](./diagrams/Seaport.drawio.sv ## Install -To install dependencies and compile contracts: +To install dependencies and compile contracts (Node.js version in `.nvmrc`): ```bash git clone --recurse-submodules https://github.com/ProjectOpenSea/seaport && cd seaport @@ -856,6 +856,8 @@ FOUNDRY_PROFILE=optimized forge build This should create an `optimized-out/` directory in your project root. +The optimized build reproduces the init code of the deployed Seaport 1.6 contract byte for byte. `test/foundry/DeployedBytecode.t.sol` fails if a toolchain or dependency change breaks that. CI uses Foundry v1.9.0 (`foundryup --install v1.9.0`). + To run tests with full traces and debugging with source, create an `.env` file with the following line: ```bash diff --git a/foundry.toml b/foundry.toml index 460739791..4d4263181 100644 --- a/foundry.toml +++ b/foundry.toml @@ -7,7 +7,6 @@ libs = ["node_modules", "lib"] test = 'test/foundry' remappings = [ '@rari-capital/solmate/=lib/solmate/', - 'ds-test/=lib/ds-test/src/', 'forge-std/=lib/forge-std/src/', 'murky/=lib/murky/src/', '@openzeppelin/=lib/openzeppelin-contracts/', @@ -50,8 +49,14 @@ cache_path = 'reference-cache' [profile.optimized] via_ir = true out = 'optimized-out' +# Separate from the default `cache`, so the test profile doesn't evict it and +# CI can cache this build on its own. +cache_path = 'optimized-cache' script = 'contracts' bytecode_hash = 'none' +# This profile reproduces the deployed Seaport 1.6 init code, which +# test/foundry/DeployedBytecode.t.sol checks. 1.6 was verified with 9_999_999 +# optimizer runs, but the default 4_294_967_295 produces identical bytecode. # no need to compile tests with via-ir since they load optimized bytecode directly by default test ='contracts' diff --git a/lib/ds-test b/lib/ds-test deleted file mode 160000 index e282159d5..000000000 --- a/lib/ds-test +++ /dev/null @@ -1 +0,0 @@ -Subproject commit e282159d5170298eb2455a6c05280ab5a73a4ef0 diff --git a/lib/forge-std b/lib/forge-std index cffb56287..f3dae6e6e 160000 --- a/lib/forge-std +++ b/lib/forge-std @@ -1 +1 @@ -Subproject commit cffb5628775fbf120bfc3c123149f6a6d99dc275 +Subproject commit f3dae6e6ee381f25eb6a246f7da9b85c91a68219 diff --git a/lib/seaport-core b/lib/seaport-core index 1a0a4758c..523097f9c 160000 --- a/lib/seaport-core +++ b/lib/seaport-core @@ -1 +1 @@ -Subproject commit 1a0a4758cced1d3de962817cd37c2387fb290eea +Subproject commit 523097f9cee66c15d308c900c50f336b291cda08 diff --git a/package.json b/package.json index dd567da4d..baf12a3bb 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "license": "MIT", "private": false, "engines": { - "node": ">=18.15.0" + "node": ">=26" }, "dependencies": { "@nomicfoundation/hardhat-network-helpers": "^1.0.7", diff --git a/test/foundry/DeployedBytecode.t.sol b/test/foundry/DeployedBytecode.t.sol new file mode 100644 index 000000000..16f51ca10 --- /dev/null +++ b/test/foundry/DeployedBytecode.t.sol @@ -0,0 +1,56 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.17; + +import { Test } from "forge-std/Test.sol"; + +/** + * @notice Checks that the `optimized` profile still builds the exact init code + * of the canonical Seaport 1.6 deployment, so toolchain and dependency + * changes in this repository cannot silently change the contract. + * + * Run `FOUNDRY_PROFILE=optimized forge build` before this test. + */ +contract DeployedBytecodeTest is Test { + // Canonical Seaport 1.6, deployed at the same address on every chain. + address constant SEAPORT_1_6 = 0x0000000000000068F116a894984e2DB1123eB395; + + // Constructor argument of the canonical deployment. + address constant CONDUIT_CONTROLLER = + 0x00000000F9490004C11Cef243f5400493c00Ad63; + + // ImmutableCreate2Factory and the salt passed to it in Ethereum mainnet + // tx 0x926e958d5919f0089f47a353b0a8a211bd858abb20348261d41672d77fa7c6a0. + address constant IMMUTABLE_CREATE2_FACTORY = + 0x0000000000FFe8B47B3e2130213B802212439497; + bytes32 constant SEAPORT_1_6_SALT = + 0x0000000000000000000000000000000000000000d738b7f0bb99901b1c83f249; + + // keccak256 of the init code (creation code plus constructor argument) + // deployed in the transaction above. + bytes32 constant SEAPORT_1_6_INIT_CODE_HASH = + 0xde057106c8377de87f4547af6ef65fa2c96fddbc136be5748060ed7c32902d94; + + function test_initCodeHashDerivesCanonicalAddress() public pure { + assertEq( + vm.computeCreate2Address( + SEAPORT_1_6_SALT, + SEAPORT_1_6_INIT_CODE_HASH, + IMMUTABLE_CREATE2_FACTORY + ), + SEAPORT_1_6 + ); + } + + function test_optimizedBuildMatchesDeployedInitCode() public view { + bytes memory initCode = abi.encodePacked( + vm.getCode("optimized-out/Seaport.sol/Seaport.json"), + abi.encode(CONDUIT_CONTROLLER) + ); + + assertEq( + keccak256(initCode), + SEAPORT_1_6_INIT_CODE_HASH, + "Seaport build no longer matches the deployed 1.6 init code" + ); + } +} diff --git a/test/foundry/zone/TestTransferValidationZoneFuzz.t.sol b/test/foundry/zone/TestTransferValidationZoneFuzz.t.sol index 29aee2cd7..5b1f749a7 100644 --- a/test/foundry/zone/TestTransferValidationZoneFuzz.t.sol +++ b/test/foundry/zone/TestTransferValidationZoneFuzz.t.sol @@ -627,16 +627,23 @@ contract TestTransferValidationZoneOffererTest is BaseOrderTest { // If the fuzz args call for using the transfer validation zone, make // sure that it is actually enforcing the expected requirements. if (context.fulfillArgs.shouldUseTransferValidationZone) { + // Keep the negative-test recipient distinct from the authorized one. + address expectedRecipient = context + .fulfillArgs + .shouldSpecifyRecipient + ? context.fulfillArgs.offerRecipient + : address(this); address strangerAddress = address(0xdeafbeef); + if (strangerAddress == expectedRecipient) { + strangerAddress = address(0xdeafbef0); + } vm.expectRevert( abi.encodeWithSignature( "InvalidOwner(address,address,address,uint256)", // The expected recipient is either the offer recipient or // the caller, depending on the fuzz args. - context.fulfillArgs.shouldSpecifyRecipient - ? context.fulfillArgs.offerRecipient - : address(this), + expectedRecipient, // The stranger address gets passed into the recipient field // below, so it will be the actual recipient. strangerAddress,