Skip to content

About

Sapper's pull request check for Foundry projects: every pull request's contracts attacked on a private fork before they ship.

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

23 Commits

Folders and files

Repository files navigation

Sapper preflight

Sapper attacks the contracts in every pull request before they ship.

The action builds your Foundry project and sends the compiled contracts to Sapper. Sapper deploys them from a fresh account on a private fork of its home chain (or another chain it watches, with chain-id), and its Breaker tries to break the rules you declare or move value to an outside account. A staked Checker replays anything it finds from scratch before your pull request hears about it.

The pull request gets one comment, edited in place on every run, and a check run. Both show the outcome and how many confirmed findings there are at each severity. Finding details never appear on GitHub: the report is sealed to your disclosure key and opens in the Sapper console.

Quick start

  1. In the Sapper console, open Settings and register your disclosure key. Reports are sealed to it, and a check does not start until it is registered.
  2. Open Pull requests and create a CI token. Add it to your repository as the Actions secret SAPPER_CI_TOKEN.
  3. Add sapper.json beside foundry.toml (see below).
  4. Add .github/workflows/sapper.yml:
name: Sapper
on: pull_request
permissions:
  contents: read
  checks: write
  pull-requests: write
jobs:
  preflight:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: sapper-agents/sapper-action@v0.2.0
        with:
          token: ${{ secrets.SAPPER_CI_TOKEN }}

A CI token runs on the monthly compute budget that comes with a contract Sapper watches for you. Without one, pay per run instead (see Paying per run).

To block merging on a confirmed finding at fail-on or above, add the workflow's job (preflight above) to the branch's required status checks. Require the job rather than the Sapper preflight check run: a pull request the action skips, such as one from a fork, gets a passing job and no check run (see What runs where).

sapper.json

{
  "contracts": [
    { "name": "RewardsVault", "args": ["5 ether"] }
  ],
  "setup": [
    { "to": "$RewardsVault", "fn": "initialize(address)", "args": ["$deployer"] },
    { "to": "$RewardsVault", "fn": "fund()", "value": "10 ether" }
  ],
  "rules": "sapper.rules.json"
}
Field Meaning
contracts Contracts to deploy, in order. name is the contract name in your build output; add path, the source file's full path such as src/v2/Vault.sol, when two files define the same name. args are constructor arguments; value is ETH sent to the constructor.
setup Calls the deployer makes after every contract exists, such as initialize or funding. Leave out fn to send plain ETH.
rules A rules file, or the rules inline. Same format as registering a contract in the console.
watchTokens Tokens whose balance Sapper also watches on the attacking account.
primary The name of the contract the report is about, one of contracts. Defaults to the first one.
chainId The chain the contracts deploy onto: Sapper's home chain by default, or another chain it watches. The chain-id input overrides it.
out Foundry's build directory, if it is not out.

$RewardsVault stands for that contract's address on the fork and $deployer for the fresh account that deployed it. Amounts may be written as 10 ether or 5 gwei anywhere a number goes, or as a whole number of wei.

Before anything is sent, the action checks sapper.json and its rules against your build, down to each fn and the arguments it takes, and names the file and field of every problem.

A rule compares two values, each a view call or a constant:

[
  {
    "id": "owner-fixed",
    "description": "The vault stays owned by the account that deployed it",
    "lhs": { "call": { "target": "$RewardsVault", "fn": "owner() view returns (address)" } },
    "op": "==",
    "rhs": { "const": "$deployer" },
    "severity": "Critical"
  }
]

op is one of ==, !=, >=, <=, >, <. Each rule reads a contract the check deploys, or $deployer, as its target or an argument, so the check tests the code in this pull request. With no rules, only value moved to the attacking account counts.

The example project holds a vault with a seeded bug, its sapper.json and its rules.

Inputs

Input Default
token CI token from the console.
payment-key Private key of a wallet that pays per run instead.
pay-with budget with a token, x402 with a key scan-time pays from the scan time of the workspace (token) or the wallet (key).
lane first one offered, other than sapr The lane a payment key pays on: base, elysium, sapr or home. $SAPR pays only when this is sapr.
max-price 25 The most the action pays for one run, in US dollars: above 0 and at most 1,000.
approve-permit2 false Send the one Permit2 approval a lane on Elysium needs, then pay.
rpc-url the chain's public RPC Endpoint for that approval. Pass it from a secret: a provider's URL usually carries your key.
chain-id Sapper's home chain The chain the contracts deploy onto: 4663 for Robinhood Chain, 99901 for Elysium. Another chain must be one Sapper watches.
disclosure-key the paying wallet's key The public key a paid run's report is sealed to: 43 base64url characters, without padding. It is an account's disclosure key, registered in the console under Settings. Left empty, the report opens for the paying wallet when it signs in to the console.
config sapper.json Path to the config inside working-directory.
working-directory . The Foundry project.
fail-on high Fail the job on a confirmed finding at this severity or higher: critical, high, medium, low or never, in any case.
comment true Post the pull request comment.
timeout-minutes 30 How long to wait for the result: a whole number of minutes from 1 to 360.
foundry-version stable Foundry version for forge build.
skip-build false Set when an earlier step already built the project.
api-url https://api.sapperagents.com Sapper's API.
github-token ${{ github.token }} Token for the check run and the comment. Needs checks: write and pull-requests: write. When it is empty, the run writes neither and warns.

The comment edited in place is the one the workflow's own token posted, as github-actions[bot]. With another github-token, a run edits that comment if the token is allowed to, and otherwise posts a new one.

approve-permit2, comment and skip-build take true or false, in any case. Anything else stops the run with an error naming the input.

With a CI token, disclosure-key, max-price, lane, rpc-url and approve-permit2 have no effect, and the run warns when any of them is set.

Outputs

result (passed, found, advisory or incomplete), report-url, critical and high. All four are empty when a run ends without a result, for example when Sapper refuses it or the action skips it.

advisory means Sapper found an attack path it could not replay on a fork, such as one that calls HyperCore, so nothing was confirmed. The advisory is sealed to your disclosure key.

incomplete means the check stopped before a result. When the action stops waiting at timeout-minutes, the check keeps running and its result appears in the console under Pull requests.

Both end with a neutral check run and a passing job, so read result if a later step should treat them as a failure.

When Sapper answers that too many checks are running or this month's compute budget is used up, the job fails at once and does not retry. Run it again later, or pay per run.

If the API at api-url does not offer pull request checks, nothing runs: the run posts a short note saying so, its check is neutral and the job passes.

Paying per run

      - uses: sapper-agents/sapper-action@v0.2.0
        with:
          payment-key: ${{ secrets.SAPPER_PAYMENT_KEY }}
          max-price: "25"

Each run pays Sapper's one-off price over x402, signed by that wallet. It pays on the lane lane names or, when lane is empty, on the first lane Sapper offers that the wallet can pay, other than sapr:

lane Pays with Signed as
elysium USDC on Elysium a Permit2 transfer, after the wallet approves Permit2 for the run's amount of USDC
sapr $SAPR on Elysium, at the quoted discount a Permit2 transfer, after the wallet approves Permit2 for the run's amount of $SAPR
base USDC on Base a transfer authorization
home the home chain's own lane, where its dollar token takes transfer authorizations a transfer authorization

max-price caps the price in US dollars. On the sapr lane the cap is checked against Sapper's own quote, so the amount of $SAPR the wallet signs follows that quote. Payment is taken only after your contracts deploy on the fork. Fund the wallet with what you expect to spend and nothing more.

When the wallet has not approved Permit2 for the run's amount, the run stops before anything is charged and prints the one transaction to send from the paying wallet: an approval of exactly that amount. approve-permit2: true sends it for you. The action never sends any other approval, unlimited ones included.

Unless disclosure-key names another key, the report is sealed to the paying wallet's disclosure key. Sign in to the console with that wallet to open it.

Paying with scan time

Holding $SAPR accrues scan time, and a pull request check can spend it. With a CI token, pay-with: scan-time spends the workspace's scan time. With a payment key, the wallet signs a one-time message for the run and its own scan time pays; no transfer is made.

      - uses: sapper-agents/sapper-action@v0.2.0
        with:
          payment-key: ${{ secrets.SAPPER_PAYMENT_KEY }}
          pay-with: scan-time

What runs where

The action only compiles. Your contracts execute on Sapper's private fork, never on the runner and never on a live network. The source and bytecode you send are held encrypted while the scan runs and deleted when it ends; a confirmed finding keeps its sealed reproduction.

Under pull_request, pull requests from forks and those Dependabot opens receive no Actions secrets. When no token or payment key reaches the action for one of them, it skips the pull request with a notice and the job passes.

A pass means the Breaker broke none of your rules on this fork within its step and compute limits. It does not replace an audit.

Development

The action runs dist/index.mjs, built from src/ with Bun and committed. Tests need Foundry to compile the example project.

bun install
bun test
bun run typecheck
bun run build   # then commit dist/index.mjs; CI fails when it is out of date

License

MIT. See LICENSE.

About

Sapper's pull request check for Foundry projects: every pull request's contracts attacked on a private fork before they ship.

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages