public void GlobalSetup() { ByteCode = Bytes.FromHexString(Environment.GetEnvironmentVariable("NETH.BENCHMARK.BYTECODE")); Console.WriteLine($"Running benchmark for bytecode {ByteCode?.ToHexString()}"); IDb codeDb = new StateDb(); ISnapshotableDb stateDb = new StateDb(); _stateProvider = new StateProvider(stateDb, codeDb, LimboLogs.Instance); _stateProvider.CreateAccount(Address.Zero, 1000.Ether()); _stateProvider.Commit(_spec); _storageProvider = new StorageProvider(stateDb, _stateProvider, LimboLogs.Instance); _virtualMachine = new VirtualMachine(_stateProvider, _storageProvider, _blockhashProvider, MainnetSpecProvider.Instance, LimboLogs.Instance); _environment = new ExecutionEnvironment(); _environment.ExecutingAccount = Address.Zero; _environment.CodeSource = Address.Zero; _environment.Originator = Address.Zero; _environment.Sender = Address.Zero; _environment.CodeInfo = new CodeInfo(ByteCode); _environment.GasPrice = 0; _environment.Value = 0; _environment.TransferValue = 0; _environment.CurrentBlock = _header; _evmState = new EvmState(long.MaxValue, _environment, ExecutionType.Transaction, false, true, false); }
public void GlobalSetup() { TrieStore trieStore = new(new MemDb(), new OneLoggerLogManager(NullLogger.Instance)); IKeyValueStore codeDb = new MemDb(); _stateProvider = new StateProvider(trieStore, codeDb, new OneLoggerLogManager(NullLogger.Instance)); _stateProvider.CreateAccount(Address.Zero, 1000.Ether()); _stateProvider.Commit(_spec); _storageProvider = new StorageProvider(trieStore, _stateProvider, new OneLoggerLogManager(NullLogger.Instance)); _worldState = new WorldState(_stateProvider, _storageProvider); Console.WriteLine(MuirGlacier.Instance); _virtualMachine = new VirtualMachine(_blockhashProvider, MainnetSpecProvider.Instance, new OneLoggerLogManager(NullLogger.Instance)); _environment = new ExecutionEnvironment { ExecutingAccount = Address.Zero, CodeSource = Address.Zero, Caller = Address.Zero, CodeInfo = new CodeInfo(Bytecode), Value = 0, TransferValue = 0, TxExecutionContext = new TxExecutionContext(_header, Address.Zero, 0) }; _evmState = new EvmState(100_000_000L, _environment, ExecutionType.Transaction, true, _worldState.TakeSnapshot(), false); }
public void Can_dispose_after_init() { EvmState evmState = CreateEvmState(); evmState.InitStacks(); evmState.Dispose(); }
public void Nothing_to_commit() { EvmState parentEvmState = new EvmState(10000, new ExecutionEnvironment(), ExecutionType.Call, true, false); EvmState evmState = new EvmState(10000, new ExecutionEnvironment(), ExecutionType.Call, true, false); evmState.CommitToParent(parentEvmState); }
public void GlobalSetup() { ByteCode = Bytes.FromHexString(Environment.GetEnvironmentVariable("NETH.BENCHMARK.BYTECODE") ?? string.Empty); Console.WriteLine($"Running benchmark for bytecode {ByteCode?.ToHexString()}"); TrieStore trieStore = new(new MemDb(), new OneLoggerLogManager(NullLogger.Instance)); IKeyValueStore codeDb = new MemDb(); _stateProvider = new StateProvider(trieStore, codeDb, new OneLoggerLogManager(NullLogger.Instance)); _stateProvider.CreateAccount(Address.Zero, 1000.Ether()); _stateProvider.Commit(_spec); _storageProvider = new StorageProvider(trieStore, _stateProvider, new OneLoggerLogManager(NullLogger.Instance)); _worldState = new WorldState(_stateProvider, _storageProvider); _virtualMachine = new VirtualMachine(_blockhashProvider, MainnetSpecProvider.Instance, LimboLogs.Instance); _environment = new ExecutionEnvironment { ExecutingAccount = Address.Zero, CodeSource = Address.Zero, Caller = Address.Zero, CodeInfo = new CodeInfo(ByteCode), Value = 0, TransferValue = 0, TxExecutionContext = new TxExecutionContext(_header, Address.Zero, 0) }; _evmState = new EvmState(long.MaxValue, _environment, ExecutionType.Transaction, true, _worldState.TakeSnapshot(), false); }
public void Can_dispose_after_init() { EvmState evmState = new EvmState(10000, new ExecutionEnvironment(), ExecutionType.Call, true, false); evmState.InitStacks(); evmState.Dispose(); }
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 Commit_adds_refunds() { EvmState parentEvmState = new EvmState(10000, new ExecutionEnvironment(), ExecutionType.Call, true, false); EvmState evmState = new EvmState(10000, new ExecutionEnvironment(), ExecutionType.Call, true, false); evmState.CommitToParent(parentEvmState); parentEvmState.Refund.Should().Be(evmState.Refund); }
public void Things_are_cold_to_start_with() { EvmState evmState = CreateEvmState(); StorageCell storageCell = new(TestItem.AddressA, 1); evmState.IsCold(TestItem.AddressA).Should().BeTrue(); evmState.IsCold(storageCell).Should().BeTrue(); }
public void Nothing_to_commit() { EvmState parentEvmState = CreateEvmState(); using (EvmState evmState = CreateEvmState(parentEvmState)) { evmState.CommitToParent(parentEvmState); } }
public void Can_warm_address_up_twice() { EvmState evmState = CreateEvmState(); Address address = TestItem.AddressA; evmState.WarmUp(address); evmState.WarmUp(address); evmState.IsCold(address).Should().BeFalse(); }
public void Can_warm_address_up_twice() { EvmState evmState = new EvmState(10000, new ExecutionEnvironment(), ExecutionType.Call, true, false); Address address = TestItem.AddressA; evmState.WarmUp(address); evmState.WarmUp(address); evmState.IsCold(address).Should().BeFalse(); }
public void Address_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); evmState.WarmUp(TestItem.AddressA); evmState.CommitToParent(parentEvmState); parentEvmState.IsCold(TestItem.AddressA).Should().BeFalse(); }
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 Destroy_list_is_committed() { EvmState parentEvmState = new EvmState(10000, new ExecutionEnvironment(), ExecutionType.Call, true, false); EvmState evmState = new EvmState(10000, new ExecutionEnvironment(), ExecutionType.Call, true, false); evmState.DestroyList.Add(Address.Zero); evmState.CommitToParent(parentEvmState); parentEvmState.DestroyList.Contains(Address.Zero).Should().BeTrue(); }
public void Can_warm_storage_up_twice() { EvmState evmState = CreateEvmState(); Address address = TestItem.AddressA; StorageCell storageCell = new(address, 1); evmState.WarmUp(storageCell); evmState.WarmUp(storageCell); evmState.IsCold(storageCell).Should().BeFalse(); }
public void Address_to_restore_keeps_it_cold() { EvmState parentEvmState = CreateEvmState(); using (EvmState evmState = CreateEvmState(parentEvmState)) { evmState.WarmUp(TestItem.AddressA); } parentEvmState.IsCold(TestItem.AddressA).Should().BeTrue(); }
public void Restore_doesnt_add_refunds() { EvmState parentEvmState = CreateEvmState(); using (EvmState evmState = CreateEvmState(parentEvmState)) { evmState.Refund = 333; } parentEvmState.Refund.Should().Be(0); }
public void Destroy_list_is_restored() { EvmState parentEvmState = CreateEvmState(); using (EvmState evmState = CreateEvmState(parentEvmState)) { evmState.DestroyList.Add(Address.Zero); } parentEvmState.DestroyList.Contains(Address.Zero).Should().BeFalse(); }
public void Logs_are_committed() { EvmState parentEvmState = new EvmState(10000, new ExecutionEnvironment(), ExecutionType.Call, true, false); EvmState evmState = new EvmState(10000, new ExecutionEnvironment(), ExecutionType.Call, true, false); LogEntry logEntry = new LogEntry(Address.Zero, Bytes.Empty, Array.Empty <Keccak>()); evmState.Logs.Add(logEntry); evmState.CommitToParent(parentEvmState); parentEvmState.Logs.Contains(logEntry).Should().BeTrue(); }
public void Address_to_commit_keeps_it_warm() { EvmState parentEvmState = CreateEvmState(); using (EvmState evmState = CreateEvmState(parentEvmState)) { evmState.WarmUp(TestItem.AddressA); evmState.CommitToParent(parentEvmState); } parentEvmState.IsCold(TestItem.AddressA).Should().BeFalse(); }
public void Commit_adds_refunds() { EvmState parentEvmState = CreateEvmState(); using (EvmState evmState = CreateEvmState(parentEvmState)) { evmState.Refund = 333; evmState.CommitToParent(parentEvmState); } parentEvmState.Refund.Should().Be(333); }
public void Storage_to_restore_keeps_it_cold() { EvmState parentEvmState = CreateEvmState(); StorageCell storageCell = new(TestItem.AddressA, 1); using (EvmState evmState = CreateEvmState(parentEvmState)) { evmState.WarmUp(storageCell); } parentEvmState.IsCold(storageCell).Should().BeTrue(); }
public void Logs_are_restored() { EvmState parentEvmState = CreateEvmState(); LogEntry logEntry = new(Address.Zero, Bytes.Empty, Array.Empty <Keccak>()); using (EvmState evmState = CreateEvmState(parentEvmState)) { evmState.Logs.Add(logEntry); } parentEvmState.Logs.Contains(logEntry).Should().BeFalse(); }
public void Destroy_list_is_committed() { EvmState parentEvmState = CreateEvmState(); using (EvmState evmState = CreateEvmState(parentEvmState)) { evmState.DestroyList.Add(Address.Zero); evmState.CommitToParent(parentEvmState); } parentEvmState.DestroyList.Contains(Address.Zero).Should().BeTrue(); }
public void Storage_to_commit_keeps_it_warm() { EvmState parentEvmState = CreateEvmState(); StorageCell storageCell = new(TestItem.AddressA, 1); using (EvmState evmState = CreateEvmState(parentEvmState)) { evmState.WarmUp(storageCell); evmState.CommitToParent(parentEvmState); } parentEvmState.IsCold(storageCell).Should().BeFalse(); }
public void Can_warm_up_many() { EvmState evmState = new EvmState(10000, new ExecutionEnvironment(), ExecutionType.Call, true, false); for (int i = 0; i < TestItem.Addresses.Length; i++) { evmState.WarmUp(TestItem.Addresses[i]); evmState.WarmUp(new StorageCell(TestItem.Addresses[i], 1)); } for (int i = 0; i < TestItem.Addresses.Length; i++) { evmState.IsCold(TestItem.Addresses[i]).Should().BeFalse(); evmState.IsCold(new StorageCell(TestItem.Addresses[i], 1)).Should().BeFalse(); } }
public void Can_warm_up_many() { EvmState evmState = CreateEvmState(); for (int i = 0; i < TestItem.Addresses.Length; i++) { evmState.WarmUp(TestItem.Addresses[i]); evmState.WarmUp(new StorageCell(TestItem.Addresses[i], 1)); } for (int i = 0; i < TestItem.Addresses.Length; i++) { evmState.IsCold(TestItem.Addresses[i]).Should().BeFalse(); evmState.IsCold(new StorageCell(TestItem.Addresses[i], 1)).Should().BeFalse(); } }
private static EvmState CreateEvmState(EvmState parentEvmState = null, bool isContinuation = false) => parentEvmState is null ? new EvmState(10000, new ExecutionEnvironment(), ExecutionType.Call, true, Snapshot.Empty, isContinuation) : new EvmState(10000, new ExecutionEnvironment(), ExecutionType.Call, false, Snapshot.Empty, 0, 0, false, parentEvmState, isContinuation, false);
protected void RunTest(VirtualMachineTest test) { TestContext.WriteLine($"Running {test.GetType().FullName}"); VirtualMachine machine = new VirtualMachine(_stateProvider, _storageProvider, _blockhashProvider, _specProvider, _logManager); ExecutionEnvironment environment = new ExecutionEnvironment(); environment.Value = test.Execution.Value; environment.CallDepth = 0; environment.Sender = test.Execution.Caller; environment.ExecutingAccount = test.Execution.Address; BlockHeader header = new BlockHeader( Keccak.OfAnEmptyString, Keccak.OfAnEmptySequenceRlp, test.Environment.CurrentCoinbase, test.Environment.CurrentDifficulty, test.Environment.CurrentNumber, (long)test.Environment.CurrentGasLimit, test.Environment.CurrentTimestamp, Bytes.Empty); environment.CurrentBlock = header; environment.GasPrice = test.Execution.GasPrice; environment.InputData = test.Execution.Data; environment.CodeInfo = new CodeInfo(test.Execution.Code); environment.Originator = test.Execution.Origin; foreach (KeyValuePair <Address, AccountState> accountState in test.Pre) { foreach (KeyValuePair <UInt256, byte[]> storageItem in accountState.Value.Storage) { _storageProvider.Set(new StorageCell(accountState.Key, storageItem.Key), storageItem.Value); if (accountState.Key.Equals(test.Execution.Address)) { _storageProvider.Set(new StorageCell(accountState.Key, storageItem.Key), storageItem.Value); } } _stateProvider.UpdateCode(accountState.Value.Code); _stateProvider.CreateAccount(accountState.Key, accountState.Value.Balance); Keccak codeHash = _stateProvider.UpdateCode(accountState.Value.Code); _stateProvider.UpdateCodeHash(accountState.Key, codeHash, Olympic.Instance); for (int i = 0; i < accountState.Value.Nonce; i++) { _stateProvider.IncrementNonce(accountState.Key); } } EvmState state = new EvmState((long)test.Execution.Gas, environment, ExecutionType.Transaction, true, false); _storageProvider.Commit(); _stateProvider.Commit(Olympic.Instance); TransactionSubstate substate = machine.Run(state, NullTxTracer.Instance); if (test.Out == null) { Assert.NotNull(substate.Error); return; } Assert.True(Bytes.AreEqual(test.Out, substate.Output), $"Exp: {test.Out.ToHexString(true)} != Actual: {substate.Output.ToHexString(true)}"); Assert.AreEqual((long)test.Gas, state.GasAvailable, "gas available"); foreach (KeyValuePair <Address, AccountState> accountState in test.Post) { bool accountExists = _stateProvider.AccountExists(accountState.Key); UInt256 balance = accountExists ? _stateProvider.GetBalance(accountState.Key) : 0; UInt256 nonce = accountExists ? _stateProvider.GetNonce(accountState.Key) : 0; Assert.AreEqual(accountState.Value.Balance, balance, $"{accountState.Key} Balance"); Assert.AreEqual(accountState.Value.Nonce, nonce, $"{accountState.Key} Nonce"); // TODO: not testing properly 0 balance accounts if (accountExists) { byte[] code = _stateProvider.GetCode(accountState.Key); Assert.AreEqual(accountState.Value.Code, code, $"{accountState.Key} Code"); } foreach (KeyValuePair <UInt256, byte[]> storageItem in accountState.Value.Storage) { byte[] value = _storageProvider.Get(new StorageCell(accountState.Key, storageItem.Key)); Assert.True(Bytes.AreEqual(storageItem.Value, value), $"Storage[{accountState.Key}_{storageItem.Key}] Exp: {storageItem.Value.ToHexString(true)} != Actual: {value.ToHexString(true)}"); } } }