Skip to content

Commit

Permalink
return memory expansion
Browse files Browse the repository at this point in the history
  • Loading branch information
AntoineCyr committed Feb 14, 2025
1 parent f656650 commit f38afb4
Showing 1 changed file with 28 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <algorithm>

#include <nil/blueprint/zkevm/zkevm_word.hpp>
#include <nil/blueprint/zkevm_bbf/subcomponents/memory_cost.hpp>
#include <nil/blueprint/zkevm_bbf/types/copy_event.hpp>
#include <nil/blueprint/zkevm_bbf/types/opcode.hpp>

Expand All @@ -49,16 +50,38 @@ namespace nil {
using typename generic_component<FieldType,stage>::TYPE;

zkevm_return_bbf(context_type &context_object, const opcode_input_type<FieldType, stage> &current_state):
generic_component<FieldType,stage>(context_object, false)
{
TYPE offset;
TYPE length;
generic_component<FieldType,stage>(context_object, false){
using Memory_Cost = typename bbf::memory_cost<FieldType, stage>;

TYPE offset, length, current_mem, next_mem, memory_expansion, S;
if constexpr( stage == GenerationStage::ASSIGNMENT ){
offset = w_lo<FieldType>(current_state.stack_top());
length = w_lo<FieldType>(current_state.stack_top(1));
current_mem = current_state.memory_size;
next_mem = std::max(offset + length, current_mem);
S = next_mem > current_mem;
}
allocate(offset, 32, 0);
allocate(length, 33, 0);
allocate(current_mem, 34, 0);
allocate(next_mem, 35, 0);
allocate(S, 36, 0);

std::vector<std::size_t> memory_cost_lookup_area_1 = {32, 33, 34,
35, 36, 37};
std::vector<std::size_t> memory_cost_lookup_area_2 = {38, 39, 40,
41, 42, 43};
allocate(memory_expansion,45,0);

context_type current_memory_ct =
context_object.subcontext(memory_cost_lookup_area_1, 1, 1);
context_type next_memory_ct =
context_object.subcontext(memory_cost_lookup_area_2, 1, 1);

Memory_Cost current_memory =
Memory_Cost(current_memory_ct, current_mem);
Memory_Cost next_memory = Memory_Cost(next_memory_ct, next_mem);
memory_expansion = next_memory.cost - current_memory.cost;
if constexpr( stage == GenerationStage::CONSTRAINTS ){
std::vector<TYPE> tmp;
tmp = {
Expand Down Expand Up @@ -113,7 +136,7 @@ namespace nil {
// constrain(current_state.pc_next() - current_state.pc(0) - 1); // PC transition
// constrain(current_state.gas(0) - current_state.gas_next() - 1); // GAS transition
// constrain(current_state.stack_size(0) - current_state.stack_size_next()); // stack_size transition
// constrain(current_state.memory_size(0) - current_state.memory_size_next()); // memory_size transition
// constrain(current_state.memory_size(0) - current_state.memory_size_next() - memory_extension); // memory_size transition
// constrain(current_state.rw_counter_next() - current_state.rw_counter(0)); // rw_counter transition
} else {
// std::cout << "\tASSIGNMENT implemented" << std::endl;
Expand Down

0 comments on commit f38afb4

Please sign in to comment.