Skip to content

Commit

Permalink
Added grinding mask check in EVM code #49 (#50)
Browse files Browse the repository at this point in the history
* Added grinding mask check in EVM code #49

* added example of custom mask #49 NilFoundation/crypto3-zk-marshalling#53 NilFoundation/evm-placeholder-verification#84
  • Loading branch information
vo-nil authored Nov 8, 2023
1 parent 0f70482 commit 2348688
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
5 changes: 5 additions & 0 deletions include/nil/blueprint/transpiler/lpc_scheme_gen.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,12 @@ namespace nil {
replacements["$POINTS_INITIALIZATION$"] = points_initializer.str();
replacements["$ETHA$"] = to_string(etha);
if( PlaceholderParams::commitment_scheme_type::fri_type::use_grinding){
auto params = PlaceholderParams::commitment_scheme_type::fri_type::grinding_type::get_params();
uint32_t mask_value = params.template get<uint32_t>("mask", 0);
std::stringstream mask_value_hex;
mask_value_hex << std::hex << std::showbase << std::setw(8) << std::setfill('0') << mask_value;
replacements["$GRINDING_CHECK$"] = modular_commitment_grinding_check_template;
replacements["$GRINDING_MASK$"] = mask_value_hex.str();
} else {
replacements["$GRINDING_CHECK$"] = "";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ namespace nil {
std::string modular_commitment_grinding_check_template = R"(
bytes calldata proof_of_work = blob[blob.length - 4:];
transcript.update_transcript(tr_state, proof_of_work);
transcript.get_integral_challenge_be(tr_state, 4);
)";
uint256 p_o_w = transcript.get_integral_challenge_be(tr_state, 4);
if (p_o_w & $GRINDING_MASK$ != 0) return false;
)";

std::string modular_commitment_library_template = R"(
// SPDX-License-Identifier: Apache-2.0.
Expand Down
5 changes: 4 additions & 1 deletion test/transpiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
#include <nil/crypto3/zk/commitments/polynomial/fri.hpp>
#include <nil/crypto3/zk/commitments/polynomial/lpc.hpp>
#include <nil/crypto3/zk/commitments/polynomial/kzg.hpp>
#include <nil/crypto3/zk/commitments/detail/polynomial/proof_of_work.hpp>
#include <nil/crypto3/zk/commitments/batched_commitment.hpp>

#include <nil/crypto3/random/algebraic_random_device.hpp>
Expand Down Expand Up @@ -200,9 +201,11 @@ BOOST_AUTO_TEST_SUITE(placeholder_circuit1)
transcript_hash_type,
placeholder_test_params::lambda,
placeholder_test_params::m,
true
true,
crypto3::zk::commitments::proof_of_work<transcript_hash_type, std::uint32_t, 0xFFFF8000 >
>;


using lpc_type = commitments::list_polynomial_commitment<field_type, lpc_params_type>;
using lpc_scheme_type = typename commitments::lpc_commitment_scheme<lpc_type>;
using lpc_placeholder_params_type = nil::crypto3::zk::snark::placeholder_params<circuit_params, lpc_scheme_type>;
Expand Down

0 comments on commit 2348688

Please sign in to comment.