What are the types of blockchain ledgers?
There are 2 types.
- Account based (e.g. Ethereum)
- (E)UTXO based (e.g. Cardano, Bitcoin)
Account based have issue of global state. Transactions cannot be transitive.
A->B AND B->C =/= A->C
This is because the order in which the transaction occur matter, and may not be sequenced correctly.
UTXO are more complicated to manage, however computationally cheaper and provide ways for optimization.
Are short for unspent transaction outputs.
These have a simple ownership model where the output has a public key attached to it, which identifies who “owns” the UTXO.
The collection of these UTXO gives us the net worth of an account tagged to their public key.
Cardano uses something slightly different, EUTXO model. The EUTXO can be locked by hash of a validator script.
This decides if the transaction spending the output should be authorized to do so, e.g. checking if the UTXO was signed by a particular key (and hence providing the basic functionality of UTXO)
Validator scripts have 3 arguments:
- datum - attached to EUTXO tagged to script. Used to carry state.
- redeemer - attached to input doing the spending. Provides input from script from the spender.
- Context - Information about transaction doing the spending. Make assertions about the way output was sent.
As an example, let’s see how we could implement an atomic swap.
The datum contains the keys of the two parties in the swap, and a description of what they are swapping The redeemer is unused. The context contains a representation of the transaction.
The logic of the validator script is then: does the transaction make a payment from the second party to the first party, containing the value that they are supposed to send? If so, then they may spend this output and send it where they want (or we could insist that the send it to their key, but we might as well let them do what they like with it).