Skip to content

Comments

chore: fix build and tests#118

Merged
Ugo-X merged 1 commit intomainfrom
chore-cleanups
Aug 25, 2025
Merged

chore: fix build and tests#118
Ugo-X merged 1 commit intomainfrom
chore-cleanups

Conversation

@JoE11-y
Copy link
Contributor

@JoE11-y JoE11-y commented Aug 25, 2025

Summary by CodeRabbit

  • New Features

    • Burn events now include a burn_id for clearer tracking and reconciliation.
    • The burn_xzb_for_unlock call now requires a burn_id parameter alongside amount.
  • Tests

    • Test suite updated to cover burn_id usage across single and multiple burn scenarios, with assertions reflecting the new event field.

@coderabbitai
Copy link

coderabbitai bot commented Aug 25, 2025

Walkthrough

Adds a burn_id: u256 parameter to burn_xzb_for_unlock and includes it in BurnEvent. Updates the L2 bridge contract, its public interface, and tests accordingly. Minor stylistic change in storage pop. Adjusts xZBERC20 test trait impl generics without changing behavior.

Changes

Cohort / File(s) Summary
L2 Bridge: event and method update
contracts/L2/src/core/ZeroXBridgeL2.cairo
Added burn_id: u256 to BurnEvent; extended burn_xzb_for_unlock(ref self, burn_id: u256, amount: u256); included burn_id in emitted event; minor style change when popping last_peaks.
Public interface sync
contracts/L2/src/interfaces/IZeroXBridgeL2.cairo
Updated IZeroXBridgeL2 burn_xzb_for_unlock signature to accept burn_id: u256 as first parameter.
ERC20 test trait impl tweak
contracts/L2/src/core/xZBERC20.cairo
Changed impl target from IxZbTest to IxZbTest; function body unchanged.
Tests alignment with new API/event
contracts/L2/tests/test_ZeroXBridgeL2.cairo
Updated calls to burn_xzb_for_unlock to pass burn_id; assertions expect BurnEvent { burn_id, user, amount, nonce, commitment_hash }.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor User
  participant Bridge as ZeroXBridgeL2
  participant Token as xZB ERC20
  participant Events as L2 Event Log

  User->>Bridge: burn_xzb_for_unlock(burn_id, amount)
  Bridge->>Token: burn(user, amount)
  Token-->>Bridge: Burn OK
  Note right of Bridge: Prepare BurnEvent payload<br/>including burn_id
  Bridge->>Events: Emit BurnEvent(burn_id, user, amount, nonce, commitment_hash)
  Events-->>User: Event recorded
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • L1 contracts #76 — Prior edits to ZeroXBridgeL2 burn structures/signatures; closely related to adding burn_id.
  • Update xZBERC20.cairo #116 — Changes around TestMint impl in xZBERC20; overlaps with this impl adjustment.

Suggested reviewers

  • Ugo-X

Poem

A hop, a skip, a burn_id bright,
I stamp my paw, events take flight.
Unlocks now tagged—no nibble lost,
Carrots counted, hashes tossed.
On L2 fields I drum with glee,
“Mint, burn, log!”—bun-led decree. 🥕🐇

Tip

🔌 Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.

✨ Finishing Touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch chore-cleanups

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@Ugo-X Ugo-X merged commit 38e9554 into main Aug 25, 2025
2 of 3 checks passed
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (5)
contracts/L2/src/core/ZeroXBridgeL2.cairo (3)

136-142: Adding burn_id to BurnEvent improves traceability

Good addition; it gives indexers and off-chain consumers a stable handle for burns. Consider marking burn_id as a keyed field to make it indexable in event logs.

Minimal diff:

-    pub struct BurnEvent {
-        pub burn_id: u256,
+    pub struct BurnEvent {
+        #[key]
+        pub burn_id: u256,

Note: this changes the event ABI (keys vs data). If you adopt it, verify any event parsing code/tests.


245-253: Tweak panic message for accuracy

The check is correct, but the message says “less than zero,” which can’t happen for u256. Make the message precise.

-            assert(burn_amount_usd > 0, 'Burn amount less than zero');
+            assert(burn_amount_usd > 0, 'Burn amount must be greater than zero');

250-252: Potential u256 overflow in mul/div sequence

(amount * PRECISION) / mint_rate can overflow u256 for large amounts before division. Same pattern exists in mint_and_claim_xzb ((usd_amount * mint_rate) / PRECISION). Not urgent for this PR, but worth addressing.

  • Prefer a mul_div-style helper that does 512-bit intermediate math (mul then exact division).
  • If that’s not available, guard inputs (assert amount <= MAX_SAFE) or refactor to reduce overflow risk with acceptable rounding trade-offs.
  • Document limits in interface comments if you rely on bounded ranges.
contracts/L2/src/interfaces/IZeroXBridgeL2.cairo (1)

18-19: Interface synced with implementation — LGTM

Signature now takes burn_id before amount and matches the core contract.

Add a short doc comment describing burn_id semantics (e.g., client-provided vs contract-generated, uniqueness expectations).

contracts/L2/tests/test_ZeroXBridgeL2.cairo (1)

547-552: Avoid repeated re-declarations of burn_id for readability

Rebinding burn_id five times is legal but a bit noisy. Consider using distinct identifiers (burn_id1..burn_id5) or an array and iterate.

Example approach:

-    let burn_id = 123124_u256;
+    let burn_id1 = 123124_u256;
...
-    let burn_id = 1223124_u256;
+    let burn_id2 = 1223124_u256;
# …and so on, or store in an array and loop.

Also applies to: 556-560, 564-568, 572-576, 580-584

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 186d6f3 and f4d5e33.

📒 Files selected for processing (4)
  • contracts/L2/src/core/ZeroXBridgeL2.cairo (4 hunks)
  • contracts/L2/src/core/xZBERC20.cairo (1 hunks)
  • contracts/L2/src/interfaces/IZeroXBridgeL2.cairo (1 hunks)
  • contracts/L2/tests/test_ZeroXBridgeL2.cairo (7 hunks)
🔇 Additional comments (6)
contracts/L2/src/core/xZBERC20.cairo (1)

97-102: Confirm generated trait signature for IxZbTest

Please manually verify that the trait generated by #[generate_trait] for your test interface matches the impl you’ve written:

  • Inspect the macro-expanded definition of IxZbTest (e.g., via your IDE’s Cairo stub file or by running the Cairo compiler with expansion output).
  • If the generated trait is declared as trait IxZbTest<ContractState> { … }, update your impl to:
    impl TestMint of IxZbTest<ContractState> {
        #[external(v0)]
        fn test_mint(ref self: ContractState, recipient: ContractAddress, amount: u256) {
            self.erc20.mint(recipient, amount);
        }
    }
  • If the trait is non-generic (trait IxZbTest { … }), your current impl is correct.

Also consider isolating this test-only external method—either gate it behind a test feature flag or move it into a dedicated test helper module—to avoid exposing it in your production ABI.

contracts/L2/src/core/ZeroXBridgeL2.cairo (2)

281-287: Event emission now includes burn_id — LGTM

Emission payload aligns with the updated struct and interface. No concerns.


484-485: Storage pop style change — LGTM

Using let _ = …pop() silences the unused value warning and keeps intent clear.

contracts/L2/tests/test_ZeroXBridgeL2.cairo (3)

155-160: Expected BurnEvent updated correctly

Assertions include burn_id and preserve the original hash computation (without burn_id), which matches the contract’s commitment logic. Looks good.


627-631: Repeated burn_id inside loop — confirm intent

Using a constant burn_id = 1 for all 8 burns is fine since the contract doesn’t enforce uniqueness, but double-check this reflects intended semantics (some indexers may assume burn_id distinguishes burns).

If uniqueness is desired, compute burn_id from the loop counter.


133-137: All burn_xzb_for_unlock Call Sites Updated and Verified — Approving Changes

  • Verified every occurrence of .burn_xzb_for_unlock( in contracts/L2/tests/test_ZeroXBridgeL2.cairo (lines 133–137, 209–212, 244–249, 505–509, 550–552, 558–560, 566–568, 574–576, 582–584, 629–631) now uses (burn_id, burn_amount) in the correct order.
  • Confirmed the interface definition in contracts/L2/src/interfaces/IZeroXBridgeL2.cairo is updated to
    fn burn_xzb_for_unlock(ref self: TContractState, burn_id: u256, amount: core::integer::u256);
  • Confirmed the implementation in contracts/L2/src/core/ZeroXBridgeL2.cairo matches the new signature:
    fn burn_xzb_for_unlock(ref self: ContractState, burn_id: u256, amount: u256) { … }

LGTM – no further changes needed.

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.

2 participants