Replay a deployed contract's real QIE history against your new bytecode and see what changes.

Upgrade regression

npx shadowfork regress 0x3f43da82ec9a4f5285f10faf1f26eca7319e5da5 artifacts/QUSDC.json --limit 25 --fail

How it works

  1. History: the contract's recent transactions from the QIE explorer's txlist, plus every transaction that emitted one of its logs (internal calls, such as a router pulling tokens).
  2. For each transaction, the pre-state is loaded once.
  3. The transaction runs twice from that identical state: with the deployed code, and with the candidate's runtime bytecode installed at the same address. For an EIP-1967 proxy, the candidate replaces the implementation.
  4. The baseline run is compared with what happened on chain (status and logs). A baseline that does not match is excluded, so simulator error never becomes a verdict.
  5. The two runs are compared: status, return data, every event, every storage write and balance change. Fee flows to the sender and the block's coinbase are excluded.

Verdicts

Verdict Meaning
identical Same behaviour and same gas
gas only Same behaviour, different gas
needs more gas Fails at its original gas limit, behaves the same with more. Wallets size limits from eth_estimateGas against the old code, and the 63/64 call-gas rule narrows the margin
behaviour changed Return data, events or storage differ
now reverts, now succeeds The status flipped
skipped The baseline did not match the chain

--fail exits with code 1 on any behaviour change, now reverts or now succeeds.

Example: QUSDC

QUSDC's verified source, recompiled with its verified settings (solc 0.8.20, Berlin, optimizer off), matches the deployed bytecode apart from metadata.

Candidate Result on recent history
The recompiled source every transaction identical
version() and mintBatch() added no behaviour change; some transactions need more gas than their original limit
transferFrom spending the allowance of to instead of the caller QIEDEX router swaps now revert with TransferHelper::transferFrom: transferFrom failed; calls where the spender is the recipient are unaffected

The three candidates are in fixtures/qusdc/.

Storage layout check

npx shadowfork layout 0x3f43da82ec9a4f5285f10faf1f26eca7319e5da5 artifacts/QUSDCv2.json

The old layout comes from the deployed contract's verified source on the QIE explorer, recompiled with its exact compiler version and settings (or from an old artifact). The new one comes from the candidate's storageLayout output. Every existing variable must keep its slot, offset and type; new variables must come after the old ones.

Finding Severity
moved, retyped, removed, inserted critical: existing data would be read from the wrong place
renamed (same slot and type) warning
appended fine

A QUSDC build that only swaps its parents' order (AccessControl, ERC20) compiles, passes every unit test, and shifts every variable by one slot. regress runs this check first whenever the candidate artifact carries a storage layout.

Invariant fuzzing

npx shadowfork fuzz 0x3f43da82ec9a4f5285f10faf1f26eca7319e5da5 artifacts/QUSDCv2.json --seed 42

Real holders of the token (from its recent Transfer logs) and two fresh accounts run random, seeded sequences of transfer, approve and transferFrom on a fork, against the deployed code or the candidate. After every step:

Invariant Holds when
supply totalSupply never changes
conserved balances move by exactly the amount, and their sum is unchanged
liveness a move within balance and allowance succeeds; one beyond either reverts
allowance transferFrom spends exactly the amount from the spender's allowance
events every move emits Transfer with the exact from, to and amount
inherited the candidate reads the same supply and balances as the deployed code from the same state

The broken transferFrom candidate fails liveness; the reordered candidate fails inherited before a single transfer runs.