Skip to content

feat(module): verify Tron structurally on the signing side too - #21

Merged
senamakel merged 1 commit into
mainfrom
feat/module-structural-verify
Aug 13, 2026
Merged

feat(module): verify Tron structurally on the signing side too#21
senamakel merged 1 commit into
mainfrom
feat/module-structural-verify

Conversation

@senamakel

Copy link
Copy Markdown
Member

The gap

#18 added verify_contract and 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 in raw_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 old check would have passed this.
assert!(
    tx::tron::verify_transfer(&raw_data_hex, REQUESTED, &expected_txid, &transfer).is_ok(),
    "precondition: the byte-run search is fooled by the decoy"
);

let error = build_unsigned(&SigningRequest { /* TransferContract pays ATTACKER */ }).unwrap_err();
assert!(rendered.contains("does not pay the requested recipient"), "{rendered}");

The fixture builds a real TransferContract paying ATTACKER for 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 once verify_transfer changes 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_signature verifying a second time rather than trusting the build_unsigned call — the two requests are independent, and a host could reach the second with different bytes than the digest was computed over.

fee_limit_sun is None, deliberately

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 — 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::Tron would 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

Check Result
cargo test --all-features 299 + 7 + 10 + 18 doctests, 0 failed (module tests 9 → 10)
cargo clippy --all-features --all-targets clean
cargo fmt clean

Why 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.rs pins 0.2.1 by SHA-256 today; a 0.2.2 release built from this would be the version that entry moves to.

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>
@coderabbitai

coderabbitai Bot commented Aug 13, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@senamakel, you've reached your PR review limit, so we couldn't start this review.

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 @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: a4747e15-2917-4a34-92b7-b3193f2bd999

📥 Commits

Reviewing files that changed from the base of the PR and between b128082 and 60c6c0d.

📒 Files selected for processing (2)
  • crates/tinywallet-module/src/service/mod.rs
  • crates/tinywallet-module/src/service/test.rs

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.

@senamakel
senamakel merged commit 105aa6b into main Aug 13, 2026
11 checks passed
@senamakel
senamakel deleted the feat/module-structural-verify branch August 13, 2026 17:38
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