Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add gas price factor. #343

Merged
merged 2 commits into from
Jun 10, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 13 additions & 12 deletions specs/protocol/tx_format.md
Original file line number Diff line number Diff line change
Expand Up @@ -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. |
vlopes11 marked this conversation as resolved.
Show resolved Hide resolved
| `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

Expand Down
8 changes: 4 additions & 4 deletions specs/protocol/tx_validity.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.

Expand All @@ -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
Expand Down