Safechain - A simple "transaction chain" for SAFE

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?

Transactions/contracts
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?

  1. A transaction comes in and is shared with all users of the App.
  2. Every user can decide if a transaction is valid or not. A double spent won’t be allowed for example.
  3. 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.

Miners reward
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.

4 Likes

How do you know which chain is the longest, when there is no concept of time?
Maybe 10 mins from now chain A is longest, and 15 minutes from now chain B is longest, and so on and so forth.

What happens if > 40% don’t sign? Is it the end of the chain?

It’s risky when there’s many users (likely to get too few signatures), it’s risky when there’s few.

It seems some uses - for example voting - could be good for that, but for a long term PoW chain, I think the biggest problem is the there is no concept of time.

2 Likes

A chain is like: transaction > hash > transaction. So when you pick the last transaction to insert your own you try to pick the latest transaction and add yours to that one. Maybe I add my transaction a second later to the same transaction you did. Because you were first, people went on with your transaction making that the longest chain. My transaction (part of a tree) is now invalid because nobody added a new transaction to mine. So I need to insert my transaction on the chain your were one, so I pick the latest transaction in the chain, add mine, and share it with others in the hope they sign it this time and start adding new transactions to mine.

It’s the end of that part of the chain when for example an invalid transaction is done like the example above. For the chain as a whole, it would stop indeed when x-% stops mining. But think of an example like this:

You are in a chatbox with a group of 20 friends. You run your own chain, create a coin for fun, have some little dice-game, do a lottery on your little chain etc. When 10 friends leave the chatbox you just take 6 sings to validate a transaction. When 5 new users join the chat again you take 8 sign as a minimum.

When trying to run a big and secure chain, you could have like 3500 people that sign a transaction. That should be quite secure. There’s no maximum number to the number of signs.

1 Like

Yes, that’s a kind of scenario I can imagine, something similar to voting, maybe in smaller groups.
But if it works as you envision it could have a wider range of uses.

3 Likes