Skip to content

chore(contracts): foundry scaffold with OZ v5.1 and CI pipeline - #634

Merged
alpergundogdu merged 2 commits into
mainfrom
chore/contracts-foundry-scaffold
May 21, 2026
Merged

alpergundogdu merged 2 commits into
mainfrom
chore/contracts-foundry-scaffold

Conversation

@alpergundogdu

Copy link
Copy Markdown
Contributor

Summary

First step of #452 — lays the Foundry toolchain under contracts/ so the 14-contract surface can land one PR at a time against a working build + fmt + test pipeline. No deCDN contract logic ships in this PR.

  • Foundry project at contracts/, solc 0.8.28, evm cancun
  • 4 profiles in foundry.toml: default (fast local), ci (1024 fuzz / 256-depth invariants), fuzz (10k runs for nightly), coverage (optimizer off for accurate source mapping)
  • [email protected] + [email protected] as git submodules; SHAs pinned in foundry.lock
  • @openzeppelin/contracts/ + forge-std/ remappings in remappings.txt
  • test/Sanity.t.sol confirms the toolchain wires through (forge-std loads, OZ remap resolves to the canonical IERC20.transfer selector); it will be deleted once the first real contract from Implement unified deCDN contract surface for audit (full 14-contract scope) #452 lands

CI integration

Extended the existing .github/workflows/ci.yml rather than forking a new workflow — keeps the single ci-success alls-green gate authoritative across rust + adr + solidity.

  • New solidity filter on the changes job (triggers on contracts/**, .gitmodules, the workflow file itself)
  • New solidity job: checkout with submodules: recursive, installs foundry-rs/foundry-toolchain@v1 stable, runs forge fmt --check → forge build --sizes → forge test, all under FOUNDRY_PROFILE=ci
  • Added to ci-success.needs and allowed-skips so doc-only PRs (no contracts/** changes) skip cleanly

Pinning rationale

Choice Why
solc 0.8.28 OZ v5.1 needs ^0.8.20; pinning to one stable so audit diffs don't move across machines
evm_version = "cancun" Arbitrum Sepolia + Arbitrum One both support it; gives access to tstore / mcopy if a contract wants them
optimizer_runs = 200 Standard default; tune per-contract later when sizes start mattering
OZ v5.1.0 (not 5.x latest) Pinned for audit-diff stability; bump deliberately
forge-std v1.16.1 Whatever forge init pulled — safe default

Out of scope (acceptance criteria from #452 deferred to follow-up PRs)

These belong with the contracts they apply to, not the scaffold:

  • Slither config + CI job — nothing to scan yet
  • forge coverage threshold gate — nothing to measure yet
  • ABI snapshot tests — no public interfaces yet
  • forge script deploy template — no contracts to deploy yet

Test plan

  • forge fmt --check clean locally
  • FOUNDRY_PROFILE=ci forge build --sizes clean from a forge clean state
  • FOUNDRY_PROFILE=ci forge test — 2/2 sanity tests pass
  • CI solidity job green
  • CI ci-success aggregator green (existing rust/adr/markdown jobs untouched)

Refs: #452

Lays the Foundry project structure under contracts/ for the unified
14-contract surface from #452. No deCDN contract logic ships yet —
this is the audit-ready toolchain only.

- Foundry project at contracts/, solc 0.8.28, evm cancun
- 4 profiles: default (fast local), ci (1024 fuzz / 256-depth
  invariants), fuzz (10k runs nightly), coverage (optimizer off)
- forge-std v1.16.1 + openzeppelin-contracts v5.1.0 as submodules,
  SHAs pinned in foundry.lock
- @openzeppelin/contracts/ and forge-std/ remappings
- SanityTest verifies the toolchain wires through correctly; will
  be deleted once the first real contract from #452 lands
- ci.yml extended with a `solidity` paths-filter and a solidity job
  running fmt --check / build --sizes / test under FOUNDRY_PROFILE=ci,
  gated by ci-success alls-green like the existing rust/adr jobs

Deferred to follow-up PRs (acceptance criteria from #452 that belong
with the contracts they apply to): Slither config, forge coverage
gate, ABI snapshot tests, forge script deploy template.

Refs: #452

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request initializes the Foundry development environment by adding submodules for forge-std and OpenZeppelin contracts, configuring the foundry.toml file, and establishing import remappings. A sanity test is also included to verify the setup. Feedback focuses on improving the .gitignore by excluding the entire broadcast directory to prevent repository bloat and reducing the max_test_rejects value in the fuzzing profile to ensure more efficient test execution.

Comment thread .gitignore Outdated
Comment on lines +18 to +19
/contracts/broadcast/*/[0-9]*/
/contracts/broadcast/**/dry-run/

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The current patterns for ignoring broadcast artifacts are unnecessarily complex and may still allow some metadata or summary files to be accidentally tracked. It is safer and more standard to ignore the entire broadcast/ directory to prevent repository bloat and accidental tracking of sensitive deployment metadata.

/contracts/broadcast/

Comment thread contracts/foundry.toml Outdated
verbosity = 3

[profile.fuzz]
fuzz = { runs = 10_000, max_test_rejects = 1_000_000 }

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

A max_test_rejects value of 1,000,000 is excessively high. If a fuzz test is rejecting that many inputs, it indicates a significant efficiency issue in the test's constraints (e.g., over-reliance on vm.assume). This can lead to extremely long CI runtimes. It is better to use vm.bound or more specific input types to ensure the fuzzer generates valid inputs efficiently.

Suggested change
fuzz = { runs = 10_000, max_test_rejects = 1_000_000 }
fuzz = { runs = 10_000, max_test_rejects = 65536 }

@github-actions

github-actions Bot commented May 21, 2026 •

Copy link
Copy Markdown

Coverage report

Total: 89.95% (was 89.96%, ▼ 0.01%) — 16723/18591 lines

No Rust files changed in this PR.

History
Commit Total Δ vs base
9142baa 89.95% ▼ 0.01%
645ea44 (HEAD) 89.95% ▼ 0.01%

…e + cap max_test_rejects

- .gitignore: replace per-pattern broadcast/ rules with the whole dir.
  Foundry's default `broadcast/*/[0-9]*/` + `broadcast/**/dry-run/`
  pattern leaves run-latest.json + tx metadata tracked, which can leak
  RPC URLs and gas estimates. We don't need the deployment-history
  trail in-repo (tagged releases + deployment docs cover that).

- foundry.toml [profile.fuzz]: cap max_test_rejects at foundry's default
  (65_536) instead of 1_000_000. A test hitting the ceiling signals
  over-constrained inputs (typically vm.assume overuse); the right
  fix is vm.bound / tighter input types, not raising the limit.
  Comment added to flag this for the next contributor.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@alpergundogdu
alpergundogdu merged commit bb3f920 into main May 21, 2026
12 checks passed
@alpergundogdu
alpergundogdu deleted the chore/contracts-foundry-scaffold branch May 21, 2026 15:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant