From 290bed78c02faa9ce59a9812424e968070bd32f8 Mon Sep 17 00:00:00 2001 From: John Adler Date: Thu, 9 Jun 2022 16:46:52 -0400 Subject: [PATCH] Add gas price factor. --- specs/protocol/tx_format.md | 25 +++++++++++++------------ specs/protocol/tx_validity.md | 8 ++++---- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/specs/protocol/tx_format.md b/specs/protocol/tx_format.md index 23e716fb..3c48e025 100644 --- a/specs/protocol/tx_format.md +++ b/specs/protocol/tx_format.md @@ -22,18 +22,19 @@ ## Constants -| name | type | value | description | -|-----------------------------|----------|-------|-----------------------------------------------| -| `GAS_PER_BYTE` | `uint64` | | Gas charged per byte of the transaction. | -| `MAX_GAS_PER_TX` | `uint64` | | Maximum gas per transaction. | -| `MAX_INPUTS` | `uint64` | `8` | Maximum number of inputs. | -| `MAX_OUTPUTS` | `uint64` | `8` | Maximum number of outputs. | -| `MAX_PREDICATE_LENGTH` | `uint64` | | Maximum length of predicate, in instructions. | -| `MAX_PREDICATE_DATA_LENGTH` | `uint64` | | Maximum length of predicate data, in bytes. | -| `MAX_SCRIPT_LENGTH` | `uint64` | | Maximum length of script, in instructions. | -| `MAX_SCRIPT_DATA_LENGTH` | `uint64` | | Maximum length of script data, in bytes. | -| `MAX_STORAGE_SLOTS` | `uint16` | `255` | Maximum number of initial storage slots. | -| `MAX_WITNESSES` | `uint64` | `16` | Maximum number of witnesses. | +| name | type | value | description | +|-----------------------------|----------|-----------------|-----------------------------------------------| +| `GAS_PER_BYTE` | `uint64` | | Gas charged per byte of the transaction. | +| `GAS_PRICE_FACTOR` | `uint64` | `1,000,000,000` | Unit factor for gas price. | +| `MAX_GAS_PER_TX` | `uint64` | | Maximum gas per transaction. | +| `MAX_INPUTS` | `uint64` | `8` | Maximum number of inputs. | +| `MAX_OUTPUTS` | `uint64` | `8` | Maximum number of outputs. | +| `MAX_PREDICATE_LENGTH` | `uint64` | | Maximum length of predicate, in instructions. | +| `MAX_PREDICATE_DATA_LENGTH` | `uint64` | | Maximum length of predicate data, in bytes. | +| `MAX_SCRIPT_LENGTH` | `uint64` | | Maximum length of script, in instructions. | +| `MAX_SCRIPT_DATA_LENGTH` | `uint64` | | Maximum length of script data, in bytes. | +| `MAX_STORAGE_SLOTS` | `uint16` | `255` | Maximum number of initial storage slots. | +| `MAX_WITNESSES` | `uint64` | `16` | Maximum number of witnesses. | ## TransactionType diff --git a/specs/protocol/tx_validity.md b/specs/protocol/tx_validity.md index 1dd9d0e1..ad1031c4 100644 --- a/specs/protocol/tx_validity.md +++ b/specs/protocol/tx_validity.md @@ -100,9 +100,9 @@ def unavailable_balance(tx, col) -> int: monotonic and the cost of Ethereum calldata more than makes up for this """ sentBalance = sum_outputs(tx, col) - gasBalance = gasPrice * gasLimit + gasBalance = ceiling((gasPrice * gasLimit) / GAS_PRICE_FACTOR) # Size excludes witness data as it is malleable (even by third parties!) - bytesBalance = size(tx) * gasPrice * GAS_PER_BYTE + bytesBalance = ceiling((size(tx) * gasPrice * GAS_PER_BYTE) / GAS_PRICE_FACTOR) # Only native coin can be used to pay for gas if col != 0: return sentBalance @@ -154,7 +154,7 @@ Once the free balances are computed, the [script is executed](../vm/main.md#scri 1. The unspent free balance `unspentBalance` for each asset ID. 1. The unspent gas `unspentGas` from the `$ggas` register. -The fees incurred for a transaction are `(tx.gasLimit - unspentGas) * tx.gasPrice`. +The fees incurred for a transaction are `ceiling(((tx.gasLimit - unspentGas) * tx.gasPrice) / GAS_PRICE_FACTOR)`. If the transaction as included in a block does not match this final transaction, the block is invalid. @@ -168,7 +168,7 @@ Given transaction `tx`, state `state`, and contract set `contracts`, the followi If change outputs are present, they must have: -1. if the transaction does not revert; an `amount` of `unspentBalance + unspentGas * tx.gasPrice` if their asset ID is `0`, or an `amount` of the unspent free balance for that asset ID after VM execution is complete, or +1. if the transaction does not revert; an `amount` of `unspentBalance + floor((unspentGas * tx.gasPrice) / GAS_PRICE_FACTOR)` if their asset ID is `0`, or an `amount` of the unspent free balance for that asset ID after VM execution is complete, or 1. if the transaction reverts; an `amount` of the initial free balance plus `unspentGas * tx.gasPrice` if their asset ID is `0`, or an `amount` of the initial free balance for that asset ID. ### State Changes