Skip to content

Commit

Permalink
Change mint tx format and coinbase rules to mitigate dust accumulation (
Browse files Browse the repository at this point in the history
#511)

The mint transaction is no longer allowed to create coin outputs, and
instead performs an intrinsic contract balance increase.

This is lighterweight compared to using a script transaction as a
coinbase, as no VM execution needs to occur. This prevents dust
accumulation of low-value coinbase coin outputs compared to the previous
design.

---------

Co-authored-by: Green Baneling <[email protected]>
Co-authored-by: Hannes Karppila <[email protected]>
  • Loading branch information
3 people authored Aug 28, 2023
1 parent 5b1c5dc commit 762b35d
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 12 deletions.
23 changes: 18 additions & 5 deletions src/protocol/tx-validity.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,14 @@ def sum_inputs(tx, asset_id) -> int:
total += input.amount
return total

"""
Returns any minted amounts by the transaction
"""
def minted(tx, asset_id) -> int:
if tx.type != TransactionType.Mint or asset_id != tx.mint_asset_id:
return 0
return tx.mint_amount

def sum_outputs(tx, asset_id) -> int:
total: int = 0
for output in tx.outputs:
Expand All @@ -114,7 +122,7 @@ def available_balance(tx, asset_id) -> int:
"""
Make the data message balance available to the script
"""
availableBalance = sum_inputs(tx, asset_id) + sum_data_messages(tx, asset_id)
availableBalance = sum_inputs(tx, asset_id) + sum_data_messages(tx, asset_id) + minted(tx, asset_id)
return availableBalance

def unavailable_balance(tx, asset_id) -> int:
Expand Down Expand Up @@ -206,11 +214,16 @@ Transaction processing is completed by removing spent UTXOs from the state and a

### Coinbase Transaction

The coinbase transaction is a mechanism for block creators to convert fees into spendable UTXOs.
The coinbase transaction is a mechanism for block creators to collect transaction fees.

In order for a coinbase transaction to be valid:

1. It must be a [Mint](../tx-format/transaction.md#TransactionMint) transaction.
2. The coinbase transaction must be the first transaction within a block, even if there are no other transactions in the block and the fee is zero.
3. The total output value of the coinbase transaction cannot exceed the total amount of fees processed from all other transactions within the same block.
4. The `asset_id` for coinbase transaction outputs must match the `asset_id` that fees are paid in (`asset_id == 0`).
1. The coinbase transaction must be the last transaction within a block, even if there are no other transactions in the block and the fee is zero.
1. The `mintAmount` doesn't exceed the total amount of fees processed from all other transactions within the same block.
1. The `mintAssetId` matches the `asset_id` that fees are paid in (`asset_id == 0`).

The minted amount of the coinbase transaction intrinsically increases the balance corresponding to the `inputContract`.
This means the balance of `mintAssetId` is directly increased by `mintAmount` on the input contract,
without requiring any VM execution. Compared to coin outputs, intrinsically increasing a contract balance to collect
coinbase amounts prevents the accumulation of dust during low-usage periods.
17 changes: 10 additions & 7 deletions src/tx-format/transaction.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,15 +131,18 @@ Creates a contract with contract ID as computed [here](../identifiers/contract-i
## TransactionMint

The transaction is created by the block producer and is not signed. Since it is not usable outside of block creation or execution, all fields must be fully set upon creation without any zeroing.
This means that the transaction ID must also include the correct `txPointer` value, not zeroed out.

| name | type | description |
|----------------|------------------------------|------------------------------------------------------|
| `txPointer` | [TXPointer](./tx-pointer.md) | The location of the `Mint` transaction in the block. |
| `outputsCount` | `uint8` | Number of outputs. |
| `outputs` | [Output](./output.md)`[]` | List of outputs. |
| name | type | description |
|------------------|------------------------------|------------------------------------------------------|
| `txPointer` | [TXPointer](./tx-pointer.md) | The location of the `Mint` transaction in the block. |
| `inputContract` | [Input](./input.md) | The contract utxo that assets are minted to. |
| `outputContract` | [Output](./output.md) | The contract utxo that assets are being minted to. |
| `mintAmount` | `uint64` | The amount of funds minted. |
| `mintAssetId` | `byte[32]` | The asset IDs corresponding to the minted amount. |

Transaction is invalid if:

- Any output is not of type `OutputType.Coin`
- Any two outputs have the same `asset_id`
- `txPointer` is zero or doesn't match the block.
- `inputContract` is not of the type `InputType.Contract`
- `outputContract` is not of the type `OutputType.Contract`

0 comments on commit 762b35d

Please sign in to comment.