Skip to content

Commit

Permalink
Switch back to assert
Browse files Browse the repository at this point in the history
  • Loading branch information
akokoshn committed Jun 18, 2024
1 parent 4660645 commit 4c915f7
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 20 deletions.
2 changes: 1 addition & 1 deletion lib/assigner/include/assigner.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down
4 changes: 2 additions & 2 deletions lib/evmone/baseline.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ inline evmc_status_code check_requirements(const CostTable& cost_table, int64_t&
const nil::blueprint::zkevm_word<BlueprintFieldType>* 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.
Expand All @@ -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<BlueprintFieldType>::limit)
return EVMC_STACK_OVERFLOW;
}
Expand Down
20 changes: 10 additions & 10 deletions lib/evmone/eof.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,15 +121,15 @@ std::variant<EOFSectionHeaders, EOFValidationError> validate_eof_headers(bytes_v
state = State::section_size;
break;
default:
ASSERT(false);
assert(false);
}
break;
}
case State::section_size:
{
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)
Expand Down Expand Up @@ -182,12 +182,12 @@ std::variant<EOFSectionHeaders, EOFValidationError> validate_eof_headers(bytes_v
std::variant<std::vector<EOFCodeType>, 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<EOFCodeType> 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)
{
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -342,7 +342,7 @@ bool validate_rjump_destinations(bytes_view code) noexcept
std::variant<EOFValidationError, int32_t> validate_max_stack_height(
bytes_view code, size_t func_index, const std::vector<EOFCodeType>& code_types)
{
ASSERT(!code.empty());
assert(!code.empty());

// Special values used for detecting errors.
static constexpr int32_t LOC_UNVISITED = -1; // Unvisited byte.
Expand All @@ -367,7 +367,7 @@ std::variant<EOFValidationError, int32_t> 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)
{
Expand All @@ -380,7 +380,7 @@ std::variant<EOFValidationError, int32_t> 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<int8_t>(code_types[fid].outputs - stack_height_required);
}
Expand Down Expand Up @@ -508,7 +508,7 @@ std::variant<EOF1Header, EOFValidationError> validate_eof1(
auto offset = header_size + type_section_size;
for (const auto code_size : code_sizes)
{
ASSERT(offset <= std::numeric_limits<uint16_t>::max());
assert(offset <= std::numeric_limits<uint16_t>::max());
code_offsets.emplace_back(static_cast<uint16_t>(offset));
offset += code_size;
}
Expand Down Expand Up @@ -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<uint16_t>::max());
assert(code_offset <= std::numeric_limits<uint16_t>::max());
header.code_offsets.emplace_back(static_cast<uint16_t>(code_offset));
code_offset += code_size;
}
Expand Down
3 changes: 2 additions & 1 deletion lib/evmone/eof.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// SPDX-License-Identifier: Apache-2.0
#pragma once

#include <nil/crypto3/detail/assert.hpp>
#include <evmc/evmc.h>
#include <evmc/utils.h>
#include <cassert>
Expand Down Expand Up @@ -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]);
}

Expand Down
4 changes: 2 additions & 2 deletions lib/evmone/execution_state.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
8 changes: 4 additions & 4 deletions lib/evmone/instructions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -957,7 +957,7 @@ struct operation {
if constexpr (N == 0)
{
const auto index = stack.pop();
ASSERT(index.to_uint64() < std::numeric_limits<int>::max());
assert(index.to_uint64() < std::numeric_limits<int>::max());
stack.push(stack[(int)index.to_uint64() - 1]);
}
else
Expand All @@ -980,7 +980,7 @@ struct operation {
if constexpr (N == 0)
{
auto& index = stack.pop();
ASSERT(index < std::numeric_limits<int>::max());
assert(index < std::numeric_limits<int>::max());
a = &stack[(int)index.to_uint64()];
}
else
Expand Down Expand Up @@ -1120,7 +1120,7 @@ struct operation {

static inline Result call_impl(StackTop<BlueprintFieldType> stack, int64_t gas_left, ExecutionState<BlueprintFieldType>& 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();
Expand Down Expand Up @@ -1251,7 +1251,7 @@ struct operation {
}

static Result create_impl(StackTop<BlueprintFieldType> stack, int64_t gas_left, ExecutionState<BlueprintFieldType>& 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};
Expand Down

0 comments on commit 4c915f7

Please sign in to comment.