From af2e80c8db8ebf6cf7f9e2b086379c8f2be25851 Mon Sep 17 00:00:00 2001 From: Boog900 <54e72d8a-345f-4599-bd90-c6b9bc7d0ec5@aleeas.com> Date: Wed, 10 Jan 2024 23:22:36 +0000 Subject: [PATCH] add transaction weight calculations --- src/consensus_rules/transactions.md | 54 +++++++++++++++++++-- src/consensus_rules/transactions/ring_ct.md | 4 +- 2 files changed, 53 insertions(+), 5 deletions(-) diff --git a/src/consensus_rules/transactions.md b/src/consensus_rules/transactions.md index c8eb233..48ab075 100644 --- a/src/consensus_rules/transactions.md +++ b/src/consensus_rules/transactions.md @@ -6,10 +6,14 @@ This chapter does not include miner, coinbase, transactions as they are handled ## Index -1. [Rules That Apply To All Versions](./transactions.md#rules-that-apply-to-all-versions) -2. [Rules Specific to Version 1](./transactions/ring_signatures.md) +1. [Miscellaneous Rules](#miscellaneous-rules) +2. [Input Rules](./transactions/inputs.md) +3. [Output Rules](./transactions/outputs.md) +4. [Unlock Time](./transactions/unlock_time.md) +5. [Ring Signatures](./transactions/ring_signatures.md) +6. [RingCT](./transactions/ring_ct.md) -## Rules That Apply To All Versions +## Miscellaneous Rules ### Version @@ -27,6 +31,36 @@ The size of the `transaction blob` must not be bigger than 1 million bytes[^tx-s From v8 the transactions _weight_ must not be bigger than half of the [block penalty free zone](./blocks/weights.md#penalty-free-zone) minus 600[^tx-weight_limit]. +#### Calculating Transaction Weight + +For all transactions that don't use bulletproofs or bulletproofs+ the weight is just the length of the transaction blob.[^weight-pre-bp] + +For bulletproofs(+) transactions we add a "clawback" onto the transaction. + +To calculate the "clawback" we fist define a `bpBase` which is the size of a 2 output proof, normalized to 1 proof by dividing by 2[^bp-base]: + +for bulletproofs: \\(fields = 9\\) + +for bulletproofs+: \\(fields = 6\\) + +\\(bpBase = \frac{(32 * (fields + 7 * 2))}{2}\\) + +Next we calculate the size of the bulletproofs(+) field by first getting the first power of 2 above or equal to the number of outputs: `firstPower2AboveNumbOuts`. + +If `firstPower2AboveNumbOuts` is <= 2 then the \\(clawback = 0\\)[^fp2-less-than-2]. + +Next define the number of L and R elements[^lr-elements]: \\(nlr = firstPower2AboveNumbOuts + 6\\) + +now the size of the bulletproofs(+) field is[^bp+-size]: + +\\(bpSize = 32 * (fields + 2 * nlr)\\) + +now the `clawback` is[^clawback]: + +\\( clawback = \frac{(bpBase * firstPower2AboveNumbOuts - bpSize) * 4}{ 5} \\) + +To get the transaction weight now you just get the length of the transaction blob and add this `clawback`[^bp-tx-weight]. + --- [^tx-v0]: @@ -39,3 +73,17 @@ From v8 the transactions _weight_ must not be bigger than half of the [block pen and [^tx-weight_limit]: && + +[^weight-pre-bp]: + +[^bp-base]: + +[^fp2-less-than-2]: + +[^lr-elements]: + +[^bp+-size]: + +[^clawback]: + +[^bp-tx-weight]: diff --git a/src/consensus_rules/transactions/ring_ct.md b/src/consensus_rules/transactions/ring_ct.md index f679a08..8381905 100644 --- a/src/consensus_rules/transactions/ring_ct.md +++ b/src/consensus_rules/transactions/ring_ct.md @@ -46,7 +46,7 @@ were not being checked for new fork rules they are: ### OutPKs Valid Points -All outPKs must be valid points[^outPKs-valid-points]. +All outPKs must be conically encoded points[^outPKs-valid-points]. ## Simple Types Rules @@ -56,7 +56,7 @@ These rules apply to all RCT "simple" types, which are all except type "FULL". This rule applies to the pseudo-outs, from type 3 (Bulletproof) the pseudo-outs field moved to the prunable RCT section from the non-prunable section. -The pseudo-outs must all be valid points[^pseudo-outs-valid-points]. +The pseudo-outs must all be conically encoded points[^pseudo-outs-valid-points]. ### Pseudo-outs OutPKs Balance