public void Cannot_mark_as_failed_when_actions_stacked() { ParityLikeTxTracer tracer = new ParityLikeTxTracer(Build.A.Block.TestObject, Build.A.Transaction.TestObject, ParityTraceTypes.All); tracer.ReportAction(1000L, 10, Address.Zero, Address.Zero, Bytes.Empty, ExecutionType.Call, false); Assert.Throws <InvalidOperationException>(() => tracer.MarkAsFailed(TestItem.AddressA, 21000, Bytes.Empty, "Error")); }
public void Cannot_mark_as_success_when_actions_stacked() { ParityLikeTxTracer tracer = new ParityLikeTxTracer(Build.A.Block.TestObject, Build.A.Transaction.TestObject, ParityTraceTypes.All); tracer.ReportAction(1000L, 10, Address.Zero, Address.Zero, Array.Empty <byte>(), ExecutionType.Call, false); Assert.Throws <InvalidOperationException>(() => tracer.MarkAsSuccess(TestItem.AddressA, 21000, Array.Empty <byte>(), new LogEntry[] { })); }
public void Load_self_destruct() { TestState.CreateAccount(TestItem.PrivateKeyA.Address, 100.Ether()); TestState.Commit(SpecProvider.GenesisSpec); TestState.CommitTree(0); byte[] initByteCode = Prepare.EvmCode .ForInitOf( Prepare.EvmCode .PushData(1) .Op(Instruction.SLOAD) .PushData(1) .Op(Instruction.EQ) .PushData(17) .Op(Instruction.JUMPI) .PushData(1) .PushData(1) .Op(Instruction.SSTORE) .PushData(21) .Op(Instruction.JUMP) .Op(Instruction.JUMPDEST) .PushData(0) .Op(Instruction.SELFDESTRUCT) .Op(Instruction.JUMPDEST) .Done) .Done; Address contractAddress = ContractAddress.From(TestItem.PrivateKeyA.Address, 0); byte[] byteCode1 = Prepare.EvmCode .Call(contractAddress, 100000) .Op(Instruction.STOP).Done; byte[] byteCode2 = Prepare.EvmCode .Call(contractAddress, 100000) .Op(Instruction.STOP).Done; long gasLimit = 1000000; EthereumEcdsa ecdsa = new EthereumEcdsa(1, LimboLogs.Instance); Transaction initTx = Build.A.Transaction.WithCode(initByteCode).WithGasLimit(gasLimit).SignedAndResolved(ecdsa, TestItem.PrivateKeyA).TestObject; Transaction tx1 = Build.A.Transaction.WithCode(byteCode1).WithGasLimit(gasLimit).WithNonce(1).SignedAndResolved(ecdsa, TestItem.PrivateKeyA).TestObject; Transaction tx2 = Build.A.Transaction.WithCode(byteCode2).WithGasLimit(gasLimit).WithNonce(2).SignedAndResolved(ecdsa, TestItem.PrivateKeyA).TestObject; Block block = Build.A.Block.WithNumber(MainnetSpecProvider.MuirGlacierBlockNumber).WithTransactions(MuirGlacier.Instance, initTx, tx1, tx2).WithGasLimit(2 * gasLimit).TestObject; ParityLikeTxTracer initTracer = new ParityLikeTxTracer(block, initTx, ParityTraceTypes.Trace | ParityTraceTypes.StateDiff); _processor.Execute(initTx, block.Header, initTracer); AssertStorage(new StorageCell(contractAddress, 1), 0); ParityLikeTxTracer tracer1 = new ParityLikeTxTracer(block, tx1, ParityTraceTypes.Trace | ParityTraceTypes.StateDiff); _processor.Execute(tx1, block.Header, tracer1); AssertStorage(new StorageCell(contractAddress, 1), 1); ParityLikeTxTracer tracer2 = new ParityLikeTxTracer(block, tx2, ParityTraceTypes.Trace | ParityTraceTypes.StateDiff); _processor.Execute(tx2, block.Header, tracer2); AssertStorage(new StorageCell(contractAddress, 1), 0); }
private (ParityLikeTxTrace trace, Block block, Transaction tx) ExecuteAndTraceParityCall(byte[] input, UInt256 value, params byte[] code) { (var block, var transaction) = PrepareTx(BlockNumber, 100000, code, input, value); ParityLikeTxTracer tracer = new ParityLikeTxTracer(block, transaction, ParityTraceTypes.Trace | ParityTraceTypes.StateDiff); _processor.Execute(transaction, block.Header, tracer); return(tracer.BuildResult(), block, transaction); }
private (ParityLikeTxTrace trace, Block block, Transaction tx) ExecuteAndTraceParityCall(ParityTraceTypes traceTypes, params byte[] code) { (var block, var transaction) = PrepareTx(BlockNumber, 100000, code); ParityLikeTxTracer tracer = new ParityLikeTxTracer(block, transaction, traceTypes); _processor.Execute(transaction, block.Header, tracer); return(tracer.BuildResult(), block, transaction); }
protected (ParityLikeTxTrace trace, Block block, Transaction tx) ExecuteInitAndTraceParityCall(params byte[] code) { (var block, var transaction) = PrepareInitTx(BlockNumber, 100000, code); ParityLikeTxTracer tracer = new ParityLikeTxTracer(block, transaction, ParityTraceTypes.Trace | ParityTraceTypes.StateDiff); _processor.Execute(transaction, block.Header, tracer); return(tracer.BuildResult(), block, transaction); }
public void Touch_empty_trace_does_not_throw() { ParityLikeTxTracer tracer = new ParityLikeTxTracer(Build.A.Block.TestObject, null, ParityTraceTypes.StateDiff); StateProvider provider = new StateProvider(new StateDb(new MemDb()), Substitute.For <IDb>(), Logger); provider.CreateAccount(_address1, 0); Account account = provider.GetAccount(_address1); Assert.True(account.IsEmpty); provider.Commit(Frontier.Instance); // commit empty account (before the empty account fix in Spurious Dragon) Assert.True(provider.AccountExists(_address1)); provider.Reset(); // clear all caches provider.GetBalance(_address1); // justcache provider.AddToBalance(_address1, 0, SpuriousDragon.Instance); // touch Assert.DoesNotThrow(() => provider.Commit(SpuriousDragon.Instance, tracer)); }
public void Throw_operation_canceled_after_given_timeout() { var timeout = TimeSpan.FromMilliseconds(100); Transaction transactionMock = Substitute.For <Transaction>(); ParityTraceTypes type = ParityTraceTypes.Trace; Address address = new Address(new byte[] { 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1 }); CancellationToken cancellationToken = new CancellationTokenSource(timeout).Token; ParityLikeTxTracer tracer = new ParityLikeTxTracer(_blockTree.Head, transactionMock, type, cancellationToken); Thread.Sleep(timeout.Add(TimeSpan.FromMilliseconds(100))); Assert.Throws <OperationCanceledException>(() => tracer.StartOperation(0, 0, default(Instruction), 0)); Assert.Throws <OperationCanceledException>(() => tracer.ReportAction(0, 0, address, address, new byte[] { 0, 0, 0 }, ExecutionType.Transaction)); Assert.Throws <OperationCanceledException>(() => tracer.ReportAction(0, 0, address, address, new byte[] { 0, 0, 0 }, ExecutionType.Transaction)); Assert.Throws <OperationCanceledException>(() => tracer.ReportSelfDestruct(address, 0, address)); Assert.Throws <OperationCanceledException>(() => tracer.ReportStackPush(null)); }
public void Throws_operation_canceled_after_timeout() { CancellationToken cancellationToken = new CancellationTokenSource(TimeSpan.FromMilliseconds(300)).Token; (var block, var transaction) = PrepareTx(BlockNumber, 100000, new byte[] { 0, 0, 0 }); ParityLikeTxTracer tracer = new ParityLikeTxTracer(block, transaction, ParityTraceTypes.Trace, cancellationToken); try { tracer.StartOperation(0, 0, Instruction.ADD, 0); } catch (Exception ex) { if (ex is OperationCanceledException) { Assert.Fail("Threw OperationCancelledException before timeout."); } } Thread.Sleep(TimeSpan.FromMilliseconds(500)); Assert.Throws <OperationCanceledException>(() => tracer.StartOperation(0, 0, Instruction.ADD, 0)); }
public void Destroy_restore_store_different_cells_previously_existing() { byte[] baseInitCodeStore = Prepare.EvmCode .PushData(2) .Op(Instruction.CALLVALUE) .Op(Instruction.SSTORE).Done; byte[] contractCode = Prepare.EvmCode .PushData(1) .Op(Instruction.SLOAD) .PushData(1) .Op(Instruction.EQ) .PushData(17) .Op(Instruction.JUMPI) .PushData(1) .PushData(1) .Op(Instruction.SSTORE) .PushData(21) .Op(Instruction.JUMP) .Op(Instruction.JUMPDEST) .PushData(0) .Op(Instruction.SELFDESTRUCT) .Op(Instruction.JUMPDEST) .Done; byte[] baseInitCodeAfterStore = Prepare.EvmCode .ForInitOf(contractCode) .Done; byte[] baseInitCode = Bytes.Concat(baseInitCodeStore, baseInitCodeAfterStore); byte[] create2Code = Prepare.EvmCode .ForCreate2Of(baseInitCode) .Done; byte[] initOfCreate2Code = Prepare.EvmCode .ForInitOf(create2Code) .Done; Address deployingContractAddress = ContractAddress.From(TestItem.PrivateKeyA.Address, 0); Address deploymentAddress = ContractAddress.From(deployingContractAddress, new byte[32], baseInitCode); byte[] deploy = Prepare.EvmCode .CallWithValue(deployingContractAddress, 100000) .Op(Instruction.STOP).Done; byte[] byteCode1 = Prepare.EvmCode .CallWithValue(deploymentAddress, 100000) .Op(Instruction.STOP).Done; byte[] byteCode2 = Prepare.EvmCode .CallWithValue(deploymentAddress, 100000) .Op(Instruction.STOP).Done; TestState.CreateAccount(TestItem.PrivateKeyA.Address, 100.Ether()); //TestState.Commit(SpecProvider.GenesisSpec); //TestState.CommitTree(0); TestState.CreateAccount(deploymentAddress, UInt256.One); Keccak codeHash = TestState.UpdateCode(contractCode); TestState.UpdateCodeHash(deploymentAddress, codeHash, MuirGlacier.Instance); Storage.Set(new StorageCell(deploymentAddress, 7), new byte[] { 7 }); Storage.Commit(); Storage.CommitTrees(0); TestState.Commit(MuirGlacier.Instance); TestState.CommitTree(0); long gasLimit = 1000000; EthereumEcdsa ecdsa = new(1, LimboLogs.Instance); // deploy create 2 Transaction tx0 = Build.A.Transaction.WithCode(initOfCreate2Code).WithGasLimit(gasLimit).SignedAndResolved(ecdsa, TestItem.PrivateKeyA).TestObject; // call contract once Transaction tx1 = Build.A.Transaction.WithCode(byteCode1).WithGasLimit(gasLimit).WithNonce(1).SignedAndResolved(ecdsa, TestItem.PrivateKeyA).TestObject; // self destruct contract Transaction tx2 = Build.A.Transaction.WithCode(byteCode2).WithGasLimit(gasLimit).WithNonce(2).SignedAndResolved(ecdsa, TestItem.PrivateKeyA).TestObject; // deploy again using create2 Transaction tx3 = Build.A.Transaction.WithValue(3).WithCode(deploy).WithGasLimit(gasLimit).WithNonce(3).SignedAndResolved(ecdsa, TestItem.PrivateKeyA).TestObject; // call newly deployed once Transaction tx4 = Build.A.Transaction.WithCode(byteCode1).WithGasLimit(gasLimit).WithNonce(4).SignedAndResolved(ecdsa, TestItem.PrivateKeyA).TestObject; Block block = Build.A.Block.WithNumber(MainnetSpecProvider.MuirGlacierBlockNumber).WithTransactions(tx0, tx1, tx2, tx3, tx4).WithGasLimit(2 * gasLimit).TestObject; ParityLikeTxTracer tracer = new(block, tx0, ParityTraceTypes.Trace | ParityTraceTypes.StateDiff); _processor.Execute(tx0, block.Header, tracer); tracer = new ParityLikeTxTracer(block, tx1, ParityTraceTypes.Trace | ParityTraceTypes.StateDiff); _processor.Execute(tx1, block.Header, tracer); // AssertStorage(new StorageCell(deploymentAddress, 7), 7); tracer = new ParityLikeTxTracer(block, tx2, ParityTraceTypes.Trace | ParityTraceTypes.StateDiff); _processor.Execute(tx2, block.Header, tracer); // AssertStorage(new StorageCell(deploymentAddress, 7), 0); tracer = new ParityLikeTxTracer(block, tx3, ParityTraceTypes.Trace | ParityTraceTypes.StateDiff); _processor.Execute(tx3, block.Header, tracer); AssertStorage(new StorageCell(deploymentAddress, 7), 0); tracer = new ParityLikeTxTracer(block, tx4, ParityTraceTypes.Trace | ParityTraceTypes.StateDiff); _processor.Execute(tx4, block.Header, tracer); AssertStorage(new StorageCell(deploymentAddress, 7), 0); }
public void Destroy_restore_store() { TestState.CreateAccount(TestItem.PrivateKeyA.Address, 100.Ether()); TestState.Commit(SpecProvider.GenesisSpec); TestState.CommitTree(); byte[] baseInitCodeStore = Prepare.EvmCode .PushData(2) .PushData(2) .Op(Instruction.SSTORE).Done; byte[] baseInitCodeAfterStore = Prepare.EvmCode .ForInitOf( Prepare.EvmCode .PushData(1) .Op(Instruction.SLOAD) .PushData(1) .Op(Instruction.EQ) .PushData(17) .Op(Instruction.JUMPI) .PushData(1) .PushData(1) .Op(Instruction.SSTORE) .PushData(21) .Op(Instruction.JUMP) .Op(Instruction.JUMPDEST) .PushData(0) .Op(Instruction.SELFDESTRUCT) .Op(Instruction.JUMPDEST) .Done) .Done; byte[] baseInitCode = Bytes.Concat(baseInitCodeStore, baseInitCodeAfterStore); byte[] create2Code = Prepare.EvmCode .ForCreate2Of(baseInitCode) .Done; byte[] initOfCreate2Code = Prepare.EvmCode .ForInitOf(create2Code) .Done; Address deployingContractAddress = ContractAddress.From(TestItem.PrivateKeyA.Address, 0); Address deploymentAddress = ContractAddress.From(deployingContractAddress, new byte[32], baseInitCode); byte[] deploy = Prepare.EvmCode .Call(deployingContractAddress, 100000) .Op(Instruction.STOP).Done; byte[] byteCode1 = Prepare.EvmCode .Call(deploymentAddress, 100000) .Op(Instruction.STOP).Done; byte[] byteCode2 = Prepare.EvmCode .Call(deploymentAddress, 100000) .Op(Instruction.STOP).Done; long gasLimit = 1000000; EthereumEcdsa ecdsa = new EthereumEcdsa(1, LimboLogs.Instance); // deploy create 2 Transaction tx0 = Build.A.Transaction.WithInit(initOfCreate2Code).WithGasLimit(gasLimit).SignedAndResolved(ecdsa, TestItem.PrivateKeyA).TestObject; // invoke create 2 to deploy contract Transaction tx1 = Build.A.Transaction.WithInit(deploy).WithGasLimit(gasLimit).WithNonce(1).SignedAndResolved(ecdsa, TestItem.PrivateKeyA).TestObject; // call contract once Transaction tx2 = Build.A.Transaction.WithInit(byteCode1).WithGasLimit(gasLimit).WithNonce(2).SignedAndResolved(ecdsa, TestItem.PrivateKeyA).TestObject; // self destruct contract Transaction tx3 = Build.A.Transaction.WithInit(byteCode2).WithGasLimit(gasLimit).WithNonce(3).SignedAndResolved(ecdsa, TestItem.PrivateKeyA).TestObject; // deploy again using create2 Transaction tx4 = Build.A.Transaction.WithInit(deploy).WithGasLimit(gasLimit).WithNonce(4).SignedAndResolved(ecdsa, TestItem.PrivateKeyA).TestObject; // call newly deployed once Transaction tx5 = Build.A.Transaction.WithInit(byteCode1).WithGasLimit(gasLimit).WithNonce(5).SignedAndResolved(ecdsa, TestItem.PrivateKeyA).TestObject; Block block = Build.A.Block.WithNumber(MainnetSpecProvider.MuirGlacierBlockNumber).WithTransactions(tx0, tx1, tx2, tx3, tx4, tx5).WithGasLimit(2 * gasLimit).TestObject; ParityLikeTxTracer tracer0 = new ParityLikeTxTracer(block, tx0, ParityTraceTypes.Trace | ParityTraceTypes.StateDiff); _processor.Execute(tx0, block.Header, tracer0); // AssertStorage(new StorageCell(deploymentAddress, 1), 0); ParityLikeTxTracer tracer = new ParityLikeTxTracer(block, tx1, ParityTraceTypes.Trace | ParityTraceTypes.StateDiff); _processor.Execute(tx1, block.Header, tracer); // AssertStorage(new StorageCell(deploymentAddress, 1), 0); // AssertStorage(new StorageCell(deploymentAddress, 2), 2); tracer = new ParityLikeTxTracer(block, tx2, ParityTraceTypes.Trace | ParityTraceTypes.StateDiff); _processor.Execute(tx2, block.Header, tracer); // AssertStorage(new StorageCell(deploymentAddress, 1), 1); // AssertStorage(new StorageCell(deploymentAddress, 2), 2); tracer = new ParityLikeTxTracer(block, tx3, ParityTraceTypes.Trace | ParityTraceTypes.StateDiff); _processor.Execute(tx3, block.Header, tracer); // AssertStorage(new StorageCell(deploymentAddress, 1), 0); // AssertStorage(new StorageCell(deploymentAddress, 2), 0); tracer = new ParityLikeTxTracer(block, tx4, ParityTraceTypes.Trace | ParityTraceTypes.StateDiff); _processor.Execute(tx4, block.Header, tracer); // AssertStorage(new StorageCell(deploymentAddress, 1), 0); // AssertStorage(new StorageCell(deploymentAddress, 2), 2); tracer = new ParityLikeTxTracer(block, tx5, ParityTraceTypes.Trace | ParityTraceTypes.StateDiff); _processor.Execute(tx5, block.Header, tracer); AssertStorage(new StorageCell(deploymentAddress, 1), 1); AssertStorage(new StorageCell(deploymentAddress, 2), 2); }