Skip to content

Commit

Permalink
Opcode constraints initialization started #95
Browse files Browse the repository at this point in the history
ETatuzova committed Nov 2, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent c904c37 commit c7aacb9
Showing 2 changed files with 25 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -54,7 +54,7 @@ namespace nil {
TYPE chunks_sum;
TYPE chunks_sum_inv;
TYPE result;
if( stage == GenerationStage::ASSIGNMENT ){
if constexpr( stage == GenerationStage::ASSIGNMENT ){
std::cout << "\tISZERO bbf object assigns its area" << std::endl;
zkevm_word_type A = current_state.stack_top();
a_chunks = zkevm_word_to_field_element<FieldType>(A);
@@ -75,6 +75,7 @@ namespace nil {
constrain(chunks_sum_expr - chunks_sum);
constrain(result + chunks_sum * chunks_sum_inv - 1);
constrain(result * (result - 1));
std::cout << "Result = " << result << std::endl;
}
};

@@ -91,7 +92,10 @@ namespace nil {
virtual void fill_context(
typename generic_component<FieldType, GenerationStage::CONSTRAINTS>::context_type &context,
const opcode_input_type<GenerationStage::CONSTRAINTS> &current_state
) {}
) {
std::cout << "\tBuild ISZERO constraints" << std::endl;
zkevm_iszero_bbf<FieldType, GenerationStage::CONSTRAINTS> bbf_obj(context, current_state);
}
virtual std::size_t rows_amount() override {
return 1;
}
19 changes: 19 additions & 0 deletions crypto3/libs/blueprint/include/nil/blueprint/zkevm_bbf/zkevm.hpp
Original file line number Diff line number Diff line change
@@ -413,6 +413,25 @@ namespace nil {
mc.push_back(opcode_constraint - all_states[1].opcode);
mc.push_back(row_counter_constraint - all_states[1].row_counter);

if( stage == GenerationStage::CONSTRAINTS) {
for( std::size_t opcode_num = 0; opcode_num < implemented_opcodes.size(); opcode_num++ ){
zkevm_opcode current_opcode = implemented_opcodes[opcode_num];
std::cout << "Build constraints for " << current_opcode << std::endl;
if( opcode_impls.find(current_opcode) == opcode_impls.end() ){
std::cout << "Implementation for "<< current_opcode << " is not defined" << std::endl;
continue;
}
std::size_t current_opcode_bare_rows_amount = opcode_impls[current_opcode]->rows_amount();
opcode_input_type<GenerationStage::CONSTRAINTS> current_state_obj;
context_type fresh_ct = context_object.fresh_subcontext(
opcode_area,
1,
1+current_opcode_bare_rows_amount
);
opcode_impls[current_opcode]->fill_context(fresh_ct, current_state_obj);
}
}

for( auto &constr: erc ){
context_object.relative_constrain(context_object.relativize(constr, -1), 0, max_zkevm_rows-1);
}

0 comments on commit c7aacb9

Please sign in to comment.