Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

opts.state and opts.activatePrecompiles are not compatible #411

Closed
davidmurdoch opened this issue Dec 21, 2018 · 3 comments · Fixed by #415
Closed

opts.state and opts.activatePrecompiles are not compatible #411

davidmurdoch opened this issue Dec 21, 2018 · 3 comments · Fixed by #415

Comments

@davidmurdoch
Copy link
Contributor

davidmurdoch commented Dec 21, 2018

#376 made a change that makes the following happen:

var myTrie = new Trie();
var vm = new VM({
   state: myTrie,
   activatePrecompiles: true
});
myTrie.root.equals(myTrie.EMPTY_TRIE_ROOT); // true
myTrie.root.equals(vm.statemanager._trie.root); // false

opts.state is no longer used by the internal StateManager. Is this intentional?

@holgerd77
Copy link
Member

Just checked, this is actually only happening with the combination of also setting activatePrecompiles: true you're applying above. In the code there is then the trie newly instantiated (see code).

I would very much assume that this is a bug and should be fixed, any other opinions why this mgith be there and if it could have a reasoning?

@davidmurdoch how urgent is this for you?

@davidmurdoch
Copy link
Contributor Author

I think it was just missed in the nit of refactoring done in #376, seems like a bug to me.

For ganache-core we can temporarily work around it by creating the precompile entries in our own state trie, and set activatePrecompiles to false when creating the VM instance.

We can just do something like this:

const createStateTrie = function(db, root) {
  const trie = new Trie(db, root);
  for (var i = 1; i <= 8; i++) {
    trie.put(new BN(i).toArrayLike(Buffer, "be", 20), new Account().serialize());
  }
  return trie;
};
const vm = new VM({state: createStateTrie(data.trie_db, block.header.stateRoot)});

We currently don't have any tests for precompiled contracts in ganache-core, so I'm not 100% confident we actually need it.

So to answer your question directly: it's not very urgent for us.

@holgerd77
Copy link
Member

Thanks for the detailed answer, will try to do a big fix release on this anyhow ASAP. This is a serious bug and shouldn't be left in the code for too long.

Not sure if I'll make it before Christmas though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants