public static void Main(string[] args)
    {
        StorageCell m = new StorageCell( );

        m.Put("Hello");
        Console.WriteLine(m.Get( ));
    }
Beispiel #2
0
        public void Non_existing()
        {
            StorageCell  storageCell = new StorageCell(_address1, UInt256.One);
            IReleaseSpec spec        = MuirGlacier.Instance;

            MemDb           stateDb         = new MemDb();
            TrieStore       trieStore       = new TrieStore(stateDb, Logger);
            StateProvider   provider        = new StateProvider(trieStore, new MemDb(), Logger);
            StorageProvider storageProvider = new StorageProvider(trieStore, provider, Logger);

            void CommitEverything()
            {
                storageProvider.Commit();
                storageProvider.CommitTrees(0);
                provider.Commit(spec);
                provider.CommitTree(0);
            }

            provider.CreateAccount(_address1, 1);
            storageProvider.Set(storageCell, new byte[] { 1 });
            CommitEverything();
            Keccak stateRoot0 = provider.StateRoot;

            StateReader reader =
                new StateReader(new TrieStore(stateDb, LimboLogs.Instance), Substitute.For <IDb>(), Logger);
            Keccak storageRoot = reader.GetStorageRoot(stateRoot0, _address1);

            reader.GetStorage(storageRoot, storageCell.Index + 1).Should().BeEquivalentTo(new byte[] { 0 });
            reader.GetStorage(Keccak.EmptyTreeHash, storageCell.Index + 1).Should().BeEquivalentTo(new byte[] { 0 });
        }
Beispiel #3
0
        public async Task Can_ask_about_storage_in_parallel()
        {
            StorageCell     storageCell     = new StorageCell(_address1, UInt256.One);
            IReleaseSpec    spec            = MuirGlacier.Instance;
            MemDb           stateDb         = new MemDb();
            TrieStore       trieStore       = new TrieStore(stateDb, Logger);
            StateProvider   provider        = new StateProvider(trieStore, new MemDb(), Logger);
            StorageProvider storageProvider = new StorageProvider(trieStore, provider, Logger);

            void UpdateStorageValue(byte[] newValue)
            {
                storageProvider.Set(storageCell, newValue);
            }

            void AddOneToBalance()
            {
                provider.AddToBalance(_address1, 1, spec);
            }

            void CommitEverything()
            {
                storageProvider.Commit();
                storageProvider.CommitTrees(0);
                provider.Commit(spec);
                provider.CommitTree(0);
            }

            provider.CreateAccount(_address1, 1);
            CommitEverything();

            AddOneToBalance();
            UpdateStorageValue(new byte[] { 1 });
            CommitEverything();
            Keccak stateRoot0 = provider.StateRoot;

            AddOneToBalance();
            UpdateStorageValue(new byte[] { 2 });
            CommitEverything();
            Keccak stateRoot1 = provider.StateRoot;

            AddOneToBalance();
            UpdateStorageValue(new byte[] { 3 });
            CommitEverything();
            Keccak stateRoot2 = provider.StateRoot;

            AddOneToBalance();
            UpdateStorageValue(new byte[] { 4 });
            CommitEverything();
            Keccak stateRoot3 = provider.StateRoot;

            StateReader reader =
                new StateReader(new TrieStore(stateDb, LimboLogs.Instance), Substitute.For <IDb>(), Logger);

            Task a = StartStorageTask(reader, stateRoot0, storageCell, new byte[] { 1 });
            Task b = StartStorageTask(reader, stateRoot1, storageCell, new byte[] { 2 });
            Task c = StartStorageTask(reader, stateRoot2, storageCell, new byte[] { 3 });
            Task d = StartStorageTask(reader, stateRoot3, storageCell, new byte[] { 4 });

            await Task.WhenAll(a, b, c, d);
        }
Beispiel #4
0
        public void Things_are_cold_to_start_with()
        {
            EvmState    evmState    = new EvmState(10000, new ExecutionEnvironment(), ExecutionType.Call, true, false);
            StorageCell storageCell = new StorageCell(TestItem.AddressA, 1);

            evmState.IsCold(TestItem.AddressA).Should().BeTrue();
            evmState.IsCold(storageCell).Should().BeTrue();
        }
        public void Can_collect_stats()
        {
            MemDb           memDb           = new MemDb();
            IDb             stateDb         = memDb;
            TrieStore       trieStore       = new TrieStore(stateDb, new MemoryLimit(0.MB()), Persist.EveryBlock, LimboLogs.Instance);
            StateProvider   stateProvider   = new StateProvider(trieStore, stateDb, LimboLogs.Instance);
            StorageProvider storageProvider = new StorageProvider(trieStore, stateProvider, LimboLogs.Instance);

            stateProvider.CreateAccount(TestItem.AddressA, 1);
            Keccak codeHash = stateProvider.UpdateCode(new byte[] { 1, 2, 3 });

            stateProvider.UpdateCodeHash(TestItem.AddressA, codeHash, Istanbul.Instance);

            stateProvider.CreateAccount(TestItem.AddressB, 1);
            Keccak codeHash2 = stateProvider.UpdateCode(new byte[] { 1, 2, 3, 4 });

            stateProvider.UpdateCodeHash(TestItem.AddressB, codeHash2, Istanbul.Instance);

            for (int i = 0; i < 1000; i++)
            {
                StorageCell storageCell = new StorageCell(TestItem.AddressA, (UInt256)i);
                storageProvider.Set(storageCell, new byte[] { (byte)i });
            }

            storageProvider.Commit();
            stateProvider.Commit(Istanbul.Instance);

            storageProvider.CommitTrees(0);
            stateProvider.CommitTree(0);
            storageProvider.CommitTrees(1);
            stateProvider.CommitTree(1);

            memDb.Delete(codeHash2); // missing code
            Keccak storageKey = new Keccak("0x345e54154080bfa9e8f20c99d7a0139773926479bc59e5b4f830ad94b6425332");

            memDb.Delete(storageKey); // deletes some storage
            trieStore.ClearCache();

            TrieStatsCollector statsCollector = new TrieStatsCollector(stateDb, LimboLogs.Instance);

            stateProvider.Accept(statsCollector, stateProvider.StateRoot);
            var stats = statsCollector.Stats;

            stats.CodeCount.Should().Be(1);
            stats.MissingCode.Should().Be(1);

            stats.NodesCount.Should().Be(1348);

            stats.StateBranchCount.Should().Be(1);
            stats.StateExtensionCount.Should().Be(1);
            stats.AccountCount.Should().Be(2);

            stats.StorageCount.Should().Be(1343);
            stats.StorageBranchCount.Should().Be(337);
            stats.StorageExtensionCount.Should().Be(12);
            stats.StorageLeafCount.Should().Be(994);
            stats.MissingStorage.Should().Be(1);
        }
Beispiel #6
0
        public void Can_warm_storage_up_twice()
        {
            EvmState    evmState    = new EvmState(10000, new ExecutionEnvironment(), ExecutionType.Call, true, false);
            Address     address     = TestItem.AddressA;
            StorageCell storageCell = new StorageCell(address, 1);

            evmState.WarmUp(storageCell);
            evmState.WarmUp(storageCell);
            evmState.IsCold(storageCell).Should().BeFalse();
        }
        public void Get_storage()
        {
            /* all testing will be touching just a single storage cell */
            var storageCell = new StorageCell(TestItem.AddressA, 1);

            /* to start with we need to create an account that we will be setting storage at */
            _stateProvider.CreateAccount(storageCell.Address, UInt256.One);
            _stateProvider.Commit(MuirGlacier.Instance);
            _stateProvider.CommitTree();

            /* at this stage we have an account with empty storage at the address that we want to test */

            byte[] initialValue = new byte[] { 1, 2, 3 };
            _storageProvider.Set(storageCell, initialValue);
            _storageProvider.Commit();
            _storageProvider.CommitTrees();
            _stateProvider.Commit(MuirGlacier.Instance);
            _stateProvider.CommitTree();

            var retrieved =
                _blockchainBridge.GetStorage(storageCell.Address, storageCell.Index, _stateProvider.StateRoot);

            retrieved.Should().BeEquivalentTo(initialValue);

            /* at this stage we set the value in storage to 1,2,3 at the tested storage cell */

            /* Now we are testing scenario where the storage is being changed by the block processor.
            *  To do that we create some different storage / state access stack that represents the processor.
            *  It is a different stack of objects than the one that is used by the blockchain bridge. */

            byte[] newValue = new byte[] { 1, 2, 3, 4, 5 };

            StateProvider processorStateProvider =
                new StateProvider(_dbProvider.StateDb, _dbProvider.CodeDb, LimboLogs.Instance);

            processorStateProvider.StateRoot = _stateProvider.StateRoot;

            StorageProvider processorStorageProvider =
                new StorageProvider(_dbProvider.StateDb, processorStateProvider, LimboLogs.Instance);

            processorStorageProvider.Set(storageCell, newValue);
            processorStorageProvider.Commit();
            processorStorageProvider.CommitTrees();
            processorStateProvider.Commit(MuirGlacier.Instance);
            processorStateProvider.CommitTree();

            /* At this stage the DB should have the storage value updated to 5.
             * We will try to retrieve the value by taking the state root from the processor.*/

            retrieved =
                _blockchainBridge.GetStorage(storageCell.Address, storageCell.Index, processorStateProvider.StateRoot);
            retrieved.Should().BeEquivalentTo(newValue);

            /* If it failed then it means that the blockchain bridge cached the previous call value */
        }
Beispiel #8
0
 public void ReportStorageRead(StorageCell storageCell)
 {
     for (int index = 0; index < _txTracers.Count; index++)
     {
         ITxTracer innerTracer = _txTracers[index];
         if (innerTracer.IsTracingStorage)
         {
             innerTracer.ReportStorageRead(storageCell);
         }
     }
 }
Beispiel #9
0
 public void ReportStorageRead(StorageCell storageCell)
 {
     for (var index = 0; index < _txTracers.Length; index++)
     {
         var innerTracer = _txTracers[index];
         if (innerTracer.IsTracingStorage)
         {
             innerTracer.ReportStorageRead(storageCell);
         }
     }
 }
Beispiel #10
0
        public void Storage_to_commit_keeps_it_warm()
        {
            EvmState    parentEvmState = new EvmState(10000, new ExecutionEnvironment(), ExecutionType.Call, true, false);
            EvmState    evmState       = new EvmState(10000, new ExecutionEnvironment(), ExecutionType.Call, true, false);
            StorageCell storageCell    = new StorageCell(TestItem.AddressA, 1);

            evmState.WarmUp(storageCell);

            evmState.CommitToParent(parentEvmState);
            parentEvmState.IsCold(storageCell).Should().BeFalse();
        }
Beispiel #11
0
 public void ReportStorageChange(StorageCell storageCell, byte[] before, byte[] after)
 {
     for (var index = 0; index < _txTracers.Length; index++)
     {
         var innerTracer = _txTracers[index];
         if (innerTracer.IsTracingStorage)
         {
             innerTracer.ReportStorageChange(storageCell, before, after);
         }
     }
 }
 protected void AssertStorage(StorageCell storageCell, UInt256 expectedValue)
 {
     _callIndex++;
     if (!TestState.AccountExists(storageCell.Address))
     {
         Assert.AreEqual(expectedValue.ToBigEndian().WithoutLeadingZeros().ToArray(), new byte[] { 0 }, $"storage {storageCell}, call {_callIndex}");
     }
     else
     {
         byte[] actualValue = Storage.Get(storageCell);
         Assert.AreEqual(expectedValue.ToBigEndian().WithoutLeadingZeros().ToArray(), actualValue, $"storage {storageCell}, call {_callIndex}");
     }
 }
Beispiel #13
0
 private Task StartStorageTask(StateReader reader, Keccak stateRoot, StorageCell storageCell, byte[] value)
 {
     return(Task.Run(
                () =>
     {
         for (int i = 0; i < 1000; i++)
         {
             Keccak storageRoot = reader.GetStorageRoot(stateRoot, storageCell.Address);
             byte[] result = reader.GetStorage(storageRoot, storageCell.Index);
             result.Should().BeEquivalentTo(value);
         }
     }));
 }
 protected void AssertStorage(StorageCell storageCell, BigInteger expectedValue)
 {
     _callIndex++;
     if (!TestState.AccountExists(storageCell.Address))
     {
         Assert.AreEqual(expectedValue.ToBigEndianByteArray(), new byte[1] {
             0
         }, $"storage {storageCell}, call {_callIndex}");
     }
     else
     {
         byte[] actualValue = Storage.Get(storageCell);
         Assert.AreEqual(expectedValue.ToBigEndianByteArray(), actualValue, $"storage {storageCell}, call {_callIndex}");
     }
 }
        public void Regression_mainnet_226522()
        {
            _blockNumber = 1;
            Address     deployed    = ContractAddress.From(TestItem.AddressC, 0);
            StorageCell storageCell = new StorageCell(deployed, 1);

            byte[] deployedCode = new byte[106]; // cost is * 200

            byte[] initCode = Prepare.EvmCode
                              .PushData(1)
                              .PushData(1)
                              .Op(Instruction.SSTORE)
                              .PushData(0)
                              .PushData(1)
                              .Op(Instruction.SSTORE) // here we reset storage so we would get refund of 15000 gas
                              .ForInitOf(deployedCode).Done;

            byte[] createCode = Prepare.EvmCode
                                .Create(initCode, 0)
                                .PushData(0)
                                .Op(Instruction.SSTORE)
                                .Done;

            TestState.CreateAccount(TestItem.AddressC, 1.Ether());
            Keccak createCodeHash = TestState.UpdateCode(createCode);

            TestState.UpdateCodeHash(TestItem.AddressC, createCodeHash, Spec);

            byte[] code = Prepare.EvmCode
                          .Call(TestItem.AddressC, 32000 + 20003 + 20000 + 5000 + 500 + 0) // not enough
                          .Done;

            var receipt = Execute(code);

            byte[] result = Storage.Get(storageCell);
            Assert.AreEqual(new byte[] { 0 }, result, "storage reverted");
            Assert.AreEqual(83199, receipt.GasSpent, "with refund");

            byte[] returnData = Storage.Get(new StorageCell(TestItem.AddressC, 0));
            Assert.AreEqual(deployed.Bytes, returnData, "address returned");
        }
Beispiel #16
0
 public void StorageCellClicked(StorageCell cell)
 {
     if(cell!=null){
         if(fuseISODlg.gameObject.activeInHierarchy){
             //fuseISODlg.initFuseISODlgCell(cell.equipData.equipDef.id);
         }
     }
 }
Beispiel #17
0
 public void StorageCellClicked(StorageCell cell)
 {
     //		Debug.LogError("StorageCellClicked");
     TeamDlg.instance.StorageCellClicked (cell);
 }
Beispiel #18
0
        public async Task Get_storage()
        {
            IDbProvider dbProvider = await TestMemDbProvider.InitAsync();

            /* all testing will be touching just a single storage cell */
            StorageCell storageCell = new StorageCell(_address1, UInt256.One);

            TrieStore       trieStore = new TrieStore(dbProvider.StateDb, Logger);
            StateProvider   state     = new StateProvider(trieStore, dbProvider.CodeDb, Logger);
            StorageProvider storage   = new StorageProvider(trieStore, state, Logger);

            /* to start with we need to create an account that we will be setting storage at */
            state.CreateAccount(storageCell.Address, UInt256.One);
            state.Commit(MuirGlacier.Instance);
            state.CommitTree(1);

            /* at this stage we have an account with empty storage at the address that we want to test */

            byte[] initialValue = new byte[] { 1, 2, 3 };
            storage.Set(storageCell, initialValue);
            storage.Commit();
            storage.CommitTrees(2);
            state.Commit(MuirGlacier.Instance);
            state.CommitTree(2);

            StateReader reader = new StateReader(
                new TrieStore(dbProvider.StateDb, LimboLogs.Instance), dbProvider.CodeDb, Logger);

            var account   = reader.GetAccount(state.StateRoot, _address1);
            var retrieved = reader.GetStorage(account.StorageRoot, storageCell.Index);

            retrieved.Should().BeEquivalentTo(initialValue);

            /* at this stage we set the value in storage to 1,2,3 at the tested storage cell */

            /* Now we are testing scenario where the storage is being changed by the block processor.
            *  To do that we create some different storage / state access stack that represents the processor.
            *  It is a different stack of objects than the one that is used by the blockchain bridge. */

            byte[] newValue = new byte[] { 1, 2, 3, 4, 5 };

            StateProvider processorStateProvider =
                new StateProvider(trieStore, new MemDb(), LimboLogs.Instance);

            processorStateProvider.StateRoot = state.StateRoot;

            StorageProvider processorStorageProvider =
                new StorageProvider(trieStore, processorStateProvider, LimboLogs.Instance);

            processorStorageProvider.Set(storageCell, newValue);
            processorStorageProvider.Commit();
            processorStorageProvider.CommitTrees(3);
            processorStateProvider.Commit(MuirGlacier.Instance);
            processorStateProvider.CommitTree(3);

            /* At this stage the DB should have the storage value updated to 5.
             * We will try to retrieve the value by taking the state root from the processor.*/

            retrieved =
                reader.GetStorage(processorStateProvider.GetStorageRoot(storageCell.Address), storageCell.Index);
            retrieved.Should().BeEquivalentTo(newValue);

            /* If it failed then it means that the blockchain bridge cached the previous call value */
        }
Beispiel #19
0
 private bool hitSlot(StorageCell cell)
 {
     Ray ray = this.uiCamera.ScreenPointToRay(Input.mousePosition);
     RaycastHit hit = new RaycastHit();
     if(cell.collider.Raycast(ray,out hit,10000)){
         Debug.Log("hit "+cell.gameObject.name);
         return true;
     }else{
         return false;
     }
 }
        public void Chaotic_test()
        {
            const int accountsCount = 100;

            CryptoRandom random = new CryptoRandom();
            List <AddressWithStorage> addressesWithStorage = new List <AddressWithStorage>();

            for (int i = 0; i < accountsCount; i++)
            {
                AddressWithStorage addressWithStorage = new AddressWithStorage();
                addressWithStorage.StorageCells = new StorageCell[i];
                byte[] addressBytes = random.GenerateRandomBytes(20);
                addressWithStorage.Address = new Address(addressBytes);

                for (int j = 0; j < i; j++)
                {
                    byte[]      storageIndex = random.GenerateRandomBytes(32);
                    UInt256     index        = new UInt256(storageIndex);
                    StorageCell storageCell  = new StorageCell(addressWithStorage.Address, index);
                    addressWithStorage.StorageCells[j] = storageCell;
                }

                addressesWithStorage.Add(addressWithStorage);
            }

            IDb       memDb     = new MemDb();
            TrieStore trieStore = new TrieStore(memDb, LimboLogs.Instance);
            StateTree tree      = new StateTree(trieStore, LimboLogs.Instance);

            for (int i = 0; i < accountsCount; i++)
            {
                Account     account     = Build.An.Account.WithBalance((UInt256)i).TestObject;
                StorageTree storageTree = new StorageTree(trieStore, Keccak.EmptyTreeHash, LimboLogs.Instance);
                for (int j = 0; j < i; j++)
                {
                    storageTree.Set(addressesWithStorage[i].StorageCells[j].Index, new byte[1] {
                        1
                    });
                }

                storageTree.UpdateRootHash();
                storageTree.Commit(0);

                account = account.WithChangedStorageRoot(storageTree.RootHash);
                tree.Set(addressesWithStorage[i].Address, account);
            }

            tree.UpdateRootHash();
            tree.Commit(0);

            for (int i = 0; i < accountsCount; i++)
            {
                AccountProofCollector collector = new AccountProofCollector(addressesWithStorage[i].Address, addressesWithStorage[i].StorageCells.Select(sc => sc.Index).ToArray());
                tree.Accept(collector, tree.RootHash, true);

                AccountProof accountProof = collector.BuildResult();
                accountProof.Address.Should().Be(addressesWithStorage[i].Address);
                accountProof.Balance.Should().Be((UInt256)i);
                accountProof.Nonce.Should().Be(0);
                accountProof.CodeHash.Should().Be(Keccak.OfAnEmptyString);
                if (i != 0)
                {
                    accountProof.StorageRoot.Should().NotBe(Keccak.EmptyTreeHash);
                }
                accountProof.StorageProofs.Length.Should().Be(i);

                for (int j = 0; j < i; j++)
                {
                    byte[] indexBytes = new byte[32];
                    addressesWithStorage[i].StorageCells[j].Index.ToBigEndian(indexBytes.AsSpan());
                    accountProof.StorageProofs[j].Key.ToHexString().Should().Be(indexBytes.ToHexString(), $"{i} {j}");

                    TrieNode node = new TrieNode(NodeType.Unknown, accountProof.StorageProofs[j].Proof.Last());
                    node.ResolveNode(null);
                    // TestContext.Write($"|[{i},{j}]");
                    if (node.Value.Length != 1)
                    {
                        TestContext.WriteLine();
                        TestContext.WriteLine(addressesWithStorage[i].Address);
                        TestContext.WriteLine(i);
                        foreach (StorageCell storageCell in addressesWithStorage[i].StorageCells)
                        {
                            TestContext.WriteLine("storage: " + storageCell.Index);
                        }
                    }

                    node.Value.Should().BeEquivalentTo(new byte[] { 1 });
                }
            }
        }
Beispiel #21
0
 public void WarmUp(StorageCell storageCell)
 {
     AccessedStorageCells.Add(storageCell);
 }
Beispiel #22
0
 public void ReportStorageRead(StorageCell storageCell)
 {
     throw new NotImplementedException();
 }
Beispiel #23
0
 public void ReportStorageChange(StorageCell storageCell, byte[] before, byte[] after)
 {
     throw new NotImplementedException();
 }
Beispiel #24
0
 private void ShowHighLight(StorageCell cell, bool highLight)
 {
     this.isHighLight = false;
     if(cell.equipData == null){
         if (highLight) {
             cell.Bg.spriteName = (storagePanel.currentFilter == StoragePanel.FILTER.OWN_ISO)?ISO_Checked:Gear_Checked;
         }else{
             cell.Bg.spriteName = (storagePanel.currentFilter == StoragePanel.FILTER.OWN_ISO)?ISO_UnChecked:Gear_UnChecked;
         }
         if(storagePanel != null)
         {
             storagePanel.setHighlightOnSlot(null);
             storagePanel.SetInfoBar (null,null,null);
         }
     }else{
         if (highLight) {
             cell.Bg.spriteName = (cell.equipData.equipDef.type == EquipData.Type.ISO)? ISO_Checked:Gear_Checked;
             cell.Bg.MakePixelPerfect ();
             if(storagePanel != null)
             {
                 storagePanel.setHighlightOnSlot(null);
                 storagePanel.SetInfoBar (this.equipData,this.Icon_Gear.atlas,this.Icon_Gear.spriteName);
             }
         } else {
             cell.Bg.spriteName = (cell.equipData.equipDef.type == EquipData.Type.ISO)? ISO_UnChecked:Gear_UnChecked;
             cell.Bg.MakePixelPerfect ();
         }
     }
 }
 public void ReportStorageRead(StorageCell storageCell)
 {
     _currentTxTracer.ReportStorageRead(storageCell);
 }
Beispiel #26
0
 public bool IsCold(StorageCell storageCell)
 {
     return(_accessedStorageKeys is null || !AccessedStorageCells.Contains(storageCell));
 }
Beispiel #27
0
 public void ReportStorageRead(StorageCell storageCell)
 => throw new InvalidOperationException(ErrorMessage);
Beispiel #28
0
 public void ReportStorageRead(StorageCell storageCell)
 {
     // implicit knowledge here that if we read storage then for sure we have at least asked for the account's balance
     // and so we do not need to add account to Accounts
     Storages.Add(storageCell);
 }
        public void _Test_storage_failed_case(string historicallyFailingCase)
        {
            string[] lines        = historicallyFailingCase.Split(Environment.NewLine);
            int      storageCount = lines.Length - 2;

            IDb       memDb     = new MemDb();
            TrieStore trieStore = new TrieStore(memDb, LimboLogs.Instance);
            StateTree tree      = new StateTree(trieStore, LimboLogs.Instance);

            Address address      = new Address(Bytes.FromHexString(lines[0]));
            int     accountIndex = int.Parse(lines[1]);

            UInt256[] indexes = new UInt256[storageCount];
            for (int j = 0; j < storageCount; j++)
            {
                indexes[j] = UInt256.Parse(lines[j + 2].Replace("storage: ", string.Empty));
            }

            AddressWithStorage addressWithStorage = new AddressWithStorage();

            addressWithStorage.StorageCells = new StorageCell[storageCount];
            addressWithStorage.Address      = address;

            StorageTree storageTree = new StorageTree(trieStore, Keccak.EmptyTreeHash, LimboLogs.Instance);

            for (int j = 0; j < storageCount; j++)
            {
                UInt256     index       = UInt256.Parse(lines[j + 2].Replace("storage: ", string.Empty));
                StorageCell storageCell = new StorageCell(address, index);
                addressWithStorage.StorageCells[j] = storageCell;
                byte[] rawKey = new byte[32];
                addressWithStorage.StorageCells[j].Index.ToBigEndian(rawKey);
                TestContext.WriteLine($"Set {Keccak.Compute(rawKey).Bytes.ToHexString()}");
                storageTree.Set(addressWithStorage.StorageCells[j].Index, new byte[] { 1 });
                storageTree.UpdateRootHash();
                storageTree.Commit(0);
            }

            Account account = Build.An.Account.WithBalance((UInt256)accountIndex).WithStorageRoot(storageTree.RootHash).TestObject;

            tree.Set(addressWithStorage.Address, account);

            tree.UpdateRootHash();
            tree.Commit(0);

            TreeDumper treeDumper = new TreeDumper();

            tree.Accept(treeDumper, tree.RootHash, true);
            TestContext.WriteLine(treeDumper.ToString());

            AccountProofCollector collector = new AccountProofCollector(address, indexes);

            tree.Accept(collector, tree.RootHash, true);

            AccountProof accountProof = collector.BuildResult();

            accountProof.Address.Should().Be(address);
            accountProof.Balance.Should().Be((UInt256)accountIndex);
            accountProof.Nonce.Should().Be(0);
            accountProof.CodeHash.Should().Be(Keccak.OfAnEmptyString);
            if (accountIndex != 0)
            {
                accountProof.StorageRoot.Should().NotBe(Keccak.EmptyTreeHash);
            }
            accountProof.StorageProofs.Length.Should().Be(accountIndex);

            for (int j = 0; j < accountProof.StorageProofs.Length; j++)
            {
                TrieNode node = new TrieNode(NodeType.Unknown, accountProof.StorageProofs[j].Proof.Last());
                node.ResolveNode(new TrieStore(memDb, NullLogManager.Instance));
                if (node.Value.Length != 1)
                {
                    TestContext.WriteLine($"{j}");
                    // throw new InvalidDataException($"{j}");
                }
            }
        }
Beispiel #30
0
 public static async void UpdateStorageCell(StorageCell storageCell)
 {
     await SQLDatabase.UpdateAsync(storageCell);
 }
 public void ReportStorageChange(StorageCell storageCell, byte[] before, byte[] after)
 {
     _currentTxTracer.ReportStorageChange(storageCell, before, after);
 }
 public void ReportStorageRead(StorageCell storageCell) => throw new OperationCanceledException(ErrorMessage);
Beispiel #33
0
 public void ReportStorageChange(StorageCell storageCell, byte[] before, byte[] after) => throw new InvalidOperationException(ErrorMessage);
Beispiel #34
0
 public Change(ChangeType changeType, StorageCell storageCell, byte[] value)
 {
     StorageCell = storageCell;
     Value = value;
     ChangeType = changeType;
 }