Skip to content

tx simulate re-assembly: re-record auth and avoid double-counting the resource fee #2603

@mootz12

Description

@mootz12

What

assemble() (cmd/soroban-cli/src/assembled.rs) was written for the case of assembling a freshly built transaction with empty auth and a classic-only fee. When tx simulate is run on an envelope that is already assembled or partially authorized, two things go wrong:

  1. Recorded auth is dropped. assemble() only copies simulation.results[*].auth onto the operation when body.auth.is_empty(). With --auth-mode=root|non-root the RPC records fresh auth even when entries already exist, but the assembled output keeps the original entries and silently discards the recorded set.
  2. The resource fee is double-counted. assemble() computes the fee as raw.fee + min_resource_fee. If the incoming tx already carries SorobanTransactionData (ext V1) whose resource_fee is folded into raw.fee, re-assembling adds the simulated resource fee on top of one that is already there.

Both bugs surface on the same path — re-simulating an already-assembled/partially-authorized envelope, e.g. re-recording a partially authorized transaction to capture non-root sub-invocation auth.

Proposed Fix

  1. Auth replacement. Thread the requested auth mode into assemble(). When an explicit record mode (root / record_allow_nonroot) was used, replace body.auth with the simulation-recorded entries even if it is non-empty. For enforce / unset, keep the current is_empty()-only behavior so caller-provided auth is preserved.
  2. Fee protection. Before adding min_resource_fee, subtract any resource fee already present in the incoming transaction. Mirror the JS SDK guard: if raw.ext is TransactionExt::V1(data), and raw.fee - data.resource_fee > 0, subtract data.resource_fee from the classic fee first. See js-stellar-sdk assembleTransaction (src/rpc/transaction.ts).

Acceptance criteria

  • tx simulate --auth-mode=root|non-root on an envelope that already contains auth entries emits XDR containing the newly recorded authorization entries.
  • tx simulate on an already-assembled Soroban envelope (ext V1 with a resource fee) does not inflate the resource fee.
  • enforce / unset still preserve caller-provided auth.
  • invoke / deploy / upload behavior is unchanged.
  • Tests: re-record a pre-populated envelope through tx simulate (assert recorded auth present); re-simulate an assembled envelope (assert the fee is not double-counted).

References

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    Status
    Backlog (Not Ready)

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions