From 058d9a952a3ede95d2617b98e8dd669938d22463 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Bylica?= Date: Tue, 13 Aug 2019 19:46:05 +0200 Subject: [PATCH] Do not keep information about block stack change This information is only needed in analysis to compute other block stack requirements parameters. --- lib/evmone/analysis.cpp | 8 +++++--- lib/evmone/analysis.hpp | 1 - test/unittests/analysis_test.cpp | 2 -- test/utils/dump.cpp | 2 +- 4 files changed, 6 insertions(+), 7 deletions(-) diff --git a/lib/evmone/analysis.cpp b/lib/evmone/analysis.cpp index 4a4046eafe..f8b13843b2 100644 --- a/lib/evmone/analysis.cpp +++ b/lib/evmone/analysis.cpp @@ -54,6 +54,7 @@ code_analysis analyze( block_info* block = nullptr; + int block_stack_change = 0; int instr_index = 0; const auto code_end = code + code_size; @@ -68,6 +69,7 @@ code_analysis analyze( { // Create new block. block = &analysis.blocks.emplace_back(); + block_stack_change = 0; // Create BEGINBLOCK instruction which either replaces JUMPDEST or is injected // in case there is no JUMPDEST. @@ -89,9 +91,9 @@ code_analysis analyze( const auto instr_stack_req = metrics.num_stack_arguments; const auto instr_stack_change = metrics.num_stack_returned_items - instr_stack_req; - block->stack_req = std::max(block->stack_req, instr_stack_req - block->stack_change); - block->stack_change += instr_stack_change; - block->stack_max = std::max(block->stack_max, block->stack_change); + block->stack_req = std::max(block->stack_req, instr_stack_req - block_stack_change); + block_stack_change += instr_stack_change; + block->stack_max = std::max(block->stack_max, block_stack_change); if (metrics.gas_cost > 0) // can be -1 for undefined instruction block->gas_cost += metrics.gas_cost; diff --git a/lib/evmone/analysis.hpp b/lib/evmone/analysis.hpp index 6195e47ceb..c56ce234af 100644 --- a/lib/evmone/analysis.hpp +++ b/lib/evmone/analysis.hpp @@ -165,7 +165,6 @@ struct block_info int64_t gas_cost = 0; int stack_req = 0; ///< The required stack height to execute the block. int stack_max = 0; ///< The relative maximum stack height in the block. - int stack_change = 0; ///< The relative stack height change after the execution of the block. }; struct code_analysis diff --git a/test/unittests/analysis_test.cpp b/test/unittests/analysis_test.cpp index 1172ff4f84..b450f5c752 100644 --- a/test/unittests/analysis_test.cpp +++ b/test/unittests/analysis_test.cpp @@ -43,7 +43,6 @@ TEST(analysis, example1) EXPECT_EQ(analysis.blocks[0].gas_cost, 14); EXPECT_EQ(analysis.blocks[0].stack_req, 0); EXPECT_EQ(analysis.blocks[0].stack_max, 2); - EXPECT_EQ(analysis.blocks[0].stack_change, 0); } TEST(analysis, stack_up_and_down) @@ -63,7 +62,6 @@ TEST(analysis, stack_up_and_down) EXPECT_EQ(analysis.blocks[0].gas_cost, 7 * 3 + 10 * 2 + 3); EXPECT_EQ(analysis.blocks[0].stack_req, 3); EXPECT_EQ(analysis.blocks[0].stack_max, 7); - EXPECT_EQ(analysis.blocks[0].stack_change, -2); } TEST(analysis, push) diff --git a/test/utils/dump.cpp b/test/utils/dump.cpp index ce5113d1bc..e7d331f0f2 100644 --- a/test/utils/dump.cpp +++ b/test/utils/dump.cpp @@ -48,7 +48,7 @@ void dump_analysis(const evmone::code_analysis& analysis) std::cout << " "; std::cout << " " << std::setw(10) << block->gas_cost << " " << block->stack_req << " " - << block->stack_max << " " << block->stack_change << "\n"; + << block->stack_max << "\n"; } std::cout << "│ " << std::setw(9) << std::left << name << std::setw(4) << std::right