Correct the ZIP 317 transaction fee calculator - #763
Open
DanielDerefaka wants to merge 1 commit into
Open
Conversation
The builder used a base fee of 10,000 zats plus 10,000 per extra action, and counted logical actions by adding up every component the transaction touched. Neither matches ZIP 317, so a shielded send was quoted at 0.0002 ZEC while the Output Description stage of the same visualizer shows the real 0.0001 ZEC. Move the calculation into src/lib/zip317.ts and follow the spec: conventional_fee = marginal_fee * max(grace_actions, logical_actions) with marginal_fee 5,000 zats and grace_actions 2. Logical actions are now one contribution per pool, so transparent inputs and outputs are measured in bytes against the standard P2PKH sizes, Sapling spends pair with outputs, and Orchard and Ironwood Actions count directly. The builder's fee panel also shows the formula it just applied and the actions each pool contributed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes the ZIP 317 fee calculation in the Build a Shielded Transaction visualizer.
The bug
calculateZip317FeeinBuildShieldedTransactionContent.tsxwas:Three things are off against ZIP 317:
marginal_feeis 5,000 zats, not 10,000.marginal_fee × max(grace_actions, logical_actions)withgrace_actions = 2, not a base plus a per extra action charge.The visible symptom: an Orchard to Orchard send was quoted at 0.0002 ZEC, while the Output Description stage of the same visualizer already shows the correct 0.0001 ZEC on the change note.
The fix
Moved the calculation into
src/lib/zip317.ts, following the spec directly:Logical actions are now built one contribution per pool, with the ZIP's own field names so the code can be read next to the spec:
max(ceil(tx_in_total_size / 150), ceil(tx_out_total_size / 34))2 × nJoinSplitmax(nSpendsSapling, nOutputsSapling)nActionsOrchardnActionsIronwood(revision 1)simpleTransfer(from, to)builds the shape the visualizer actually models: one note or UTXO spent in the sender's pool, the recipient paid in the target pool, change back to the sender. Every pool pair comes out at 2 logical actions, so the builder now quotes 0.0001 ZEC across the board, which is what a wallet charges for a simple send and is the point ZIP 317 is making.The fee panel also shows the formula it just applied, e.g.
so the number is no longer unexplained.
Testing
src/lib/__tests__/zip317.test.ts, 21 cases covering the spec parameters, each pool contribution, the grace floor, byte rounding, and all nine pool pairs. These live undersrc/libso the existinglib-testsjob runs them.yarn jest src/libpasses, 6 suites / 57 tests.yarn buildclean,tsc --noEmitclean, no new eslint findings.yarn build && yarn startand checked the fee, the action count and the breakdown line each time.