Skip to content

Commit

Permalink
Logging beautified, new tests added #279
Browse files Browse the repository at this point in the history
  • Loading branch information
ETatuzova committed Jan 30, 2025
1 parent 66e1721 commit bde6c51
Show file tree
Hide file tree
Showing 37 changed files with 71 additions and 66 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,24 @@ namespace nil {

std::map<std::string, std::set<std::vector<typename BlueprintFieldType::value_type>>> used_dynamic_tables;

std::size_t lookup_constraints_amount = 0;
std::map<std::string, std::size_t> table_lookup_map;
for (const auto& i : used_lookup_gates) {
lookup_constraints_amount += lookup_gates[i].constraints.size();
for( const auto &constraint : lookup_gates[i].constraints ){
std::string table_name = bp.get_reserved_indices_right().at(constraint.table_id);
if( table_lookup_map.find(table_name) == table_lookup_map.end()){
table_lookup_map[table_name] = 1;
} else {
table_lookup_map[table_name]++;
}
}
}
std::cout << "Lookup constraints amount = " << lookup_constraints_amount << std::endl;
for( const auto[k,v]: table_lookup_map){
std::cout << "\t" << k << " lookup constraints amount = " << v << std::endl;
}

std::cout << "Satisfiability check. Check" << std::endl;
for (const auto& i : used_gates) {
std::cout << "\tCheck gate " << i << std::endl;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -383,8 +383,7 @@ namespace nil {
} else if(opcode == "RETURNDATASIZE") {
// 0x3d
// std::cout << "Test me, please!" << std::endl;
std::cout << "RETURNDATASIZE not implemented" << std::endl;
exit(2);
// std::cout << "RETURNDATASIZE not implemented" << std::endl;
_rw_operations.push_back(stack_rw_operation(call_id, stack_next.size()-1, rw_counter++, true, stack_next[stack_next.size()-1]));

} else if(opcode == "RETURNDATACOPY") {
Expand Down Expand Up @@ -893,7 +892,8 @@ namespace nil {
_rw_operations.push_back(stack_rw_operation(call_id, stack.size()-3, rw_counter++, false, stack[stack.size()-5]));
_rw_operations.push_back(stack_rw_operation(call_id, stack.size()-2, rw_counter++, false, stack[stack.size()-6]));
_rw_operations.push_back(stack_rw_operation(call_id, stack.size()-1, rw_counter++, false, stack[stack.size()-7]));
_rw_operations.push_back(stack_rw_operation(call_id, stack_next.size()-1, rw_counter++, true, stack_next[stack_next.size()-1]));
//_rw_operations.push_back(stack_rw_operation(call_id, stack_next.size()-1, rw_counter++, true, stack_next[stack_next.size()-1]));
//exit(2);
} else if(opcode == "CALLCODE") {
// 0xf2
_rw_operations.push_back(stack_rw_operation(call_id, stack.size()-7, rw_counter++, false, stack[stack.size()-1]));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,6 @@ namespace nil {
is_add? S_128.second: A_128.second
};
lookup(tmp, "zkevm_rw");
} else {
std::cout << "\tAssignment implemented" << std::endl;
}
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -456,8 +456,6 @@ namespace nil {
Res0,
Res1};
lookup(tmp, "zkevm_rw");
} else {
std::cout << "\tASSIGNMENT implemented" << std::endl;
}
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,6 @@ namespace nil {
break;
}
lookup(tmp, "zkevm_rw");
} else {
std::cout << "\tASSIGNMENT implemented" << std::endl;
}
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,6 @@ namespace nil {
result
};
lookup(tmp, "zkevm_rw");
} else {
std::cout << "\tAssignment implemented" << std::endl;
}
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,6 @@ namespace nil {
// length
// };
// lookup(tmp, "zkevm_rw");
} else {
std::cout << "\tSTATE transition implemented" << std::endl;
}
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,6 @@ namespace nil {
constrain(current_state.stack_size_next() - current_state.stack_size(0)); // stack_size transition
constrain(current_state.memory_size(0) - current_state.memory_size_next()); // memory_size transition
constrain(current_state.rw_counter_next() - current_state.rw_counter(0) - 2); // rw_counter transition
} else {
std::cout << "\tSTATE transition implemented" << std::endl;
}
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,6 @@ namespace nil {
constrain(current_state.stack_size_next() - current_state.stack_size(0) - 1); // stack_size transition
constrain(current_state.memory_size(0) - current_state.memory_size_next()); // memory_size transition
constrain(current_state.rw_counter_next() - current_state.rw_counter(0) - 1); // rw_counter transition
} else {
std::cout << "\tSTATE transition implemented" << std::endl;
}
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,6 @@ namespace nil {
constrain(current_state.stack_size_next() - current_state.stack_size(0) - 1); // stack_size transition
constrain(current_state.memory_size(0) - current_state.memory_size_next()); // memory_size transition
constrain(current_state.rw_counter_next() - current_state.rw_counter(0) - 1); // rw_counter transition
} else {
std::cout << "\tSTATE transition implemented" << std::endl;
}
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,6 @@ namespace nil {
result
};
lookup(tmp, "zkevm_rw");
} else {
std::cout << "\tASSIGNMENT implemented" << std::endl;
}
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ namespace nil {
std::vector<TYPE> B_chunks(16);
if constexpr( stage == GenerationStage::ASSIGNMENT ){
// std::cout << "\tinput=" << std::hex << current_state.additional_input << std::dec << std::endl;
std::cout << "\tASSIGNMENT implemented" << std::endl;
auto A = current_state.stack_top(x - 1);
auto A16 = nil::blueprint::w_to_16(A);
for( std::size_t i = 0; i < 16; i++ ){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,6 @@ namespace nil {
r // addr is smaller than maximum contract size
};
lookup(tmp, "zkevm_rw");
} else {
std::cout << "\tASSIGNMENT implemented" << std::endl;
}
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,6 @@ namespace nil {
s * R_128.second
};
lookup(tmp, "zkevm_exp");
} else {
std::cout << "\tAssignment implemented" << std::endl;
}
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ namespace nil {
TYPE chunks_sum_inv;
TYPE result;
if constexpr( stage == GenerationStage::ASSIGNMENT ){
std::cout << "\tASSIGNMENT implemented" << std::endl;
zkevm_word_type A = current_state.stack_top();
auto a = w_to_16(A);
for( std::size_t i = 0; i < a_chunks.size(); i++ ){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ namespace nil {
{
TYPE addr;
if constexpr( stage == GenerationStage::ASSIGNMENT ){
std::cout << "\tASSIGNMENT implemented" << std::endl;
auto add_chunks = nil::blueprint::w_to_16(current_state.stack_top());
addr = add_chunks[15];
}
Expand Down Expand Up @@ -134,8 +133,6 @@ namespace nil {
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.rw_counter_next() - current_state.rw_counter(0)); // rw_counter transition
} else {
std::cout << "\tASSIGNMENT implemented" << std::endl;
}
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ namespace nil {
TYPE is_jump;
TYPE new_pc;
if constexpr( stage == GenerationStage::ASSIGNMENT ){
std::cout << "\tASSIGNMENT implemented" << std::endl;
addr = nil::blueprint::w_to_16(current_state.stack_top())[15];
auto c_chunks = nil::blueprint::w_to_16(current_state.stack_top(1));
for( std::size_t i = 0; i < 16; i++ ){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,6 @@ namespace nil {
hash_lo
};
lookup(tmp, "zkevm_rw");
} else {
std::cout << "\tASSIGNMENT implemented" << std::endl;
}
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,6 @@ namespace nil {
V_128.second // addr is smaller than maximum contract size
};
lookup(tmp, "zkevm_rw");
} else {
std::cout << "\tASSIGNMENT implemented" << std::endl;
}
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ namespace nil {
// TYPE memory_quad_r;
std::vector<TYPE> value(32);
if constexpr( stage == GenerationStage::ASSIGNMENT ){
std::cout << "\tASSIGNMENT implemented" << std::endl;
auto address = w_to_16(current_state.stack_top())[15];
addr = address;
addr1 = address;
Expand Down Expand Up @@ -204,8 +203,6 @@ namespace nil {
lookup(tmp, "zkevm_rw");
}
}
} else {
std::cout << "\tASSIGNMENT implemented" << std::endl;
}
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ namespace nil {
// TYPE memory_quad_r;
std::vector<TYPE> value(32);
if constexpr( stage == GenerationStage::ASSIGNMENT ){
std::cout << "\tASSIGNMENT implemented" << std::endl;
auto address = w_to_16(current_state.stack_top())[15];
addr = address;
addr1 = address;
Expand Down Expand Up @@ -186,8 +185,6 @@ namespace nil {
value[31] // addr is smaller than maximum contract size
};
lookup(tmp, "zkevm_rw");
} else {
std::cout << "\tASSIGNMENT implemented" << std::endl;
}
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,6 @@ namespace nil {
R_128.second
};
lookup(tmp, "zkevm_rw");
} else {
std::cout << "\tAssignment implemented" << std::endl;
}
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -623,8 +623,6 @@ namespace nil {
Res0,
Res1};
lookup(tmp, "zkevm_rw");
} else {
std::cout << "\tASSIGNMENT implemented" << std::endl;
}
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,6 @@ namespace nil {
R_128.second
};
lookup(tmp, "zkevm_rw");
} else {
std::cout << "Assignment implemented" << std::endl;
}
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,6 @@ namespace nil {
constrain(current_state.stack_size(0) - current_state.stack_size_next() - 1); // stack_size transition
constrain(current_state.memory_size(0) - current_state.memory_size_next()); // 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
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,6 @@ namespace nil {
// 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.rw_counter_next() - current_state.rw_counter(0)); // rw_counter transition
} else {
// std::cout << "\tASSIGNMENT implemented" << std::endl;
}
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,6 @@ namespace nil {
allocate(V[i], i,0);
allocate(K_hi, 32, 0);
allocate(K_lo, 33, 0);
std::cout << "\tK_hi = " << K_hi << std::endl;
std::cout << "\tK_lo = " << K_lo << std::endl;
auto V_128 = chunks16_to_chunks128<TYPE>(V);
if constexpr( stage == GenerationStage::CONSTRAINTS ){
constrain(current_state.pc_next() - current_state.pc(0) - 1); // PC transition
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ namespace nil {
std::vector<TYPE> B_chunks(16);
if constexpr( stage == GenerationStage::ASSIGNMENT ){
// std::cout << "\tinput=" << std::hex << current_state.additional_input << std::dec << std::endl;
std::cout << "\tASSIGNMENT implemented" << std::endl;
auto A = current_state.stack_top();
auto A16 = nil::blueprint::w_to_16(A);
auto B = current_state.stack_top(x);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ namespace nil {

std::size_t cur = 0;
for(std::size_t i = 0; i < bytecodes.size(); i++) {
std::cout << "Bytecode " << i << " size = " << bytecodes[i].first.size() << std::endl;
TYPE hash_hi_val = w_hi<FieldType>(bytecodes[i].second);
TYPE hash_lo_val = w_lo<FieldType>(bytecodes[i].second);
TYPE push_size = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ namespace nil {
) :
max_blocks(max_blocks_),
generic_component<FieldType,stage>(context_object) {
std::cout << "a";
if constexpr (stage == GenerationStage::ASSIGNMENT) {
TYPE theta = input.rlc_challenge;

Expand Down
19 changes: 9 additions & 10 deletions crypto3/libs/blueprint/include/nil/blueprint/zkevm_bbf/zkevm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,13 +189,13 @@ namespace nil {
);
std::size_t opcode_id = (std::find(implemented_opcodes.begin(), implemented_opcodes.end(), current_opcode) - implemented_opcodes.begin());
std::cout << current_opcode
<< " with id = " << opcode_id
<< " will be assigned as " << std::hex << current_state.opcode << std::dec
<< " id = " << opcode_id
//<< " assigned as " << std::hex << current_state.opcode << std::dec
<< " on row " << current_row
<< " rows_amount = " << current_opcode_rows_amount
<< " stack_size = " << current_state.stack_size
<< " memory_size = " << current_state.memory_size
<< " rw_counter = 0x" << std::hex<< current_state.rw_counter << std::dec
<< " uses " << current_opcode_rows_amount << " rows"
<< " STS = " << current_state.stack_size
<< " MS = " << current_state.memory_size
<< " RWC = 0x" << std::hex<< current_state.rw_counter << std::dec
<< " gas = " << current_state.gas
// << " bytecode_hash = " << current_state.bytecode_hash
<< std::endl;
Expand Down Expand Up @@ -352,9 +352,9 @@ namespace nil {
TYPE evm_opcode_constraint;
for( std::size_t opcode_num = 0; opcode_num < implemented_opcodes_amount; opcode_num++){
zkevm_opcode current_opcode = implemented_opcodes[opcode_num];
if( opcode_impls.find(current_opcode) == opcode_impls.end() ) {
std::cout << "Opcode " << current_opcode <<" implementation not found" << std::endl;
}
// if( opcode_impls.find(current_opcode) == opcode_impls.end() ) {
// std::cout << "Opcode " << current_opcode <<" implementation not found" << std::endl;
// }
std::size_t current_opcode_bare_rows_amount =
opcode_impls.find(current_opcode) == opcode_impls.end()?
0:
Expand Down Expand Up @@ -441,7 +441,6 @@ namespace nil {

opcode_impls[current_opcode]->fill_context(fresh_ct, opcode_state_vars);
auto opcode_constraints = fresh_ct.get_constraints();
std::cout << "Opcode " << current_opcode << std::endl;
for( const auto &constr_list: opcode_constraints){
for( const auto &local_row: constr_list.first){
for( auto constraint: constr_list.second){
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"bytecode":"0x608060405234801561001057600080fd5b506004361061002b5760003560e01c80636d4f5c9014610030575b600080fd5b61003861004a565b60405190815260200160405180910390f35b600080546040805162dc4c0f60e61b815290516001600160a01b0390921691829163371303c0916004808301926020929190829003018188875af1158015610096573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906100ba9190610126565b9150806001600160a01b031663371303c06040518163ffffffff1660e01b81526004016020604051808303816000875af11580156100fc573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906101209190610126565b91505090565b60006020828403121561013857600080fd5b505191905056"}
Loading

0 comments on commit bde6c51

Please sign in to comment.