public void Nonce_is_correct() { StateTree tree = new StateTree(); byte[] code = new byte[] { 1, 2, 3 }; Account account1 = Build.An.Account.WithBalance(1).WithNonce(UInt256.One).TestObject; Account account2 = Build.An.Account.WithBalance(2).TestObject; tree.Set(TestItem.AddressA, account1); tree.Set(TestItem.AddressB, account2); tree.Commit(); ProofCollector proofCollector = new ProofCollector(TestItem.AddressA); tree.Accept(proofCollector, new MemDb(), tree.RootHash); AccountProof proof = proofCollector.BuildResult(); Assert.AreEqual(account1.Nonce, proof.Nonce); ProofCollector proofCollector2 = new ProofCollector(TestItem.AddressB); tree.Accept(proofCollector2, new MemDb(), tree.RootHash); AccountProof proof2 = proofCollector2.BuildResult(); Assert.AreEqual(UInt256.Zero, proof2.Nonce); }
public void Storage_proofs_have_values_set_complex_3_setup() { Keccak a = new Keccak("0x000000000000000000000000000000000000000000aaaaaaaaaaaaaaaaaaaaaa"); Keccak b = new Keccak("0x0000000000000000000000000bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"); Keccak c = new Keccak("0x00000000001ccccccccccccccccccccccccccccccccccccccccccccccccccccc"); Keccak d = new Keccak("0x00000000001ddddddddddddddddddddddddddddddddddddddddddddddddddddd"); Keccak e = new Keccak("0x00000000001eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee"); IDb memDb = new MemDb(); StateTree tree = new StateTree(memDb); StorageTree storageTree = new StorageTree(memDb); storageTree.Set(a.Bytes, Rlp.Encode(Bytes.FromHexString("0xab12000000000000000000000000000000000000000000000000000000000000000000000000000000"))); storageTree.Set(b.Bytes, Rlp.Encode(Bytes.FromHexString("0xab34000000000000000000000000000000000000000000000000000000000000000000000000000000"))); storageTree.Set(c.Bytes, Rlp.Encode(Bytes.FromHexString("0xab56000000000000000000000000000000000000000000000000000000000000000000000000000000"))); storageTree.Set(d.Bytes, Rlp.Encode(Bytes.FromHexString("0xab78000000000000000000000000000000000000000000000000000000000000000000000000000000"))); storageTree.Set(e.Bytes, Rlp.Encode(Bytes.FromHexString("0xab9a000000000000000000000000000000000000000000000000000000000000000000000000000000"))); storageTree.Commit(); byte[] code = new byte[] { 1, 2, 3 }; Account account1 = Build.An.Account.WithBalance(1).WithStorageRoot(storageTree.RootHash).TestObject; Account account2 = Build.An.Account.WithBalance(2).TestObject; tree.Set(TestItem.AddressA, account1); tree.Set(TestItem.AddressB, account2); tree.Commit(); ProofCollector proofCollector = new ProofCollector(TestItem.AddressA, new Keccak[] { a, b, c, d, e }); tree.Accept(proofCollector, memDb, tree.RootHash); AccountProof proof = proofCollector.BuildResult(); TestOneWaySerialization(proof, "{\"accountProof\":[\"0xe215a0e2a0cd25c7c043b502d300690d497d07c90503cf48575d7c4d9df48c3239c3f4\",\"0xf8518080808080a064c7ecf7af3f0cd537929398725a611310f6d5190a097aca9c03a3d21ce061128080808080808080a02352504a0cd6095829b18bae394d0c882d84eead7be5b6ad0a87daaff9d2fb4a8080\",\"0xf869a020227dead52ea912e013e7641ccd6b3b174498e55066b0c174a09c8c3cc4bf5eb846f8448001a0afc6e7c1c13f18c0ee2a94c64c0855a03d1dd26afe5f6b2c2a99eb065223ca39a0c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470\"],\"balance\":\"0x1\",\"codeHash\":\"0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470\",\"nonce\":\"0x0\",\"storageHash\":\"0xafc6e7c1c13f18c0ee2a94c64c0855a03d1dd26afe5f6b2c2a99eb065223ca39\",\"storageProof\":[{\"key\":\"0x000000000000000000000000000000000000000000aaaaaaaaaaaaaaaaaaaaaa\",\"proof\":[\"0xe886000000000000a0830818307108fb62adbcdd1d9b869a4cf8955dc211a286503febdf17ac599b2e\",\"0xf851a020be9ddd30723181a87b18a6d2bfa2b3323f30f1d0646aa9c7eea06af9e31c57a06da0dc6a9169f5f35fd7d057065203ba2c9fb225d8d6b4bb35f2dc1d2ba693b6808080808080808080808080808080\",\"0xea880000000000000000a0c0f54c2d3456184a7bc418ec5b534a9a136ed3b5627caced8bed3732264b3fed\",\"0xf851a034c4b62df64d959a98788985227a6c0ab009d7db955547d0be790c1ce553ed4980808080808080808080a0b43c9841efec2ea2b85472f8883b77a2669cc8ed0c86a422d4114b9e17f115918080808080\"],\"value\":\"0xab12000000000000000000000000000000000000000000000000000000000000000000000000000000\"},{\"key\":\"0x0000000000000000000000000bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\",\"proof\":[\"0xe886000000000000a0830818307108fb62adbcdd1d9b869a4cf8955dc211a286503febdf17ac599b2e\",\"0xf851a020be9ddd30723181a87b18a6d2bfa2b3323f30f1d0646aa9c7eea06af9e31c57a06da0dc6a9169f5f35fd7d057065203ba2c9fb225d8d6b4bb35f2dc1d2ba693b6808080808080808080808080808080\",\"0xea880000000000000000a0c0f54c2d3456184a7bc418ec5b534a9a136ed3b5627caced8bed3732264b3fed\",\"0xf851a034c4b62df64d959a98788985227a6c0ab009d7db955547d0be790c1ce553ed4980808080808080808080a0b43c9841efec2ea2b85472f8883b77a2669cc8ed0c86a422d4114b9e17f115918080808080\"],\"value\":\"0xab34000000000000000000000000000000000000000000000000000000000000000000000000000000\"},{\"key\":\"0x00000000001ccccccccccccccccccccccccccccccccccccccccccccccccccccc\",\"proof\":[\"0xe886000000000000a0830818307108fb62adbcdd1d9b869a4cf8955dc211a286503febdf17ac599b2e\",\"0xf851a020be9ddd30723181a87b18a6d2bfa2b3323f30f1d0646aa9c7eea06af9e31c57a06da0dc6a9169f5f35fd7d057065203ba2c9fb225d8d6b4bb35f2dc1d2ba693b6808080808080808080808080808080\",\"0xf871808080808080808080808080a0d05f5bbfc8b0cf084848efcdd079e280384c937c8f30e5fe86dea0b4c3e23ebaa0ed9e169336203e22c92423e552c29f717f1024954239f90ee6940d9546149ad3a06841d65c5f2d895812aa6b18874d0aeae1cca5d73d3ee9277dc00bc84bee6ca78080\",\"0xf8479b20ccccccccccccccccccccccccccccccccccccccccccccccccccccaaa9ab56000000000000000000000000000000000000000000000000000000000000000000000000000000\"],\"value\":\"0xab56000000000000000000000000000000000000000000000000000000000000000000000000000000\"},{\"key\":\"0x00000000001ddddddddddddddddddddddddddddddddddddddddddddddddddddd\",\"proof\":[\"0xe886000000000000a0830818307108fb62adbcdd1d9b869a4cf8955dc211a286503febdf17ac599b2e\",\"0xf851a020be9ddd30723181a87b18a6d2bfa2b3323f30f1d0646aa9c7eea06af9e31c57a06da0dc6a9169f5f35fd7d057065203ba2c9fb225d8d6b4bb35f2dc1d2ba693b6808080808080808080808080808080\",\"0xf871808080808080808080808080a0d05f5bbfc8b0cf084848efcdd079e280384c937c8f30e5fe86dea0b4c3e23ebaa0ed9e169336203e22c92423e552c29f717f1024954239f90ee6940d9546149ad3a06841d65c5f2d895812aa6b18874d0aeae1cca5d73d3ee9277dc00bc84bee6ca78080\",\"0xf8479b20ddddddddddddddddddddddddddddddddddddddddddddddddddddaaa9ab78000000000000000000000000000000000000000000000000000000000000000000000000000000\"],\"value\":\"0xab78000000000000000000000000000000000000000000000000000000000000000000000000000000\"},{\"key\":\"0x00000000001eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee\",\"proof\":[\"0xe886000000000000a0830818307108fb62adbcdd1d9b869a4cf8955dc211a286503febdf17ac599b2e\",\"0xf851a020be9ddd30723181a87b18a6d2bfa2b3323f30f1d0646aa9c7eea06af9e31c57a06da0dc6a9169f5f35fd7d057065203ba2c9fb225d8d6b4bb35f2dc1d2ba693b6808080808080808080808080808080\",\"0xf871808080808080808080808080a0d05f5bbfc8b0cf084848efcdd079e280384c937c8f30e5fe86dea0b4c3e23ebaa0ed9e169336203e22c92423e552c29f717f1024954239f90ee6940d9546149ad3a06841d65c5f2d895812aa6b18874d0aeae1cca5d73d3ee9277dc00bc84bee6ca78080\",\"0xf8479b20eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeaaa9ab9a000000000000000000000000000000000000000000000000000000000000000000000000000000\"],\"value\":\"0xab9a000000000000000000000000000000000000000000000000000000000000000000000000000000\"}]}"); }
public void Shows_empty_values_when_account_is_missing() { IDb memDb = new MemDb(); StateTree tree = new StateTree(memDb); byte[] code = new byte[] { 1, 2, 3 }; Account account2 = Build.An.Account.WithBalance(2).TestObject; tree.Set(TestItem.AddressB, account2); tree.Commit(); TreeDumper dumper = new TreeDumper(); tree.Accept(dumper, memDb, tree.RootHash); Console.WriteLine(dumper.ToString()); ProofCollector proofCollector = new ProofCollector(TestItem.AddressA); tree.Accept(proofCollector, memDb, tree.RootHash); AccountProof proof = proofCollector.BuildResult(); Assert.AreEqual((UInt256)2, proof.Balance); Assert.AreEqual(UInt256.Zero, proof.Nonce); Assert.AreEqual(Keccak.OfAnEmptyString, proof.CodeHash); Assert.AreEqual(Keccak.EmptyTreeHash, proof.StorageRoot); }
public void Code_hash_is_correct() { StateTree tree = new StateTree(); byte[] code = new byte[] { 1, 2, 3 }; Account account1 = Build.An.Account.WithBalance(1).WithCode(code).TestObject; Account account2 = Build.An.Account.WithBalance(2).TestObject; tree.Set(TestItem.AddressA, account1); tree.Set(TestItem.AddressB, account2); tree.Commit(); ProofCollector proofCollector = new ProofCollector(TestItem.AddressA); tree.Accept(proofCollector, new MemDb(), tree.RootHash); AccountProof proof = proofCollector.BuildResult(); Assert.AreEqual(account1.CodeHash, proof.CodeHash); ProofCollector proofCollector2 = new ProofCollector(TestItem.AddressB); tree.Accept(proofCollector2, new MemDb(), tree.RootHash); AccountProof proof2 = proofCollector2.BuildResult(); Assert.AreEqual(Keccak.OfAnEmptyString, proof2.CodeHash); }
public void Storage_proofs_have_keys_set() { IDb memDb = new MemDb(); StateTree tree = new StateTree(memDb); StorageTree storageTree = new StorageTree(memDb); storageTree.Set(UInt256.Zero, Bytes.FromHexString("0xab12000000000000000000000000000000000000000000000000000000000000000000000000000000")); storageTree.Set(UInt256.One, Bytes.FromHexString("0xab34000000000000000000000000000000000000000000000000000000000000000000000000000000")); storageTree.Commit(); byte[] code = new byte[] { 1, 2, 3 }; Account account1 = Build.An.Account.WithBalance(1).WithStorageRoot(storageTree.RootHash).TestObject; Account account2 = Build.An.Account.WithBalance(2).TestObject; tree.Set(TestItem.AddressA, account1); tree.Set(TestItem.AddressB, account2); tree.Commit(); ProofCollector proofCollector = new ProofCollector(TestItem.AddressA, Bytes.FromHexString("0x0000000000000000000000000000000000000000000000000000000000000000"), Bytes.FromHexString("0x0000000000000000000000000000000000000000000000000000000000000001")); tree.Accept(proofCollector, memDb, tree.RootHash); AccountProof proof = proofCollector.BuildResult(); Assert.AreEqual("0x290decd9548b62a8d60345a988386fc84ba6bc95484008f6362f93160ef3e563", proof.StorageProofs[0].Key.Bytes.ToHexString(true)); Assert.AreEqual("0xb10e2d527612073b26eecdfd717e6a320cf44b4afac2b0732d9fcbe2b7fa0cf6", proof.StorageProofs[1].Key.Bytes.ToHexString(true)); }
public void Storage_proofs_have_values_set() { IDb memDb = new MemDb(); StateTree tree = new StateTree(memDb); StorageTree storageTree = new StorageTree(memDb); storageTree.Set(UInt256.Zero, Bytes.FromHexString("0xab12000000000000000000000000000000000000000000000000000000000000000000000000000000")); storageTree.Set(UInt256.One, Bytes.FromHexString("0xab34000000000000000000000000000000000000000000000000000000000000000000000000000000")); storageTree.Commit(); byte[] code = new byte[] { 1, 2, 3 }; Account account1 = Build.An.Account.WithBalance(1).WithStorageRoot(storageTree.RootHash).TestObject; Account account2 = Build.An.Account.WithBalance(2).TestObject; tree.Set(TestItem.AddressA, account1); tree.Set(TestItem.AddressB, account2); tree.Commit(); ProofCollector proofCollector = new ProofCollector(TestItem.AddressA, Bytes.FromHexString("0x0000000000000000000000000000000000000000000000000000000000000000"), Bytes.FromHexString("0x0000000000000000000000000000000000000000000000000000000000000001")); tree.Accept(proofCollector, memDb, tree.RootHash); AccountProof proof = proofCollector.BuildResult(); Assert.AreEqual("0xab12000000000000000000000000000000000000000000000000000000000000000000000000000000", proof.StorageProofs[0].Value.ToHexString(true)); Assert.AreEqual("0xab34000000000000000000000000000000000000000000000000000000000000000000000000000000", proof.StorageProofs[1].Value.ToHexString(true)); }
public void Storage_root_is_correct() { StateTree tree = new StateTree(); byte[] code = new byte[] { 1, 2, 3 }; Account account1 = Build.An.Account.WithBalance(1).WithStorageRoot(TestItem.KeccakA).TestObject; Account account2 = Build.An.Account.WithBalance(2).TestObject; tree.Set(TestItem.AddressA, account1); tree.Set(TestItem.AddressB, account2); tree.Commit(); ProofCollector proofCollector = new ProofCollector(TestItem.AddressA); tree.Accept(proofCollector, new MemDb(), tree.RootHash); AccountProof proof = proofCollector.BuildResult(); Assert.AreEqual(TestItem.KeccakA, proof.StorageRoot); ProofCollector proofCollector2 = new ProofCollector(TestItem.AddressB); tree.Accept(proofCollector2, new MemDb(), tree.RootHash); AccountProof proof2 = proofCollector2.BuildResult(); Assert.AreEqual(Keccak.EmptyTreeHash, proof2.StorageRoot); }
public void Balance_is_correct() { StateTree tree = new StateTree(); Account account1 = Build.An.Account.WithBalance(1).TestObject; Account account2 = Build.An.Account.WithBalance(2).TestObject; tree.Set(TestItem.AddressA, account1); tree.Set(TestItem.AddressB, account2); tree.Commit(); ProofCollector proofCollector = new ProofCollector(TestItem.AddressA); tree.Accept(proofCollector, new MemDb()); AccountProof proof = proofCollector.BuildResult(); Assert.AreEqual(UInt256.One, proof.Balance); ProofCollector proofCollector2 = new ProofCollector(TestItem.AddressB); tree.Accept(proofCollector2, new MemDb()); AccountProof proof2 = proofCollector2.BuildResult(); Assert.AreEqual(UInt256.One + 1, proof2.Balance); }
// https://github.com/ethereum/EIPs/issues/1186 public ResultWrapper <AccountProof> eth_getProof(Address accountAddress, byte[][] storageKeys, BlockParameter blockParameter) { BlockHeader header; try { header = _blockchainBridge.GetHeader(blockParameter); } catch (JsonRpcException ex) { return(ResultWrapper <AccountProof> .Fail(ex.Message, ex.ErrorType, null)); } ProofCollector proofCollector = new ProofCollector(accountAddress, storageKeys); _blockchainBridge.RunTreeVisitor(proofCollector, header.StateRoot); return(ResultWrapper <AccountProof> .Success(proofCollector.BuildResult())); }
public void Storage_proofs_have_values_set_complex_3_setup() { Keccak a = new Keccak("0x000000000000000000000000000000000000000000aaaaaaaaaaaaaaaaaaaaaa"); Keccak b = new Keccak("0x0000000000000000000000000bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"); Keccak c = new Keccak("0x00000000001ccccccccccccccccccccccccccccccccccccccccccccccccccccc"); Keccak d = new Keccak("0x00000000001ddddddddddddddddddddddddddddddddddddddddddddddddddddd"); Keccak e = new Keccak("0x00000000001eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee"); IDb memDb = new MemDb(); StateTree tree = new StateTree(memDb); StorageTree storageTree = new StorageTree(memDb); storageTree.Set(a.Bytes, Rlp.Encode(Bytes.FromHexString("0xab12000000000000000000000000000000000000000000000000000000000000000000000000000000"))); storageTree.Set(b.Bytes, Rlp.Encode(Bytes.FromHexString("0xab34000000000000000000000000000000000000000000000000000000000000000000000000000000"))); storageTree.Set(c.Bytes, Rlp.Encode(Bytes.FromHexString("0xab56000000000000000000000000000000000000000000000000000000000000000000000000000000"))); storageTree.Set(d.Bytes, Rlp.Encode(Bytes.FromHexString("0xab78000000000000000000000000000000000000000000000000000000000000000000000000000000"))); storageTree.Set(e.Bytes, Rlp.Encode(Bytes.FromHexString("0xab9a000000000000000000000000000000000000000000000000000000000000000000000000000000"))); storageTree.Commit(); byte[] code = new byte[] { 1, 2, 3 }; Account account1 = Build.An.Account.WithBalance(1).WithStorageRoot(storageTree.RootHash).TestObject; Account account2 = Build.An.Account.WithBalance(2).TestObject; tree.Set(TestItem.AddressA, account1); tree.Set(TestItem.AddressB, account2); tree.Commit(); TreeDumper dumper = new TreeDumper(); tree.Accept(dumper, memDb, tree.RootHash); Console.WriteLine(dumper.ToString()); ProofCollector proofCollector = new ProofCollector(TestItem.AddressA, new Keccak[] { a, b, c, d, e }); tree.Accept(proofCollector, memDb, tree.RootHash); AccountProof proof = proofCollector.BuildResult(); Assert.AreEqual("0xab12000000000000000000000000000000000000000000000000000000000000000000000000000000", proof.StorageProofs[0].Value.ToHexString(true)); Assert.AreEqual("0xab34000000000000000000000000000000000000000000000000000000000000000000000000000000", proof.StorageProofs[1].Value.ToHexString(true)); Assert.AreEqual("0xab56000000000000000000000000000000000000000000000000000000000000000000000000000000", proof.StorageProofs[2].Value.ToHexString(true)); Assert.AreEqual("0xab78000000000000000000000000000000000000000000000000000000000000000000000000000000", proof.StorageProofs[3].Value.ToHexString(true)); Assert.AreEqual("0xab9a000000000000000000000000000000000000000000000000000000000000000000000000000000", proof.StorageProofs[4].Value.ToHexString(true)); }
public void Storage_proofs_length_is_as_expected() { StateTree tree = new StateTree(); byte[] code = new byte[] { 1, 2, 3 }; Account account1 = Build.An.Account.WithBalance(1).WithStorageRoot(TestItem.KeccakA).TestObject; Account account2 = Build.An.Account.WithBalance(2).TestObject; tree.Set(TestItem.AddressA, account1); tree.Set(TestItem.AddressB, account2); tree.Commit(); ProofCollector proofCollector = new ProofCollector(TestItem.AddressA, Bytes.FromHexString("0x0000000000000000000000000000000000000000000000000000000000000000"), Bytes.FromHexString("0x0000000000000000000000000000000000000000000000000000000000000001")); tree.Accept(proofCollector, new MemDb(), tree.RootHash); AccountProof proof = proofCollector.BuildResult(); Assert.AreEqual(2, proof.StorageProofs.Length); }
public void Proof_path_is_filled() { StateTree tree = new StateTree(); byte[] code = new byte[] { 1, 2, 3 }; Account account1 = Build.An.Account.WithBalance(1).WithStorageRoot(TestItem.KeccakA).TestObject; Account account2 = Build.An.Account.WithBalance(2).TestObject; tree.Set(TestItem.AddressA, account1); tree.Set(TestItem.AddressB, account2); tree.Commit(); ProofCollector proofCollector = new ProofCollector(TestItem.AddressA); tree.Accept(proofCollector, new MemDb(), tree.RootHash); AccountProof proof = proofCollector.BuildResult(); Assert.AreEqual(3, proof.Proof.Length); }