No I’m not a coder, but inspired by topics from @Seneca I would like to show you a simple idea for a “transaction chain” on SAFE. It doesn’t have to be in the core code and could run as an App on SAFE. So what should it do?
The basic idea behind a blockchain is a ledger with all transaction/contracts visible and accountable by all. This means every user is able to check all the transactions an agree on the outcome. Normally every chain contains “blocks” where miners try to mine a block by altering a nonce and create a hash with an x-number of zero’s as the Proof Of Work (POW). There are some cons to this approach. Transactions take at least the time of a block to become valid and miners use an extreme amount of energy and (almost) useless POW to mine a block. And when the number of transactions is low, you still need to create blocks and do the POW. So, how could we work around this problem?
Treat every transaction as a block
Whenever a transaction comes in, miners should be able to do a simple POW to make the transaction valid as fast as possible. We don’t create blocks to keep the “transaction chain” as small as possible, so when no transactions are done we don’t do any POW. There is a little con to that, we miss the timestamp.
Bringing it all together
So, how can be achieve these goals on SAFE? First of all, as @Seneca showed in his post we can use an tag type to have our own address-range of 512 bits. That are a lot of possible addresses owned or not by a user of the App. Just like with Bitcoin all transaction done with the App are shared with all the users of that App. So what should happen when a transaction comes in?
- A transaction comes in and is shared with all users of the App.
- Every user can decide if a transaction is valid or not. A double spent won’t be allowed for example.
- All transactions are chained together but only when they’re valid. Invalid ones are ignored (not signed).
So how does this signing/mining process work?
Each transaction has a hash which is an identifier (address) in the network. All nodes calculate the same hash so when the sender of the transaction owns that address (he needs to, just to store that transaction) all nodes agree that the address is indeed the hash of the transaction. When the nodes agree the transaction is valid, they sign the transaction with a digital signature, and calculate some POW on that signature which gives them a unique outcome. That outcome is a hash (with an x-number of zero’s) which is now owned by the signer of the transaction. Due to the digital signature the hash (address) of this sign is unique. After signing, the node sends it’s signature to other nodes. It looks like this:
Transaction > hash > digital signature > POW on digital signature > outcome is owned by signer.
So every transaction has a whole tree-structure around it of addresses that are owned by the signers/miners. The addresses themselves are POW that the signer/miner indeed declared the transaction valid.
Next transaction in the chain
The question is, how do we go from this tree-structure and all these signs with POW to the next transaction? Well, the issuer of the new transaction uses the previous hash, adds his own transaction and hashes that as well. Now he has an address which is the hash of his transaction and the previous hash. He shares his transaction with the other nodes so they can do POW on his transaction. This new transaction get’s a whole tree-structure around it as well for all nodes to check. But the actual transaction is in a chain without a tree-structure. It’s just: previous hash > transaction > new hash.
The longest chain
As you can see the App takes one transaction at the time before it goes over to the next. But the POW can actually be very easy to speed things up. A transaction is valid when at least an x-number of users signed it. It could also be done by requesting consensus of at least 60% of the active user of the App. So 100 users in the App could start a transaction chain, and they all sign valid transactions and request at least 60 signs before they take the next transaction. There might show up different routes in the chain when different people sign different transactions. So the goal is just as with Bitcoin to follow the longest chain and make only that one valid.
I doubt if we really should reward the miners for the little easy POW they do. I also can’t think of a fair mechanism where the first 50 or 100 miners earn a reward. There are no timestamps in this system so who was first? Miners sign/mine transactions in parallel. People that run the app sign transactions as they come in. It could be very very fast.
A problem that shows up with an easy idea like this is the fact that users of the App need to scan the whole transaction chain from transaction one. Not very different from Bitcoin. another problem is when a lot of new corrupt miners show up to hijack the chain. This could be prevented by using rank which builds up after an x-number of correct signs.
So, this is it. I think it is possible and probably the most simplistic idea of a “blockchain” on SAFE. Without all these blocks that we see in other systems. let me know what you think.