0

My question is referring to immutability of smart contract data.

If I make a function in smart contract and write a conditional such that if a key of a map already exists jump out of the function and don't add it to the map.

i.e.

library Library {
  struct data {
     uint val;
     bool isValue;
   }
}

contract Array{
    using Library for Library.data;
    mapping(address => Library.data) map;
    function addCluster(address id) {
        if(map[id].isValue) throw; // duplicate key
        // else insert a key value pair 
    }
}

Is this state then immutable?

I've heard that if majority consensus of a private network agrees then they can reverse or 'roll back' already mined transactions and blocks. As stated in this article under the private blockchain section https://www.multichain.com/blog/2017/05/blockchain-immutability-myth/.

I'm trying to understand what happens consensus of a private network decide to roll back to a particular block before that transaction had been mined, will that key/value pair (state) be deleted? Thus asking can state be immutable if it was programmed to in the contract.

1

It's not a matter of reorganizing the current state in light of changes to the past. Nothing can exist in the present that isn't the result of things that happened in the past.

In the case that consensus shifts to a different description of the past, then a different present state is self-evident. The node may grind away a bit to reorganize internally but the internal logical consistency will be maintained.

If you're a StarTrek or Stephan Hawking fan, it might suffice to understand that even in the unlikely case that someone builds a time machine, travels to the past and changes something, causality will not be violated.

In the case of private chains touting rollback as a solution to errant contracts, the threshold consensus needed to do that is much lower than the comparable on public chains, because there are are fewer nodes in the consensus are they all known. In either case, the participants would be aware that there was a revision to the chain.

Hope it helps.

| improve this answer | |
  • Hey Rob thanks for the response. If you don't mind can you see if the following logic is correct? So in regards to your response, what you are saying is that if a rollback happens the internal state can change but the actual contract logic itself shouldn't be able to change though the entire contract itself can be removed if the rollback brings the chain to a previous chain length before the contract was deployed (a transaction). Can you tell me how the participants would be aware of a revision to the chain. In addition can you share a link describing how to commit one of these rollbacks. Thx – Matt Hess Aug 6 '18 at 16:20
  • It might be of best interest to inform you that the private network I will be configuring will be used as a shared database. That is why I am more concerned with the internal state rather than the actual tokens – Matt Hess Aug 6 '18 at 16:40
  • I think it would be worth mentioning that my use case of the blockchain was to setup a network for a business to validate document hashes. I have found out that instead of using a proof-of-work consensus system that is prone to 51% attacks I would need to use a permissioned network running on a proof-of-authority consensus system. This way the data can not be manipulate by someone with more computational power. Check out this link if anyone wants to learn more, ethereum.stackexchange.com/questions/7120/… . Thanks again Rob – Matt Hess Aug 7 '18 at 16:52
0

For Ethereum nodes following the normal consensus protocol, the "longest valid chain" will be the blockchain which nodes will programmatically agree is the real chain.

If your data/transaction is a part of that longest valid chain, then for all intents and purposes, that data is immutable, barring something quite crazy happening like:

  • A new longest valid chain is discovered, which dramatically alters the data on the blockchain (see 51% attack)
  • There is a fork at a point before your data is mined (and in this situation, it is possible that the "unforked" chain still gets mined, which means your data would still live on that chain)
  • An agreed upon EIP changes your data in particular, and participating Ethereum nodes and node software go along with that change

But all these scenarios are very unlikely, so I think while there are some caveats, it is fair to say that data on the blockchain, once mined to a reasonable block depth, is immutable.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.