Skip to content

Commit

Permalink
Initial deployment test #279
Browse files Browse the repository at this point in the history
  • Loading branch information
ETatuzova committed Jan 17, 2025
1 parent d17b24d commit f9f4abc
Show file tree
Hide file tree
Showing 10 changed files with 52 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -336,8 +336,6 @@ namespace nil {

} else if(opcode == "CODECOPY") {
// 0x39
std::cout << "CODECOPY not implemented" << std::endl;
exit(2);
_rw_operations.push_back(stack_rw_operation(call_id, stack.size()-1, rw_counter++, false, stack[stack.size()-1]));
_rw_operations.push_back(stack_rw_operation(call_id, stack.size()-2, rw_counter++, false, stack[stack.size()-2]));
_rw_operations.push_back(stack_rw_operation(call_id, stack.size()-3, rw_counter++, false, stack[stack.size()-3]));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ namespace nil {
std::cout << "\tExponentiation: " << a << " ^ " << d << std::endl;
_exponentiations.push_back({a, d});
pc++;
//gas -= (d == 0) ? 10 : (10 + 10 * (1 + log256(d)));
gas -= 10 + 50 * count_significant_bytes(d);
} else if (opcode == zkevm_opcode::SIGNEXTEND){
// 0x0b
zkevm_word_type b = stack.back();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#pragma once

#include <numeric>
#include <algorithm>

#include <nil/blueprint/zkevm/zkevm_word.hpp>
#include <nil/blueprint/zkevm_bbf/types/opcode.hpp>
#include <nil/blueprint/zkevm_bbf/opcodes/dummy.hpp>

namespace nil {
namespace blueprint {
namespace bbf{

template<typename FieldType>
using zkevm_codecopy_operation = zkevm_dummy_operation<FieldType>;
} // namespace bbf
} // namespace blueprint
} // namespace nil
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
#include <nil/blueprint/zkevm_bbf/opcodes/pop.hpp>
#include <nil/blueprint/zkevm_bbf/opcodes/eq.hpp>
#include <nil/blueprint/zkevm_bbf/opcodes/calldatacopy.hpp>
#include <nil/blueprint/zkevm_bbf/opcodes/codecopy.hpp>
#include <nil/blueprint/zkevm_bbf/opcodes/stop.hpp>
#include <nil/blueprint/zkevm_bbf/opcodes/exp.hpp>
#include <nil/blueprint/zkevm_bbf/opcodes/keccak.hpp>
Expand Down Expand Up @@ -647,6 +648,7 @@ namespace nil {
opcodes[zkevm_opcode::CALLDATASIZE] = std::make_shared<zkevm_calldatasize_operation<BlueprintFieldType>>();
opcodes[zkevm_opcode::CALLDATALOAD] = std::make_shared<zkevm_calldataload_operation<BlueprintFieldType>>();
opcodes[zkevm_opcode::CALLDATACOPY] = std::make_shared<zkevm_calldatacopy_operation<BlueprintFieldType>>();
opcodes[zkevm_opcode::CODECOPY] = std::make_shared<zkevm_codecopy_operation<BlueprintFieldType>>();

// // PC operations
opcodes[zkevm_opcode::JUMPI] = std::make_shared<zkevm_jumpi_operation<BlueprintFieldType>>();
Expand Down
13 changes: 5 additions & 8 deletions crypto3/libs/blueprint/include/nil/blueprint/zkevm_bbf/util.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,11 @@ namespace nil {
return exp2;
}

std::size_t log256(zkevm_word_type d) {
std::size_t result = 0;
while(d > 0){
d /= 256u;
result++;
}
return result;
std::size_t count_significant_bytes(zkevm_word_type d) {
std::size_t count = 0;
while (d > 0) d /= 256u, ++count;
return count;
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ namespace nil {
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 << "\tImplementation for "<< current_opcode << " is not defined" << std::endl;
//std::cout << "\tImplementation for "<< current_opcode << " is not defined" << std::endl;
continue;
}
std::size_t current_opcode_bare_rows_amount = opcode_impls[current_opcode]->rows_amount();
Expand All @@ -441,6 +441,7 @@ 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 Expand Up @@ -472,12 +473,12 @@ namespace nil {
std::cout << "Accumulate constraints " << max_opcode_row_constraints << std::endl;
for( std::size_t i = 0; i < max_opcode_row_constraints; i++ ){
TYPE acc_constraint;
// std::cout << "\tConstraint " << i << std::endl;
//std::cout << "\tConstraint " << i << std::endl;
for( auto &[pair, constraints]: opcode_constraints_aggregator ){
if( constraints.size() <= i) continue;
acc_constraint += context_object.relativize(zkevm_opcode_row_selectors[pair], -1) * constraints[i];
//std::cout << "\topcode " << pair.first << " row " << pair.second << " constraint " << context_object.relativize(zkevm_opcode_row_selectors[pair], -1) * constraints[i] << std::endl;
//relative_mc.push_back(context_object.relativize(zkevm_opcode_row_selectors[pair], -1) * constraints[i]);
relative_mc.push_back(context_object.relativize(zkevm_opcode_row_selectors[pair], -1) * constraints[i]);
}
relative_mc.push_back(acc_constraint);
//std::cout << "\t" << acc_constraint << std::endl;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"bytecode":"0x6080604052600160005534801561001557600080fd5b506101cf806100256000396000f3fe608060405234801561001057600080fd5b506004361061002b5760003560e01c806371e80b5814610030575b600080fd5b61004361003e3660046100f6565b610055565b60405190815260200160405180910390f35b6000805b60058160ff1610156100c157828160ff166005811061007a5761007a61012c565b6020020135848260ff16600581106100945761009461012c565b60200201356100a39190610158565b6100ad9083610188565b9150806100b9816101b0565b915050610059565b50806000808282546100d39190610188565b90915550909392505050565b8060a081018310156100f057600080fd5b92915050565b600080610140838503121561010a57600080fd5b61011484846100df565b91506101238460a085016100df565b90509250929050565b634e487b7160e01b600052603260045260246000fd5b634e487b7160e01b600052601160045260246000fd5b80820260008212600160ff1b8414161561017457610174610142565b81810583148215176100f0576100f0610142565b80820182811260008312801582168215821617156101a8576101a8610142565b505092915050565b600060ff821660ff81036101c6576101c6610142565b6001019291505056"}
1 change: 1 addition & 0 deletions crypto3/libs/blueprint/test/zkevm/data/deploy/trace0.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"jsonrpc":"2.0","id":1,"result":{"failed":false,"gas":175363,"returnValue":"0x608060405234801561001057600080fd5b506004361061002b5760003560e01c806371e80b5814610030575b600080fd5b61004361003e3660046100f6565b610055565b60405190815260200160405180910390f35b6000805b60058160ff1610156100c157828160ff166005811061007a5761007a61012c565b6020020135848260ff16600581106100945761009461012c565b60200201356100a39190610158565b6100ad9083610188565b9150806100b9816101b0565b915050610059565b50806000808282546100d39190610188565b90915550909392505050565b8060a081018310156100f057600080fd5b92915050565b600080610140838503121561010a57600080fd5b61011484846100df565b91506101238460a085016100df565b90509250929050565b634e487b7160e01b600052603260045260246000fd5b634e487b7160e01b600052601160045260246000fd5b80820260008212600160ff1b8414161561017457610174610142565b81810583148215176100f0576100f0610142565b80820182811260008312801582168215821617156101a8576101a8610142565b505092915050565b600060ff821660ff81036101c6576101c6610142565b6001019291505056","structLogs":[{"depth":1,"gas":114847,"gasCost":3,"op":"PUSH1","pc":0,"memory":[],"stack":[],"storage":{}},{"depth":1,"gas":114844,"gasCost":3,"op":"PUSH1","pc":2,"memory":[],"stack":["0000000000000000000000000000000000000000000000000000000000000080"],"storage":{}},{"depth":1,"gas":114841,"gasCost":12,"op":"MSTORE","pc":4,"memory":[],"stack":["0000000000000000000000000000000000000000000000000000000000000080","0000000000000000000000000000000000000000000000000000000000000040"],"storage":{}},{"depth":1,"gas":114829,"gasCost":3,"op":"PUSH1","pc":5,"memory":["0000000000000000000000000000000000000000000000000000000000000000","0000000000000000000000000000000000000000000000000000000000000000","0000000000000000000000000000000000000000000000000000000000000080"],"stack":[],"storage":{}},{"depth":1,"gas":114826,"gasCost":3,"op":"PUSH1","pc":7,"memory":["0000000000000000000000000000000000000000000000000000000000000000","0000000000000000000000000000000000000000000000000000000000000000","0000000000000000000000000000000000000000000000000000000000000080"],"stack":["0000000000000000000000000000000000000000000000000000000000000001"],"storage":{}},{"depth":1,"gas":114823,"gasCost":22100,"op":"SSTORE","pc":9,"memory":["0000000000000000000000000000000000000000000000000000000000000000","0000000000000000000000000000000000000000000000000000000000000000","0000000000000000000000000000000000000000000000000000000000000080"],"stack":["0000000000000000000000000000000000000000000000000000000000000001","0000000000000000000000000000000000000000000000000000000000000000"],"storage":{"0000000000000000000000000000000000000000000000000000000000000000":"0000000000000000000000000000000000000000000000000000000000000001"}},{"depth":1,"gas":92723,"gasCost":2,"op":"CALLVALUE","pc":10,"memory":["0000000000000000000000000000000000000000000000000000000000000000","0000000000000000000000000000000000000000000000000000000000000000","0000000000000000000000000000000000000000000000000000000000000080"],"stack":[],"storage":{"0000000000000000000000000000000000000000000000000000000000000000":"0000000000000000000000000000000000000000000000000000000000000001"}},{"depth":1,"gas":92721,"gasCost":3,"op":"DUP1","pc":11,"memory":["0000000000000000000000000000000000000000000000000000000000000000","0000000000000000000000000000000000000000000000000000000000000000","0000000000000000000000000000000000000000000000000000000000000080"],"stack":["0000000000000000000000000000000000000000000000000000000000000000"],"storage":{"0000000000000000000000000000000000000000000000000000000000000000":"0000000000000000000000000000000000000000000000000000000000000001"}},{"depth":1,"gas":92718,"gasCost":3,"op":"ISZERO","pc":12,"memory":["0000000000000000000000000000000000000000000000000000000000000000","0000000000000000000000000000000000000000000000000000000000000000","0000000000000000000000000000000000000000000000000000000000000080"],"stack":["0000000000000000000000000000000000000000000000000000000000000000","0000000000000000000000000000000000000000000000000000000000000000"],"storage":{"0000000000000000000000000000000000000000000000000000000000000000":"0000000000000000000000000000000000000000000000000000000000000001"}},{"depth":1,"gas":92715,"gasCost":3,"op":"PUSH2","pc":13,"memory":["0000000000000000000000000000000000000000000000000000000000000000","0000000000000000000000000000000000000000000000000000000000000000","0000000000000000000000000000000000000000000000000000000000000080"],"stack":["0000000000000000000000000000000000000000000000000000000000000000","0000000000000000000000000000000000000000000000000000000000000001"],"storage":{"0000000000000000000000000000000000000000000000000000000000000000":"0000000000000000000000000000000000000000000000000000000000000001"}},{"depth":1,"gas":92712,"gasCost":10,"op":"JUMPI","pc":16,"memory":["0000000000000000000000000000000000000000000000000000000000000000","0000000000000000000000000000000000000000000000000000000000000000","0000000000000000000000000000000000000000000000000000000000000080"],"stack":["0000000000000000000000000000000000000000000000000000000000000000","0000000000000000000000000000000000000000000000000000000000000001","0000000000000000000000000000000000000000000000000000000000000015"],"storage":{"0000000000000000000000000000000000000000000000000000000000000000":"0000000000000000000000000000000000000000000000000000000000000001"}},{"depth":1,"gas":92702,"gasCost":1,"op":"JUMPDEST","pc":21,"memory":["0000000000000000000000000000000000000000000000000000000000000000","0000000000000000000000000000000000000000000000000000000000000000","0000000000000000000000000000000000000000000000000000000000000080"],"stack":["0000000000000000000000000000000000000000000000000000000000000000"],"storage":{"0000000000000000000000000000000000000000000000000000000000000000":"0000000000000000000000000000000000000000000000000000000000000001"}},{"depth":1,"gas":92701,"gasCost":2,"op":"POP","pc":22,"memory":["0000000000000000000000000000000000000000000000000000000000000000","0000000000000000000000000000000000000000000000000000000000000000","0000000000000000000000000000000000000000000000000000000000000080"],"stack":["0000000000000000000000000000000000000000000000000000000000000000"],"storage":{"0000000000000000000000000000000000000000000000000000000000000000":"0000000000000000000000000000000000000000000000000000000000000001"}},{"depth":1,"gas":92699,"gasCost":3,"op":"PUSH2","pc":23,"memory":["0000000000000000000000000000000000000000000000000000000000000000","0000000000000000000000000000000000000000000000000000000000000000","0000000000000000000000000000000000000000000000000000000000000080"],"stack":[],"storage":{"0000000000000000000000000000000000000000000000000000000000000000":"0000000000000000000000000000000000000000000000000000000000000001"}},{"depth":1,"gas":92696,"gasCost":3,"op":"DUP1","pc":26,"memory":["0000000000000000000000000000000000000000000000000000000000000000","0000000000000000000000000000000000000000000000000000000000000000","0000000000000000000000000000000000000000000000000000000000000080"],"stack":["00000000000000000000000000000000000000000000000000000000000001cf"],"storage":{"0000000000000000000000000000000000000000000000000000000000000000":"0000000000000000000000000000000000000000000000000000000000000001"}},{"depth":1,"gas":92693,"gasCost":3,"op":"PUSH2","pc":27,"memory":["0000000000000000000000000000000000000000000000000000000000000000","0000000000000000000000000000000000000000000000000000000000000000","0000000000000000000000000000000000000000000000000000000000000080"],"stack":["00000000000000000000000000000000000000000000000000000000000001cf","00000000000000000000000000000000000000000000000000000000000001cf"],"storage":{"0000000000000000000000000000000000000000000000000000000000000000":"0000000000000000000000000000000000000000000000000000000000000001"}},{"depth":1,"gas":92690,"gasCost":3,"op":"PUSH1","pc":30,"memory":["0000000000000000000000000000000000000000000000000000000000000000","0000000000000000000000000000000000000000000000000000000000000000","0000000000000000000000000000000000000000000000000000000000000080"],"stack":["00000000000000000000000000000000000000000000000000000000000001cf","00000000000000000000000000000000000000000000000000000000000001cf","0000000000000000000000000000000000000000000000000000000000000025"],"storage":{"0000000000000000000000000000000000000000000000000000000000000000":"0000000000000000000000000000000000000000000000000000000000000001"}},{"depth":1,"gas":92687,"gasCost":84,"op":"CODECOPY","pc":32,"memory":["0000000000000000000000000000000000000000000000000000000000000000","0000000000000000000000000000000000000000000000000000000000000000","0000000000000000000000000000000000000000000000000000000000000080"],"stack":["00000000000000000000000000000000000000000000000000000000000001cf","00000000000000000000000000000000000000000000000000000000000001cf","0000000000000000000000000000000000000000000000000000000000000025","0000000000000000000000000000000000000000000000000000000000000000"],"storage":{"0000000000000000000000000000000000000000000000000000000000000000":"0000000000000000000000000000000000000000000000000000000000000001"}},{"depth":1,"gas":92603,"gasCost":3,"op":"PUSH1","pc":33,"memory":["608060405234801561001057600080fd5b506004361061002b5760003560e01c","806371e80b5814610030575b600080fd5b61004361003e3660046100f6565b61","0055565b60405190815260200160405180910390f35b6000805b60058160ff16","10156100c157828160ff166005811061007a5761007a61012c565b6020020135","848260ff16600581106100945761009461012c565b60200201356100a3919061","0158565b6100ad9083610188565b9150806100b9816101b0565b915050610059","565b50806000808282546100d39190610188565b90915550909392505050565b","8060a081018310156100f057600080fd5b92915050565b600080610140838503","121561010a57600080fd5b61011484846100df565b91506101238460a0850161","00df565b90509250929050565b634e487b7160e01b6000526032600452602460","00fd5b634e487b7160e01b600052601160045260246000fd5b80820260008212","600160ff1b8414161561017457610174610142565b81810583148215176100f0","576100f0610142565b80820182811260008312801582168215821617156101a8","576101a8610142565b505092915050565b600060ff821660ff81036101c65761","01c6610142565b60010192915050560000000000000000000000000000000000"],"stack":["00000000000000000000000000000000000000000000000000000000000001cf"],"storage":{"0000000000000000000000000000000000000000000000000000000000000000":"0000000000000000000000000000000000000000000000000000000000000001"}},{"depth":1,"gas":92600,"gasCost":0,"op":"RETURN","pc":35,"memory":["608060405234801561001057600080fd5b506004361061002b5760003560e01c","806371e80b5814610030575b600080fd5b61004361003e3660046100f6565b61","0055565b60405190815260200160405180910390f35b6000805b60058160ff16","10156100c157828160ff166005811061007a5761007a61012c565b6020020135","848260ff16600581106100945761009461012c565b60200201356100a3919061","0158565b6100ad9083610188565b9150806100b9816101b0565b915050610059","565b50806000808282546100d39190610188565b90915550909392505050565b","8060a081018310156100f057600080fd5b92915050565b600080610140838503","121561010a57600080fd5b61011484846100df565b91506101238460a0850161","00df565b90509250929050565b634e487b7160e01b6000526032600452602460","00fd5b634e487b7160e01b600052601160045260246000fd5b80820260008212","600160ff1b8414161561017457610174610142565b81810583148215176100f0","576100f0610142565b80820182811260008312801582168215821617156101a8","576101a8610142565b505092915050565b600060ff821660ff81036101c65761","01c6610142565b60010192915050560000000000000000000000000000000000"],"stack":["00000000000000000000000000000000000000000000000000000000000001cf","0000000000000000000000000000000000000000000000000000000000000000"],"storage":{"0000000000000000000000000000000000000000000000000000000000000000":"0000000000000000000000000000000000000000000000000000000000000001"}}]}}
17 changes: 17 additions & 0 deletions crypto3/libs/blueprint/test/zkevm_bbf/hardhat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,23 @@ BOOST_AUTO_TEST_CASE(minimal_math) {
complex_test<field_type>(bytecodes, pts, max_sizes);
}

BOOST_AUTO_TEST_CASE(deploy) {
using field_type = typename algebra::curves::pallas::base_field_type;
auto [bytecodes, pts] = load_hardhat_input("deploy/");
l1_size_restrictions max_sizes;

max_sizes.max_keccak_blocks = 10;
max_sizes.max_bytecode = 3000;
max_sizes.max_mpt = 0;
max_sizes.max_rw = 1000;
max_sizes.max_copy = 1000;
max_sizes.max_zkevm_rows = 500;
max_sizes.max_exponentiations = 50;
max_sizes.max_exp_rows = 500;

complex_test<field_type>(bytecodes, pts, max_sizes);
}

BOOST_AUTO_TEST_CASE(modular_operations) {
using field_type = typename algebra::curves::pallas::base_field_type;
auto [bytecodes, pts] = load_hardhat_input("modular_operations/");
Expand Down
Loading

0 comments on commit f9f4abc

Please sign in to comment.