QIP: 6 Layer: Protocol Title: Merge-Mined Transactions Author: kiltsonfire Comments-Summary: No comments yet. Comments-URI: https://github.com/quainetwork/qips/wiki/Comments:QIP-0006 Status: Draft Type: Standards Track Created: 2023-11-16 License: BSD-2-Clause
This QIP defines the process and protocol changes required to allow the merge-mining of transactions.
Merge-mined transactions (MMTX) enable objective ordering of transactions in proposed blocks, aligning incentives for block producers and miners. Additionally, MMTX reduces the impact of miner extractable value (MEV) on users and incentivizes hash contribution to the network.
MEV presents two issues: increased user costs and compromised chain progression and security. Large MEV opportunities can outweigh block reward incentives, leading miners to compete for MEV rather than cooperatively extending the longest chain. Currently, cryptocurrencies use separate mechanisms for ordering blocks and transactions within blocks. This distinction is unnecessary and creates competing markets for the same service: transaction ordering. One unified market for transaction ordering (for both intra and inter-block transactions) would eliminate this competition, enhancing security and finalization speed.
To implement a hash-based ordering market, it must govern both transaction and block ordering, removing conflicts between transaction and block progression.
This QIP suggests a base fee for processing, with transaction order determined by worked ProgPow hashes. Transactions would be merge-mined with blocks, and the mining work done on a transaction would dictate its order in a block. The most worked transactions would be prioritized. Algorithmically, this involves sorting ProgPow hashes within each block based on their values, with lower hashes processed first.
Let
Given the defined set of hashes
Algorithm 1 Sorting Hashes within Blockchain Blocks
1: H
2: function constructor(H′)
3: H ← H′ ▷ Set of hash values H
4: end function
5: function sortHashes(H)
6: for each block i from 1 to n do
7: for each transaction j from 1 to m_i do
8: Perform insertion sort on H[i] based on the hash order:
9: if hash_{i,j} < hash_{i,j-1} then
10: Swap hash_{i,j} with hash_{i,j-1}
11: end if
12: end for
13: end for
14: end function
This would mean that to MEV a MMTX, say sandwich or front-run, a MEV bot would have to mine a transaction with appropriate order around the targeted transaction. This may seem trivial for transactions which do not have significant amounts of work, however, sandwiching a tx would require finding a mined tx which is in front of and behind the target transaction. Moreover, any MEV bot would have to execute these attacks in real-time.
In addition to organizing transactions based on their hash values, the protocol incorporates the work done on each transaction into the overall entropy of the block. This approach means that blocks containing transactions with a higher amount of work, and therefore lower entropy, are more likely to be recognized as the primary block in the chain. This alignment between transaction ordering and the growth of the longest chain is essential for maintaining network integrity.
However, this method requires careful consideration to prevent potential exploits. If miners can mine transactions independently and include them arbitrarily in future blocks, they could amass a large number of mined transactions to dominate block creation. To counter this, the block's hash, with which a transaction is merged-mined, is used as a reference point. The contribution of a transaction's weight to a block's weight diminishes based on the age difference between the transaction and the block. This mechanism incentivizes miners to include transactions in their blocks as quickly as possible.
An additional layer of complexity arises with merge-mined transactions. These transactions can only be included if they are merged-mined with a canonical block. By mining on top of an already existing block, the work invested in merge-mined transactions serves to validate and reinforce the legitimacy of that block. This process not only enhances the security of the chain through implicit verification but also contributes to the overall chain entropy.
The decay in the contribution of a transaction's work to a block's entropy over time is also an important factor. The further away a transaction is from the current chain tip, the less it contributes to the block's entropy. Therefore, it's proposed that the weight of a transaction's work should decrease by half for each block that passes after it becomes eligible for inclusion. This approach encourages producers of merge-mined transactions to reference the most recent block, ensuring their transactions are included promptly. It also motivates miners to quickly include valid merge-mined transactions in their blocks, maximizing the total entropy and thereby strengthening the blockchain.
- Let
$Tx_{i,n}$ denote a MMTX, where$i$ is the block index referenced by the MMTx,$n$ is the current block index, and$j$ is the index for each MMTx referencing block$i$ included in block$n$ . - Define
$S_{int}$ as the bits of entropy achieved from mining a block, and$S_{target}$ as the entropy target in bits. A block is successfully mined when the condition$S_{int} > S_{target}$ is met.
The transaction entropy for a set of transactions included in block
In this expression:
The total entropy of a block is given by:
Although, the entropy of MMTx could be calculated going all the way back to
genesis, from the view of practical computations the depth of computation,
Additionally, it should be noted that the expected maximum contribution of
transactions to the block entropy total is the square of the intrinsic
threshold. For example, if
Counting the work of transactions towards the weight of a block can have unintended consequences. Specifically, it might motivate miners to hold back transactions with substantial work to gain an advantage in block mining. This could negatively impact the network since blocks containing unpropagated transactions take longer to verify and unpropogated transaction will provide the miner that includes it an advantage over other miners which is not proportional to their hashrate.
This issue is partially mitigated by two factors. First, if the inclusion of unpropagated transactions significantly delays block validation, the block is more likely to be rejected (become an uncle block), penalizing the miner responsible. Second, users who broadcast transactions with a substantial amount of work are motivated to ensure rapid network propagation of their transactions, increasing the likelihood of their inclusion in a block with high priority.
However, if these incentives aren't enough, the marginal cost of mining an MMTX can be changed with the demand for interblock ordering. As long as the marginal cost of MMTX production is not allowed to be zero, there will always be an incentive to propogate MMTXs.
When a MMTX is constructed to allow the work to be counted for both a transaction and a block, an issue arises due to the zero marginal cost of reusing the hash to mine a transaction that was going to mine a block. This is also the origin of potential withholding attacks when mined transactions are introduced. To eleviate these issues, it is proposed that a new merge mining scheme is introduced which allows MMTX marginal cost of production to decrease with increased demand for transaction ordering. Thus a new mechanism is proposed that will change the percentage of work that can count torwards merge mined blocks. This will prevent a withholding incentive while also creating a mechanism that will guarantee that the blockchain remains lively when there is high demand for ordering. The goal is to make it so that the marginal cost of mining a transaction is high when demand for ordering is low, and conversley the marginal cost for mining is low when the demand for ordering is high. It is important to note, that the marginal cost cannot allowed to be zero else the withholding incentives will be reintroduced.
A secondary threshold can be used to establish a criteria for determining if a share meets the block criteria and this criteria can be adjusted by what is in the proposed block dynamically to ensure that the chain always remains lively. The secondary threshold criteria will be based on the trailing zeros of the hash. Specifically, the criteria to become an MMTX block will be met if:
where $ TX_{hash,val} = TX_{hash}[end-2:] $ or more simply the last two bytes in the hash, and the $ B_{mmtx,t} $ is the block threshold for the MMTTX to be valid. The block threshold $ B_{mmtx,t} $ will be adjusted such that the threshold is high when ordering demand is low and gets lower as ordering demand increases. This will ensure that blocks remain lively even if there is high instantaneous changes in demand for mined transactions. The block threshold will be calculated as follows:
where
It is interesting to note the impact of the block expectation time on the
change in
The interesting implication of MMTX is the creation of a new datastructure that will be referred to as a workedObject. All data that may be inserted or appended to the blockchain highest abstract form is now a workObject. More specifically, a MMTX must take the form of a workObject. Depending on the weight of the workObject, it will become either a header or a MMTX.
The fields that will be needed to compute a workObject's work, or entropy reduction, need to be removed from the header so that they are not needlessly replicated.
The fields that will be removed from the header are as follows:
Field | Type |
---|---|
ParentHash[2] | common.Hash |
Number[2] | *big.Int |
Nonce | uint64 |
The following fields will be renamed:
Old Field | New Field |
---|---|
ParentHash[] | DomParentHash[] |
Number[] | DomNumber[] |
Field | Type |
---|---|
HeaderHash | common.Hash |
ParentHash | common.Hash |
Number | *big.Int |
TxHash | common.Hash |
Nonce | uint64 |
The astute reader will notice that the fields that were deleted from the header are now included in the workObject structure. The sealHash for the workObject will be computed by hashing all of the fields except for the Nonce. Mining of the workObject will take place by grinding the Nonce field. Once a workObject is found the producer will be able to determine if it is a MMTX or a Block based on the entropy threshold acheived. This workObject can then be combined with either the corresponding Header or Transaction body to create either an MMTX or a block. The MMTX must then be signed by the appropriate private key and the MMTX and the signature can be transmitted to form a transaction. If a block is achieved, the workObject can be combined with the header and optionally the block body to produce a valid header or valid block and transmitted with no further processing.
In PoW systems it is shown in {Everything is a Race and Nakamoto Always Wins}
that all attacks on safety of a PoW blockchain can be simplified to a private
mining attack. This means that in a theoretical network a PoW chain has
adversarial resiliance if
There is however, a contravening consideration, which is the ability for late joining clients to join the network. Specifically, will a late joining client or a non-nefarious network partition be able to catch up to the honest majority? The answer to this questions depends on the number of threads that a node has to validate MMTXs relative to the number of MMTXs included in a block on expectation.
For example, if a honest node has a modern GPU, it will have > 16,000 threads.
Each on of these could be used to validate the SDF of MMTXs in parallel. Thus
if the average block has 2,000 MMTXs and the average
Lets explore what would happen here if there was a transaction that can be
exploited by being front run by a MEV bot. All MEV exploits normally require a
MEV bot to get at least 1 tx in-front of the
Lets say that at this point in time Alice has managed to order her transaction
in front of Bobs. That means that the block will have a block entropy of at
least
If Bob is unsatisfied with this result he can try and mine a new tip which is a
fork with the block that was just mined. Bobs expected entropy for the nth
block will be
That means that for the time
Moreover, after Bob produces his block
This QIP licensed under the BSD 2-clause license.