The following proposal draft is intended for fostering discussion and gathering various conceptual and technical feedback before turning into a well-formed KIP.
This is a follow-up on the micropayments discussion initiated by KIP9.
The basic idea is to allow reception of coins in an additive way, where a UTXO owned by the recipient can be spent by the payer transaction (without a signature) as long as the same transaction creates a corresponding output UTXO with a larger amount going to the same recipient address. For an informal background see here.
Opt-in rather than opt-out
Allowing every UTXO to be spent this way is an opening for spam attacks, where a user trying to spend his own UTXOs can be outraced by an attacker spending the same UTXO through the new mechanism (by adding negligible amounts to it). This would essentially remove the underlying assumption of almost any wallet which assumes exclusive access to spending his own UTXOs.
Therefor our suggestion is to allow this only for special addresses (opt-in) where such an address can be configured in various ways to protect from concurrent-spending spam attacks. In the context of this document we’ll name such addresses additive addresses.
Minimum increment threshold The idea is to have the address (or more concretely, the script_pub_key
) define a minimum increment value. Any transaction spending the UTXO and adding to it less than the threshold will be invalid. By the owner specifying this threshold depending on his use case and market value conditions, such spam attacks will become costly and reduced to the point they only benefit the owner.
Semi-signatures Another possibility is to allow spending only with a semi-sig which requires knowing some secret (which is not the full private key only known to the owner). This way the payee can share the secret only with trusted senders.
Technical aspects
Script public key format
At the consensus engine level, a Kaspa address is encoded into a ScriptPublicKey
.
An additive address with a configured increment threshold can be encoded as a ScriptPublicKey
in two possible ways: (i) a special version of p2pk
with the threshold appended at the end (u64
); (ii) using p2sh
and hashing the usual spk
+ threshold
to a single hash.
The first method has the following main advantage:
- The new
spk
will have a known prefix (theversion
+ the usualspk
), which will allow easy searching for such addresses by wallets (possibly recreated from a seed w/o additional info). It’s worth noting that Kaspa nodes use key-value based databases which support prefix-key searches, thus allowing for such prefix queries in an efficient way.
The second method is more robust and general and fits into existing script engine schemes. We can also support both options.
New script-engine opcodes
The main missing component in the script engine is the ability to read from the transaction outputs. It seems that the most straightforward way is to add a new opcode which allows reading an output at index (and accessing the amount
and recipient spk
). This way, the script engine can make the required verification by accessing the spent spk
, the recipient spk
and the respective amounts. The signature can be used for adding any additional info needed such as providing proof of a semi-sig etc.
Additional remarks
- The transaction input index should be mapped to a known output index to avoid multiple spends being mapped to the same output (perhaps simply
i
toi
, forcing such inputs to be first) - It’ll be the first time that validating a sig requires looking at tx outputs (so broader context). This can be crucial. For instance such “signature” validations cannot be cached as valid
- Besides the aforementioned schemes there can be a type of special address which allows additive mining. Meaning miners can use this UTXO as input to coinbase txs and output the reward + previous balance. This can be seen as a minimum increment threshold where the threshold is dynamic and is equal to the current mining reward. To avoid any kind of attack, the input UTXO will be used only if it’s available at the time the coinbase tx is built (by the merging block), otherwise we fallback to normal behavior. This is an important feature for 10BPS where nearly 1M rewards will be mined per day.
This writeup is an intermediate summary of ongoing discussions with @ori, @Deshe2, @hashdag, @biryukovmaxim, @coderofstuff, @ey51