Skip to content

test(contracts): add bridge adapter invariant fuzz tests#47

Merged
iap merged 1 commit into
devfrom
test/bridge-invariants
May 8, 2026
Merged

test(contracts): add bridge adapter invariant fuzz tests#47
iap merged 1 commit into
devfrom
test/bridge-invariants

Conversation

@iap
Copy link
Copy Markdown
Contributor

@iap iap commented May 8, 2026

Summary

Adds invariant fuzz tests for MARKBridgeAdapter rate limiting logic. The settlement module already has a full invariant suite; this closes the gap for the bridge.

Tests added

contracts/test/invariant/bridge/MARKBridgeInvariants.t.sol

  • invariant_dailyCapNeverExceeded: accumulator never exceeds dailyCap within the current epoch
  • invariant_accumulatorConsistentWithCap: accumulator never exceeds cap regardless of limit resets or epoch changes
  • invariant_operatorRoleNeverZeroAddress: zero address never holds OPERATOR_ROLE

Handler fuzzes: bridge calls, time advancement (up to 3 days), and limit updates.

Verification

forge test: 74 tests passed, 0 failed (up from 71)

Scope

  • contracts

Risk

None — test-only addition.

Summary by CodeRabbit

  • Tests
    • Added invariant test suite for bridge adapter operations with fuzzing of token transfer scenarios and validation of transaction limits, daily cap constraints, and role assignments.

Three invariants covering MARKBridgeAdapter rate limiting logic:
- dailyCapNeverExceeded: bridgedInDailyCapEpoch <= dailyCap within epoch
- accumulatorConsistentWithCap: accumulator never exceeds cap regardless
  of limit resets or epoch changes
- operatorRoleNeverZeroAddress: zero address never holds OPERATOR_ROLE

Handler exercises bridge calls, time advancement, and limit updates
across 64 fuzz runs. Fuzzer identified and confirmed epoch-0 edge case
(bridge call at timestamp < 1 day sets epoch=0 with non-zero accumulator)
is handled correctly by the contract.
@iap iap requested a review from a team as a code owner May 8, 2026 11:56
@chatgpt-codex-connector
Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 8, 2026

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

Scanned Files

None

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 8, 2026

Review Change Stack
No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: a9eaa193-cf17-4569-a3ec-86fd87619f15

📥 Commits

Reviewing files that changed from the base of the PR and between d3ea0f5 and 01917e0.

📒 Files selected for processing (1)
  • contracts/test/invariant/bridge/MARKBridgeInvariants.t.sol

Walkthrough

This PR introduces a Foundry invariant test suite for MARKBridgeAdapter. The test defines a handler that fuzzes bridge operations with bounded amounts and daily-cap enforcement, exercises time advancement and limit updates, and validates three invariants: the daily cap is never exceeded within an epoch, the accumulator remains consistent, and the operator role is never zero.

Changes

Bridge Invariant Test Suite

Layer / File(s) Summary
Fuzz Handler
contracts/test/invariant/bridge/MARKBridgeInvariants.t.sol
MARKBridgeHandler bounds fuzz input by adapter limits, skips actions exceeding the daily cap, mints tokens to the operator, mocks the external sendERC20 call with a nonce, invokes adapter.bridgeTo, and exposes actions to warp time and update bridge limits as owner.
Invariant Test Setup
contracts/test/invariant/bridge/MARKBridgeInvariants.t.sol
MARKBridgeInvariants.setUp() deploys RYLA token and MARKBridgeAdapter, sets operator and destination, initializes bridge limits, approves the adapter, constructs the handler, and registers fuzz targets over its selectors.
Invariant Assertions
contracts/test/invariant/bridge/MARKBridgeInvariants.t.sol
Three invariants assert that bridgedInDailyCapEpoch never exceeds dailyCap for the current epoch, the accumulator remains within dailyCap, and the OPERATOR_ROLE is never held by the zero address.

Estimated Code Review Effort

🎯 1 (Trivial) | ⏱️ ~5 minutes

Possibly Related PRs

  • trade/mark#46: Both PRs add tests targeting MARKBridgeAdapter's bridgeTo behavior and daily-cap enforcement (one integration against a live supersim predeploy, the other invariant/fuzz tests mocking the predeploy).
  • trade/mark#26: Both PRs touch the MARK bridge adapter's daily-cap and epoch accumulator behavior (one adds invariant fuzz tests; the other adds a unit test checking mid-epoch accumulator reset).
  • trade/mark#24: Both PRs touch the MARK bridge flow and Superchain sendERC20 interactions (the main PR adds invariant tests that mock sendERC20 behavior while the retrieved PR changes bridgeTo to try/catch and add BridgeFailed handling).

Poem

🐰 A fuzzer hops through bridge limits,
Mocking sends with nonce commits,
Time warps forth, caps never break,
Invariants stand for the bridge's sake!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the main change: adding invariant fuzz tests for the bridge adapter.
Description check ✅ Passed The description covers all required sections from the template: summary, scope, verification, and risk assessment. It is well-structured and complete.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch test/bridge-invariants

Comment @coderabbitai help to get the list of available commands and usage tips.

@iap iap merged commit bd423c0 into dev May 8, 2026
19 checks passed
@iap iap deleted the test/bridge-invariants branch May 8, 2026 12:00
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