From 4c915f7c318b776b968c2e87fdd96f8f15c575ef Mon Sep 17 00:00:00 2001 From: akokoshn Date: Tue, 18 Jun 2024 10:02:37 +0300 Subject: [PATCH] Switch back to assert --- lib/assigner/include/assigner.hpp | 2 +- lib/evmone/baseline.hpp | 4 ++-- lib/evmone/eof.cpp | 20 ++++++++++---------- lib/evmone/eof.hpp | 3 ++- lib/evmone/execution_state.hpp | 4 ++-- lib/evmone/instructions.hpp | 8 ++++---- 6 files changed, 21 insertions(+), 20 deletions(-) diff --git a/lib/assigner/include/assigner.hpp b/lib/assigner/include/assigner.hpp index 6c9e5e2..3766079 100644 --- a/lib/assigner/include/assigner.hpp +++ b/lib/assigner/include/assigner.hpp @@ -50,7 +50,7 @@ namespace nil { const auto gas_left = (state->status == EVMC_SUCCESS || state->status == EVMC_REVERT) ? gas : 0; const auto gas_refund = (state->status == EVMC_SUCCESS) ? state->gas_refund : 0; - ASSERT(state->output_size != 0 || state->output_offset == 0); + assert(state->output_size != 0 || state->output_offset == 0); const auto evmc_result = evmc::make_result(state->status, gas_left, gas_refund, state->output_size != 0 ? &state->memory[state->output_offset] : nullptr, state->output_size); return evmc::Result{evmc_result}; diff --git a/lib/evmone/baseline.hpp b/lib/evmone/baseline.hpp index c654d8b..011f7d7 100644 --- a/lib/evmone/baseline.hpp +++ b/lib/evmone/baseline.hpp @@ -100,7 +100,7 @@ inline evmc_status_code check_requirements(const CostTable& cost_table, int64_t& const nil::blueprint::zkevm_word* stack_bottom, Opcode op) noexcept { - ASSERT( + assert( !instr::has_const_gas_cost(op) || instr::gas_costs[EVMC_FRONTIER][op] != instr::undefined); auto gas_cost = instr::gas_costs[EVMC_FRONTIER][op]; // Init assuming const cost. @@ -118,7 +118,7 @@ inline evmc_status_code check_requirements(const CostTable& cost_table, int64_t& // but it is nicer because complete gas check may need to inspect operands. if (instr::traits[op].stack_height_change > 0) { - ASSERT(instr::traits[op].stack_height_change == 1); + assert(instr::traits[op].stack_height_change == 1); if (stack_top == stack_bottom + StackSpace::limit) return EVMC_STACK_OVERFLOW; } diff --git a/lib/evmone/eof.cpp b/lib/evmone/eof.cpp index 22e2df0..6f41947 100644 --- a/lib/evmone/eof.cpp +++ b/lib/evmone/eof.cpp @@ -121,7 +121,7 @@ std::variant validate_eof_headers(bytes_v state = State::section_size; break; default: - ASSERT(false); + assert(false); } break; } @@ -129,7 +129,7 @@ std::variant validate_eof_headers(bytes_v { if (section_id == CODE_SECTION) { - ASSERT(section_num > 0); // Guaranteed by previous validation step. + assert(section_num > 0); // Guaranteed by previous validation step. for (size_t i = 0; i < section_num; ++i) { if (it >= container_end - 1) @@ -182,12 +182,12 @@ std::variant validate_eof_headers(bytes_v std::variant, EOFValidationError> validate_types( bytes_view container, size_t header_size, uint16_t type_section_size) noexcept { - ASSERT(!container.empty()); // guaranteed by EOF headers validation + assert(!container.empty()); // guaranteed by EOF headers validation std::vector types; // guaranteed by EOF headers validation - ASSERT(header_size + type_section_size < container.size()); + assert(header_size + type_section_size < container.size()); for (auto offset = header_size; offset < header_size + type_section_size; offset += 4) { @@ -216,7 +216,7 @@ EOFValidationError validate_instructions( evmc_revision rev, const EOF1Header& header, size_t code_idx, bytes_view container) noexcept { const bytes_view code{header.get_code(container, code_idx)}; - ASSERT(!code.empty()); // guaranteed by EOF headers validation + assert(!code.empty()); // guaranteed by EOF headers validation const auto& cost_table = baseline::get_baseline_cost_table(rev, 1); @@ -342,7 +342,7 @@ bool validate_rjump_destinations(bytes_view code) noexcept std::variant validate_max_stack_height( bytes_view code, size_t func_index, const std::vector& code_types) { - ASSERT(!code.empty()); + assert(!code.empty()); // Special values used for detecting errors. static constexpr int32_t LOC_UNVISITED = -1; // Unvisited byte. @@ -367,7 +367,7 @@ std::variant validate_max_stack_height( auto stack_height_change = instr::traits[opcode].stack_height_change; auto stack_height = stack_heights[i]; - ASSERT(stack_height != LOC_UNVISITED); + assert(stack_height != LOC_UNVISITED); if (opcode == OP_CALLF) { @@ -380,7 +380,7 @@ std::variant validate_max_stack_height( return EOFValidationError::stack_overflow; // Instruction validation ensures target function is returning - ASSERT(code_types[fid].outputs != NON_RETURNING_FUNCITON); + assert(code_types[fid].outputs != NON_RETURNING_FUNCITON); stack_height_change = static_cast(code_types[fid].outputs - stack_height_required); } @@ -508,7 +508,7 @@ std::variant validate_eof1( auto offset = header_size + type_section_size; for (const auto code_size : code_sizes) { - ASSERT(offset <= std::numeric_limits::max()); + assert(offset <= std::numeric_limits::max()); code_offsets.emplace_back(static_cast(offset)); offset += code_size; } @@ -585,7 +585,7 @@ EOF1Header read_valid_eof1_header(bytes_view container) auto code_offset = header_size + section_headers[TYPE_SECTION][0]; for (const auto code_size : header.code_sizes) { - ASSERT(code_offset <= std::numeric_limits::max()); + assert(code_offset <= std::numeric_limits::max()); header.code_offsets.emplace_back(static_cast(code_offset)); code_offset += code_size; } diff --git a/lib/evmone/eof.hpp b/lib/evmone/eof.hpp index 733d898..361cf76 100644 --- a/lib/evmone/eof.hpp +++ b/lib/evmone/eof.hpp @@ -3,6 +3,7 @@ // SPDX-License-Identifier: Apache-2.0 #pragma once +#include #include #include #include @@ -44,7 +45,7 @@ struct EOF1Header /// A helper to extract reference to a specific code section. [[nodiscard]] bytes_view get_code(bytes_view container, size_t code_idx) const noexcept { - ASSERT(code_idx < code_offsets.size()); + assert(code_idx < code_offsets.size()); return container.substr(code_offsets[code_idx], code_sizes[code_idx]); } diff --git a/lib/evmone/execution_state.hpp b/lib/evmone/execution_state.hpp index 7249291..b125f3c 100644 --- a/lib/evmone/execution_state.hpp +++ b/lib/evmone/execution_state.hpp @@ -94,10 +94,10 @@ class Memory void grow(size_t new_size) noexcept { // Restriction for future changes. EVM always has memory size as multiple of 32 bytes. - ASSERT(new_size % 32 == 0); + assert(new_size % 32 == 0); // Allow only growing memory. Include hint for optimizing compiler. - ASSERT(new_size > m_size); + assert(new_size > m_size); if (new_size > m_capacity) { diff --git a/lib/evmone/instructions.hpp b/lib/evmone/instructions.hpp index 17b3826..12ddede 100644 --- a/lib/evmone/instructions.hpp +++ b/lib/evmone/instructions.hpp @@ -957,7 +957,7 @@ struct operation { if constexpr (N == 0) { const auto index = stack.pop(); - ASSERT(index.to_uint64() < std::numeric_limits::max()); + assert(index.to_uint64() < std::numeric_limits::max()); stack.push(stack[(int)index.to_uint64() - 1]); } else @@ -980,7 +980,7 @@ struct operation { if constexpr (N == 0) { auto& index = stack.pop(); - ASSERT(index < std::numeric_limits::max()); + assert(index < std::numeric_limits::max()); a = &stack[(int)index.to_uint64()]; } else @@ -1120,7 +1120,7 @@ struct operation { static inline Result call_impl(StackTop stack, int64_t gas_left, ExecutionState& state, Opcode Op) noexcept { - ASSERT(Op == OP_CALL || Op == OP_CALLCODE || Op == OP_DELEGATECALL || Op == OP_STATICCALL); + assert(Op == OP_CALL || Op == OP_CALLCODE || Op == OP_DELEGATECALL || Op == OP_STATICCALL); const auto gas = stack.pop(); const auto dst = stack.pop().to_address(); @@ -1251,7 +1251,7 @@ struct operation { } static Result create_impl(StackTop stack, int64_t gas_left, ExecutionState& state, Opcode Op) noexcept { - ASSERT(Op == OP_CREATE || Op == OP_CREATE2); + assert(Op == OP_CREATE || Op == OP_CREATE2); if (state.in_static_mode()) return {EVMC_STATIC_MODE_VIOLATION, gas_left};