Skip to content

Conversation

@nicolasLuduena
Copy link

@nicolasLuduena nicolasLuduena commented Dec 5, 2025

This pull request updates the handling of coin and integer values throughout the pallas-utxorpc crate to consistently use the BigInt type from the utxorpc spec, improving compatibility and correctness for large values. It introduces helper functions to convert u64 and i64 values to BigInt, and refactors multiple mapping methods to apply these conversions. Additionally, it updates the utxorpc spec dependency to the latest version.

Dependency update:

  • Updated the utxorpc-spec dependency in Cargo.toml from version 0.17.0 to 0.18.1 to ensure compatibility with the latest protocol changes.

Helper functions and code consistency:

  • Added u64_to_bigint and i64_to_bigint helper functions in src/lib.rs and used them throughout the codebase for converting coin and integer fields to the BigInt type.

Refactoring of certificate and protocol parameter mapping:

  • Refactored certificate mapping in src/certs.rs to use BigInt for pledge, cost, coin, and delta_coin fields, ensuring all relevant fields are properly converted.
  • Refactored protocol parameter mapping in src/params.rs to convert all coin and deposit-related fields to BigInt, including fee coefficients, deposits, pool costs, and governance deposits.

Transaction and asset mapping improvements:

  • Updated transaction output, withdrawal, asset, and governance proposal mapping methods in src/lib.rs to use the new helper functions for converting coin and quantity fields to BigInt, and refactored asset quantity representation for better clarity and correctness.

Summary by CodeRabbit

  • Chores

    • Updated a core dependency to version 0.18.1.
  • Refactor

    • Numeric fields (coins, fees, deposits, quantities) now use bigint-based representations for consistent precision across transactions and protocol parameters.
  • Chores / Data

    • Test/fixture transaction data updated: numeric values are now encoded as int-wrapped objects instead of plain strings, aligning serialized data with bigint handling.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link

coderabbitai bot commented Dec 5, 2025

Walkthrough

This PR converts many numeric fields to BigInt representations across pallas-utxorpc: updates utxorpc-spec to 0.18.1, adds helpers (u64_to_bigint, i64_to_bigint), and wraps numeric coins/amounts in certs, params, lib mappings; test JSON updated to use { "int": "<value>" } objects for numeric fields.

Changes

Cohort / File(s) Summary
Dependency Update
pallas-utxorpc/Cargo.toml
Bumped utxorpc-spec dependency from 0.17.0 to 0.18.1.
Core helpers & mapping updates
pallas-utxorpc/src/lib.rs
Added u64_to_bigint and i64_to_bigint helpers; changed mappings to emit BigInt-wrapped numeric fields (tx outputs, withdrawals, fees, total_collateral, gov deposits, asset quantity computation).
Certificate numeric conversions
pallas-utxorpc/src/certs.rs
Replaced raw numeric dereferences with u64_to_bigint/i64_to_bigint for certificate fields (pledge, cost, delta_coin, coin, etc.) across Alonzo and Conway certificate mappings.
Protocol parameters conversions
pallas-utxorpc/src/params.rs
Wrapped protocol parameter numeric fields (minfee_a, minfee_b, ada_per_utxo_byte, key_deposit, pool_deposit, min_pool_cost, governance_action_deposit, drep_deposit, etc.) with u64_to_bigint across era branches and update paths.
Test fixture updates
test_data/u5c1.json
Updated serialized numeric fields from plain strings to objects with an int property (e.g., "coin": "123""coin": { "int": "123" }) for coin, fee, totalCollateral, outputCoin, and related fields.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

  • Broad, heterogeneous changes touching core mapping logic and test data; verify consistency of Option handling and downstream consumers.
  • Pay special attention to:
    • pallas-utxorpc/src/params.rs — many era-specific branches and nested updates.
    • pallas-utxorpc/src/certs.rs — multiple certificate variants and match arms.
    • pallas-utxorpc/src/lib.rs — helper semantics and all call sites (Some vs None handling).
    • test_data/u5c1.json — ensure test fixtures match the new serialized BigInt shape expected by parsers.

Suggested reviewers

  • scarmuega

Poem

🐇 I hopped through code and wrapped each coin,

ints tucked safely where they’ll shine,
pledge and fee now wear BigInt fine,
tests remade to match the line,
a tiny hop — and all aligns.

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title 'Bump utxorpc version to 0.18.1' accurately describes the primary change in the changeset. The dependency version bump is the main trigger for the PR, and while extensive refactoring work follows to adapt to the new BigInt type from the updated spec, the title captures the essential entry point.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5fc4b14 and 042c47c.

📒 Files selected for processing (2)
  • pallas-utxorpc/src/lib.rs (6 hunks)
  • pallas-utxorpc/src/params.rs (8 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
pallas-utxorpc/src/params.rs (1)
pallas-utxorpc/src/lib.rs (2)
  • rational_number_to_u5c (26-31)
  • u64_to_bigint (33-45)
🔇 Additional comments (5)
pallas-utxorpc/src/lib.rs (3)

33-51: Excellent fix for the truncation issue.

The u64_to_bigint helper now correctly handles values exceeding i64::MAX by using the BigUInt variant, addressing the overflow concern from previous reviews. The i64_to_bigint helper is straightforward and correct for signed integers.

Based on learnings, this implementation resolves the previously identified truncation risk.


285-297: Asset quantity mapping correctly refactored.

The quantity field now correctly uses u64_to_bigint for output_coin (unsigned) and i64_to_bigint for mint_coin (signed), eliminating the truncation risk identified in previous reviews.

Based on learnings, this addresses the previously flagged truncation issue in asset mapping.


216-216: LGTM: Consistent BigInt conversions throughout.

All coin, fee, deposit, and collateral conversions correctly use u64_to_bigint, ensuring uniform BigInt representation across transaction outputs, withdrawals, governance proposals, and fee structures.

Also applies to: 278-278, 487-487, 552-552, 716-716, 719-719

pallas-utxorpc/src/params.rs (2)

5-5: LGTM: Import and consistent usage.

The u64_to_bigint helper is correctly imported and consistently applied across all protocol parameter mappings for all eras (Alonzo, Shelley, Babbage, Conway).


28-37: Correct handling of required and optional numeric fields.

Protocol parameter conversions properly distinguish between:

  • Required fields using direct u64_to_bigint calls
  • Optional fields using .and_then(u64_to_bigint) for proper Option chaining

All fee coefficients, deposits, and pool costs are now consistently represented as BigInt across all eras.

Also applies to: 69-77, 88-97, 137-146, 197-198, 223-236, 297-298


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

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

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: 3

🧹 Nitpick comments (2)
pallas-utxorpc/src/params.rs (2)

223-236: Consider simplifying the optional BigInt conversion pattern.

The pattern .map(|v| u64_to_bigint(v)).flatten() is functionally correct but can be simplified using .and_then(u64_to_bigint) for better readability.

-            coins_per_utxo_byte: x.ada_per_utxo_byte.map(|v| u64_to_bigint(v)).flatten(),
+            coins_per_utxo_byte: x.ada_per_utxo_byte.and_then(u64_to_bigint),
             max_tx_size: x.max_transaction_size.unwrap_or_default(),
-            min_fee_coefficient: x.minfee_a.map(|v| u64_to_bigint(v.into())).flatten(),
-            min_fee_constant: x.minfee_b.map(|v| u64_to_bigint(v.into())).flatten(),
+            min_fee_coefficient: x.minfee_a.map(|v| v.into()).and_then(u64_to_bigint),
+            min_fee_constant: x.minfee_b.map(|v| v.into()).and_then(u64_to_bigint),
             max_block_body_size: x.max_block_body_size.unwrap_or_default(),
             max_block_header_size: x.max_block_header_size.unwrap_or_default(),
-            stake_key_deposit: x.key_deposit.map(|v| u64_to_bigint(v)).flatten(),
-            pool_deposit: x.pool_deposit.map(|v| u64_to_bigint(v)).flatten(),
+            stake_key_deposit: x.key_deposit.and_then(u64_to_bigint),
+            pool_deposit: x.pool_deposit.and_then(u64_to_bigint),
             pool_retirement_epoch_bound: x.maximum_epoch.unwrap_or_default(),
             desired_number_of_pools: x.desired_number_of_stake_pools.unwrap_or_default(),
             pool_influence: x.pool_pledge_influence.clone().map(rational_number_to_u5c),
             monetary_expansion: x.expansion_rate.clone().map(rational_number_to_u5c),
             treasury_expansion: x.treasury_growth_rate.clone().map(rational_number_to_u5c),
-            min_pool_cost: x.min_pool_cost.map(|v| u64_to_bigint(v)).flatten(),
+            min_pool_cost: x.min_pool_cost.and_then(u64_to_bigint),

297-301: Same simplification applies here.

-            governance_action_deposit: x
-                .governance_action_deposit
-                .map(|v| u64_to_bigint(v))
-                .flatten(),
-            drep_deposit: x.drep_deposit.map(|v| u64_to_bigint(v)).flatten(),
+            governance_action_deposit: x.governance_action_deposit.and_then(u64_to_bigint),
+            drep_deposit: x.drep_deposit.and_then(u64_to_bigint),
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2aba7ff and 5fc4b14.

📒 Files selected for processing (5)
  • pallas-utxorpc/Cargo.toml (1 hunks)
  • pallas-utxorpc/src/certs.rs (8 hunks)
  • pallas-utxorpc/src/lib.rs (6 hunks)
  • pallas-utxorpc/src/params.rs (8 hunks)
  • test_data/u5c1.json (37 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
pallas-utxorpc/src/certs.rs (2)
pallas-utxorpc/src/lib.rs (2)
  • i64_to_bigint (39-43)
  • u64_to_bigint (33-37)
pallas-traverse/src/value.rs (1)
  • coin (67-79)
pallas-utxorpc/src/params.rs (1)
pallas-utxorpc/src/lib.rs (2)
  • rational_number_to_u5c (26-31)
  • u64_to_bigint (33-37)
🔇 Additional comments (8)
test_data/u5c1.json (1)

1-3235: Test data properly updated to match BigInt schema.

The numeric coin and fee fields have been consistently transformed from plain strings to nested objects with an "int" property throughout the test data. All values are preserved correctly, and the transformation aligns with the PR's shift to BigInt representations across the codebase.

pallas-utxorpc/src/certs.rs (1)

5-5: LGTM!

The import of i64_to_bigint and u64_to_bigint helpers is correct, and the conversions throughout this file are applied consistently to all certificate types. The use of i64_to_bigint for delta_coin (Line 83) is appropriate since that field can be negative, while u64_to_bigint is correctly used for unsigned coin/pledge/cost fields.

pallas-utxorpc/src/lib.rs (6)

39-43: LGTM!

The i64_to_bigint function is straightforward and correct since the input is already i64.


208-208: LGTM!

Correct usage of u64_to_bigint for coin value conversion.


270-270: LGTM!

Correct usage of u64_to_bigint for withdrawal coin.


483-483: LGTM!

Correct usage of u64_to_bigint for treasury withdrawal coin.


548-548: LGTM!

Correct usage of u64_to_bigint for governance proposal deposit.


712-715: LGTM!

Correct usage of u64_to_bigint for total_collateral and fee fields.

[dependencies]
# utxorpc-spec = { path = "../../../utxorpc/spec/gen/rust" }
utxorpc-spec = { version = "0.17.0" }
utxorpc-spec = { version = "0.18.1" }
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

🌐 Web query:

utxorpc-spec 0.18.1 crates.io availability

💡 Result:

I couldn't find a published crates.io version 0.18.1 for utxorpc-spec. docs.rs shows the utxorpc_spec crates exist, and Libraries.io lists up to 0.17.0; the crates.io crate page for "utxorpc-spec" loads but does not show a 0.18.1 release in the searchable metadata I could access. [1][2][3]

Sources:

  • docs.rs (utxorpc_spec crates). [1]
  • Libraries.io (utxorpc-spec, shows 0.17.0). [2]
  • crates.io crate page (utxorpc-spec). [3]

If you want, I can (a) re-check crates.io directly for a 0.18.1 release and fetch the exact version listing, or (b) check the uxtorpc GitHub/releases for a 0.18.1 tag — which would you prefer?


🌐 Web query:

utxorpc-spec security advisories CVE

💡 Result:

I found no public CVE entries or security advisories specifically for the utxorpc-spec package or the UTxORPC ecosystem. Sources checked: PyPI package page (release history), Safety DB package entry, and crate/docs pages for utxorpc-spec. [1][2][3]

If you want, I can:

  • run a targeted NVD/CVE, GitHub advisory, and vendor-search now and report back with links and dates; or
  • monitor these sources and email/notify you on new advisories.

Sources:
[1] PyPI — utxorpc-spec (release/history).
[2] Safety DB — utxorpc package vulnerability summary.
[3] docs.rs / crate docs — utxorpc-spec.


Correct utxorpc-spec version; 0.18.1 does not exist on crates.io.

The specified version 0.18.1 is not published on crates.io. The latest available version is 0.17.0. Update the dependency to an available version.

🤖 Prompt for AI Agents
In pallas-utxorpc/Cargo.toml at line 15, the dependency utxorpc-spec is pinned
to version "0.18.1" which does not exist on crates.io; change it to a published
version (e.g., "0.17.0") by updating the version string to an available release
so Cargo can resolve the dependency successfully.

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