feat(module): verify Tron structurally on the signing side too - #21
Conversation
The host moved to `verify_contract` in tinyhumansai/openhuman#5533, but the module — the side that actually holds the key and produces the signature — was still calling `verify_transfer`. That check searches for the recipient and the amount as byte runs anywhere in `raw_data`, so a node can pay someone else and leave the requested address in an unrelated field and still get signed. Both call sites now use `verify_contract`, which parses the protobuf and reads the fields that will execute. The new test builds exactly that transaction and asserts the precondition first: assert!( tx::tron::verify_transfer(&raw_data_hex, REQUESTED, &expected_txid, &transfer).is_ok(), "precondition: the byte-run search is fooled by the decoy" ); so it fails if the gap it guards ever stops existing, rather than passing vacuously. `build_unsigned` then refuses it with "does not pay the requested recipient". Checking it host-side is not enough. A host is precisely what a caller could be lying to, and the module's whole purpose is to be the boundary the key sits behind — which is also why the second call site, `attach_signature`, verifies again rather than trusting the first. `fee_limit_sun` is `None` because the wire spec does not carry it: only the host knows what it pinned in its `createtransaction` request, and it checks that before handing the spec over. Every other field is checked here. Co-authored-by: Medulla <medulla@tinyhumans.ai>
|
Warning Review limit reached
Next review available in: 61 minutes You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
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. Comment |
The gap
#18 added
verify_contractand openhuman moved to it. The module did not — and the module is the side that holds the key and produces the signature.Both of its call sites still ran
verify_transfer, which searches for the recipient and amount as byte runs anywhere inraw_data. A node can pay someone else and leave the requested address in an unrelated field; the search is satisfied, and the module signs it.The test states the precondition first
The fixture builds a real
TransferContractpayingATTACKERfor the requested amount, with the requested address appended as field 99 — a decoy. Asserting the precondition means this test fails loudly if the gap it guards ever stops existing, rather than passing vacuously onceverify_transferchanges again.Why host-side checking was not enough
A host is precisely what a caller could be lying to. The module exists to be the boundary the key sits behind, so the check that decides whether a signature is produced belongs on this side of it. That is the same reasoning behind
attach_signatureverifying a second time rather than trusting thebuild_unsignedcall — the two requests are independent, and a host could reach the second with different bytes than the digest was computed over.fee_limit_sunisNone, deliberatelyThe wire spec does not carry it. Only the host knows what it pinned in its
createtransactionrequest, and it checks that before handing the spec over. Every other field — contract type, recipient at its declared field number, amount, TRC-20 calldata including the selector,call_value— is checked here.Adding it to
wire::TransactionSpec::Tronwould be the more complete answer, but it is a wire-contract change requiring host and module to move together; worth doing separately if we want it.Verification
cargo test --all-featurescargo clippy --all-features --all-targetscargo fmtWhy now
This wants to land before the next module artifact is cut, so the release that openhuman downloads has the check in it. The registry entry in
openhuman/src/openhuman/modules/registry.rspins0.2.1by SHA-256 today; a0.2.2release built from this would be the version that entry moves to.