diff --git a/lib/evmone/tracing.cpp b/lib/evmone/tracing.cpp index d3762af7a9..50f384a894 100644 --- a/lib/evmone/tracing.cpp +++ b/lib/evmone/tracing.cpp @@ -112,15 +112,15 @@ class InstructionTracer : public Tracer const auto opcode = ctx.code[pc]; m_out << "{"; - m_out << R"("pc":)" << pc; - m_out << R"(,"op":)" << int{opcode}; + m_out << R"("pc":)" << std::dec << pc; + m_out << R"(,"op":)" << std::dec << int{opcode}; m_out << R"(,"opName":")" << get_name(opcode) << '"'; - m_out << R"(,"gas":)" << state.gas_left; + m_out << R"(,"gas":)" << std::hex << "0x" << state.gas_left; output_stack(stack_top, stack_height); // Full memory can be dumped as evmc::hex({state.memory.data(), state.memory.size()}), // but this should not be done by default. Adding --tracing=+memory option would be nice. - m_out << R"(,"memorySize":)" << state.memory.size(); + m_out << R"(,"memorySize":)" << std::dec << state.memory.size(); m_out << "}\n"; } @@ -135,8 +135,8 @@ class InstructionTracer : public Tracer m_out << "null"; else m_out << '"' << result.status_code << '"'; - m_out << R"(,"gas":)" << result.gas_left; - m_out << R"(,"gasUsed":)" << (ctx.start_gas - result.gas_left); + m_out << R"(,"gas":)" << std::hex << "0x" << result.gas_left; + m_out << R"(,"gasUsed":)" << std::hex << "0x" << (ctx.start_gas - result.gas_left); m_out << R"(,"output":")" << evmc::hex({result.output_data, result.output_size}) << '"'; m_out << "}\n"; diff --git a/test/integration/CMakeLists.txt b/test/integration/CMakeLists.txt index a5b8744a21..0e1d24732b 100644 --- a/test/integration/CMakeLists.txt +++ b/test/integration/CMakeLists.txt @@ -23,12 +23,12 @@ DUP1,4 set_tests_properties( ${PREFIX}/trace PROPERTIES PASS_REGULAR_EXPRESSION "{\"depth\":0,\"rev\":\"Paris\",\"static\":false} -{\"pc\":0,\"op\":96,\"opName\":\"PUSH1\",\"gas\":1000000,\"stack\":\\[\\],\"memorySize\":0} -{\"pc\":2,\"op\":96,\"opName\":\"PUSH1\",\"gas\":999997,\"stack\":\\[\"0x0\"\\],\"memorySize\":0} -{\"pc\":4,\"op\":128,\"opName\":\"DUP1\",\"gas\":999994,\"stack\":\\[\"0x0\",\"0x2\"\\],\"memorySize\":0} -{\"pc\":5,\"op\":1,\"opName\":\"ADD\",\"gas\":999991,\"stack\":\\[\"0x0\",\"0x2\",\"0x2\"\\],\"memorySize\":0} -{\"pc\":6,\"op\":3,\"opName\":\"SUB\",\"gas\":999988,\"stack\":\\[\"0x0\",\"0x4\"\\],\"memorySize\":0} -{\"error\":null,\"gas\":999985,\"gasUsed\":15,\"output\":\"\"} +{\"pc\":0,\"op\":96,\"opName\":\"PUSH1\",\"gas\":0xf4240,\"stack\":\\[\\],\"memorySize\":0} +{\"pc\":2,\"op\":96,\"opName\":\"PUSH1\",\"gas\":0xf423d,\"stack\":\\[\"0x0\"\\],\"memorySize\":0} +{\"pc\":4,\"op\":128,\"opName\":\"DUP1\",\"gas\":0xf423a,\"stack\":\\[\"0x0\",\"0x2\"\\],\"memorySize\":0} +{\"pc\":5,\"op\":1,\"opName\":\"ADD\",\"gas\":0xf4237,\"stack\":\\[\"0x0\",\"0x2\",\"0x2\"\\],\"memorySize\":0} +{\"pc\":6,\"op\":3,\"opName\":\"SUB\",\"gas\":0xf4234,\"stack\":\\[\"0x0\",\"0x4\"\\],\"memorySize\":0} +{\"error\":null,\"gas\":0xf4231,\"gasUsed\":0xf,\"output\":\"\"} ") endif() diff --git a/test/integration/statetest/CMakeLists.txt b/test/integration/statetest/CMakeLists.txt index 4e6500ebc2..691a2cd8fe 100644 --- a/test/integration/statetest/CMakeLists.txt +++ b/test/integration/statetest/CMakeLists.txt @@ -80,5 +80,5 @@ add_test( ) set_tests_properties( ${PREFIX}/trace PROPERTIES - PASS_REGULAR_EXPRESSION [=[\{"pc":4,"op":1,"opName":"ADD","gas":378994,"stack":\["0x1","0x1"\],"memorySize":0\}]=] + PASS_REGULAR_EXPRESSION [=[\{"pc":4,"op":1,"opName":"ADD","gas":0x5c872,"stack":\["0x1","0x1"\],"memorySize":0\}]=] ) diff --git a/test/unittests/tracing_test.cpp b/test/unittests/tracing_test.cpp index 7dbc25df0d..3a8817c78f 100644 --- a/test/unittests/tracing_test.cpp +++ b/test/unittests/tracing_test.cpp @@ -168,10 +168,10 @@ TEST_F(tracing, trace) trace_stream << '\n'; EXPECT_EQ(trace(add(2, 3)), R"( {"depth":0,"rev":"Berlin","static":false} -{"pc":0,"op":96,"opName":"PUSH1","gas":1000000,"stack":[],"memorySize":0} -{"pc":2,"op":96,"opName":"PUSH1","gas":999997,"stack":["0x3"],"memorySize":0} -{"pc":4,"op":1,"opName":"ADD","gas":999994,"stack":["0x3","0x2"],"memorySize":0} -{"error":null,"gas":999991,"gasUsed":9,"output":""} +{"pc":0,"op":96,"opName":"PUSH1","gas":0xf4240,"stack":[],"memorySize":0} +{"pc":2,"op":96,"opName":"PUSH1","gas":0xf423d,"stack":["0x3"],"memorySize":0} +{"pc":4,"op":1,"opName":"ADD","gas":0xf423a,"stack":["0x3","0x2"],"memorySize":0} +{"error":null,"gas":0xf4237,"gasUsed":0x9,"output":""} )"); } @@ -183,14 +183,14 @@ TEST_F(tracing, trace_stack) trace_stream << '\n'; EXPECT_EQ(trace(code), R"( {"depth":0,"rev":"Berlin","static":false} -{"pc":0,"op":96,"opName":"PUSH1","gas":1000000,"stack":[],"memorySize":0} -{"pc":2,"op":96,"opName":"PUSH1","gas":999997,"stack":["0x1"],"memorySize":0} -{"pc":4,"op":96,"opName":"PUSH1","gas":999994,"stack":["0x1","0x2"],"memorySize":0} -{"pc":6,"op":96,"opName":"PUSH1","gas":999991,"stack":["0x1","0x2","0x3"],"memorySize":0} -{"pc":8,"op":1,"opName":"ADD","gas":999988,"stack":["0x1","0x2","0x3","0x4"],"memorySize":0} -{"pc":9,"op":1,"opName":"ADD","gas":999985,"stack":["0x1","0x2","0x7"],"memorySize":0} -{"pc":10,"op":1,"opName":"ADD","gas":999982,"stack":["0x1","0x9"],"memorySize":0} -{"error":null,"gas":999979,"gasUsed":21,"output":""} +{"pc":0,"op":96,"opName":"PUSH1","gas":0xf4240,"stack":[],"memorySize":0} +{"pc":2,"op":96,"opName":"PUSH1","gas":0xf423d,"stack":["0x1"],"memorySize":0} +{"pc":4,"op":96,"opName":"PUSH1","gas":0xf423a,"stack":["0x1","0x2"],"memorySize":0} +{"pc":6,"op":96,"opName":"PUSH1","gas":0xf4237,"stack":["0x1","0x2","0x3"],"memorySize":0} +{"pc":8,"op":1,"opName":"ADD","gas":0xf4234,"stack":["0x1","0x2","0x3","0x4"],"memorySize":0} +{"pc":9,"op":1,"opName":"ADD","gas":0xf4231,"stack":["0x1","0x2","0x7"],"memorySize":0} +{"pc":10,"op":1,"opName":"ADD","gas":0xf422e,"stack":["0x1","0x9"],"memorySize":0} +{"error":null,"gas":0xf422b,"gasUsed":0x15,"output":""} )"); } @@ -202,8 +202,8 @@ TEST_F(tracing, trace_error) trace_stream << '\n'; EXPECT_EQ(trace(code), R"( {"depth":0,"rev":"Berlin","static":false} -{"pc":0,"op":80,"opName":"POP","gas":1000000,"stack":[],"memorySize":0} -{"error":"stack underflow","gas":0,"gasUsed":1000000,"output":""} +{"pc":0,"op":80,"opName":"POP","gas":0xf4240,"stack":[],"memorySize":0} +{"error":"stack underflow","gas":0x0,"gasUsed":0xf4240,"output":""} )"); } @@ -215,13 +215,13 @@ TEST_F(tracing, trace_output) trace_stream << '\n'; EXPECT_EQ(trace(code), R"( {"depth":0,"rev":"Berlin","static":false} -{"pc":0,"op":98,"opName":"PUSH3","gas":1000000,"stack":[],"memorySize":0} -{"pc":4,"op":96,"opName":"PUSH1","gas":999997,"stack":["0xabcdef"],"memorySize":0} -{"pc":6,"op":82,"opName":"MSTORE","gas":999994,"stack":["0xabcdef","0x0"],"memorySize":0} -{"pc":7,"op":96,"opName":"PUSH1","gas":999988,"stack":[],"memorySize":32} -{"pc":9,"op":96,"opName":"PUSH1","gas":999985,"stack":["0x20"],"memorySize":32} -{"pc":11,"op":243,"opName":"RETURN","gas":999982,"stack":["0x20","0x0"],"memorySize":32} -{"error":null,"gas":999982,"gasUsed":18,"output":"0000000000000000000000000000000000000000000000000000000000abcdef"} +{"pc":0,"op":98,"opName":"PUSH3","gas":0xf4240,"stack":[],"memorySize":0} +{"pc":4,"op":96,"opName":"PUSH1","gas":0xf423d,"stack":["0xabcdef"],"memorySize":0} +{"pc":6,"op":82,"opName":"MSTORE","gas":0xf423a,"stack":["0xabcdef","0x0"],"memorySize":0} +{"pc":7,"op":96,"opName":"PUSH1","gas":0xf4234,"stack":[],"memorySize":32} +{"pc":9,"op":96,"opName":"PUSH1","gas":0xf4231,"stack":["0x20"],"memorySize":32} +{"pc":11,"op":243,"opName":"RETURN","gas":0xf422e,"stack":["0x20","0x0"],"memorySize":32} +{"error":null,"gas":0xf422e,"gasUsed":0x12,"output":"0000000000000000000000000000000000000000000000000000000000abcdef"} )"); } @@ -233,13 +233,13 @@ TEST_F(tracing, trace_revert) trace_stream << '\n'; EXPECT_EQ(trace(code), R"( {"depth":0,"rev":"Berlin","static":false} -{"pc":0,"op":98,"opName":"PUSH3","gas":1000000,"stack":[],"memorySize":0} -{"pc":4,"op":96,"opName":"PUSH1","gas":999997,"stack":["0xe4404"],"memorySize":0} -{"pc":6,"op":82,"opName":"MSTORE","gas":999994,"stack":["0xe4404","0x0"],"memorySize":0} -{"pc":7,"op":96,"opName":"PUSH1","gas":999988,"stack":[],"memorySize":32} -{"pc":9,"op":96,"opName":"PUSH1","gas":999985,"stack":["0x3"],"memorySize":32} -{"pc":11,"op":253,"opName":"REVERT","gas":999982,"stack":["0x3","0x1d"],"memorySize":32} -{"error":"revert","gas":999982,"gasUsed":18,"output":"0e4404"} +{"pc":0,"op":98,"opName":"PUSH3","gas":0xf4240,"stack":[],"memorySize":0} +{"pc":4,"op":96,"opName":"PUSH1","gas":0xf423d,"stack":["0xe4404"],"memorySize":0} +{"pc":6,"op":82,"opName":"MSTORE","gas":0xf423a,"stack":["0xe4404","0x0"],"memorySize":0} +{"pc":7,"op":96,"opName":"PUSH1","gas":0xf4234,"stack":[],"memorySize":32} +{"pc":9,"op":96,"opName":"PUSH1","gas":0xf4231,"stack":["0x3"],"memorySize":32} +{"pc":11,"op":253,"opName":"REVERT","gas":0xf422e,"stack":["0x3","0x1d"],"memorySize":32} +{"error":"revert","gas":0xf422e,"gasUsed":0x12,"output":"0e4404"} )"); } @@ -250,7 +250,7 @@ TEST_F(tracing, trace_create) trace_stream << '\n'; EXPECT_EQ(trace({}, 2), R"( {"depth":2,"rev":"Berlin","static":false} -{"error":null,"gas":1000000,"gasUsed":0,"output":""} +{"error":null,"gas":0xf4240,"gasUsed":0x0,"output":""} )"); } @@ -261,7 +261,7 @@ TEST_F(tracing, trace_static) trace_stream << '\n'; EXPECT_EQ(trace({}, 2, EVMC_STATIC), R"( {"depth":2,"rev":"Berlin","static":true} -{"error":null,"gas":1000000,"gasUsed":0,"output":""} +{"error":null,"gas":0xf4240,"gasUsed":0x0,"output":""} )"); } @@ -273,9 +273,9 @@ TEST_F(tracing, trace_undefined_instruction) trace_stream << '\n'; EXPECT_EQ(trace(code), R"( {"depth":0,"rev":"Berlin","static":false} -{"pc":0,"op":91,"opName":"JUMPDEST","gas":1000000,"stack":[],"memorySize":0} -{"pc":1,"op":239,"opName":"0xef","gas":999999,"stack":[],"memorySize":0} -{"error":"undefined instruction","gas":0,"gasUsed":1000000,"output":""} +{"pc":0,"op":91,"opName":"JUMPDEST","gas":0xf4240,"stack":[],"memorySize":0} +{"pc":1,"op":239,"opName":"0xef","gas":0xf423f,"stack":[],"memorySize":0} +{"error":"undefined instruction","gas":0x0,"gasUsed":0xf4240,"output":""} )"); } @@ -299,10 +299,10 @@ TEST_F(tracing, trace_eof) trace_stream << '\n'; EXPECT_EQ(trace(eof1_bytecode(add(2, 3) + OP_STOP, 2), 0, 0, EVMC_CANCUN), R"( {"depth":0,"rev":"Cancun","static":false} -{"pc":0,"op":96,"opName":"PUSH1","gas":1000000,"stack":[],"memorySize":0} -{"pc":2,"op":96,"opName":"PUSH1","gas":999997,"stack":["0x3"],"memorySize":0} -{"pc":4,"op":1,"opName":"ADD","gas":999994,"stack":["0x3","0x2"],"memorySize":0} -{"pc":5,"op":0,"opName":"STOP","gas":999991,"stack":["0x5"],"memorySize":0} -{"error":null,"gas":999991,"gasUsed":9,"output":""} +{"pc":0,"op":96,"opName":"PUSH1","gas":0xf4240,"stack":[],"memorySize":0} +{"pc":2,"op":96,"opName":"PUSH1","gas":0xf423d,"stack":["0x3"],"memorySize":0} +{"pc":4,"op":1,"opName":"ADD","gas":0xf423a,"stack":["0x3","0x2"],"memorySize":0} +{"pc":5,"op":0,"opName":"STOP","gas":0xf4237,"stack":["0x5"],"memorySize":0} +{"error":null,"gas":0xf4237,"gasUsed":0x9,"output":""} )"); }