Skip to content

Commit

Permalink
Internal commitment scheme#21
Browse files Browse the repository at this point in the history
  • Loading branch information
ETatuzova authored and nkaskov committed Oct 4, 2023
1 parent 3d97686 commit b203e04
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
7 changes: 7 additions & 0 deletions include/nil/blueprint/transpiler/lpc_scheme_gen.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,12 @@ namespace nil {
}
i++;
}

std::vector<std::uint8_t> init_blob = {};
nil::crypto3::zk::transcript::fiat_shamir_heuristic_sequential<typename PlaceholderParams::transcript_hash_type> transcript(init_blob);
transcript(common_data.vk.constraint_system_hash);
transcript(common_data.vk.fixed_values_commitment);
auto etha = transcript.template challenge<typename PlaceholderParams::field_type>();

auto fri_params = lpc_scheme.get_fri_params();
replacements["$R$"] = to_string(fri_params.r);
Expand All @@ -141,6 +147,7 @@ namespace nil {
replacements["$LOOKUP_POINTS_ID$"] = to_string(lookup_point_id);
replacements["$POINTS_IDS$"] = points_ids.str();
replacements["$POINTS_INITIALIZATION$"] = points_initializer.str();
replacements["$ETHA$"] = to_string(etha);
if( PlaceholderParams::commitment_scheme_type::fri_type::use_grinding){
replacements["$GRINDING_CHECK$"] = modular_commitment_grinding_check_template;
} else {
Expand Down
11 changes: 6 additions & 5 deletions include/nil/blueprint/transpiler/templates/commitment_scheme.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import "../../containers/merkle_verifier.sol";
import "../../algebra/polynomial.sol";
import "hardhat/console.sol";
contract modular_commitment_scheme_$TEST_NAME$ {
library modular_commitment_scheme_$TEST_NAME$ {
uint256 constant modulus = $MODULUS$;
uint64 constant batches_num = $BATCHES_NUM$;
uint256 constant r = $R$;
Expand All @@ -53,7 +53,7 @@ contract modular_commitment_scheme_$TEST_NAME$ {
uint256 constant lookup_point = $LOOKUP_POINTS_ID$;
bytes constant points_ids = hex"$POINTS_IDS$";
uint256 constant omega = $OMEGA$;
uint256 _etha;
uint256 constant _etha = $ETHA$;
struct commitment_state{
bytes leaf_data;
Expand Down Expand Up @@ -287,10 +287,11 @@ contract modular_commitment_scheme_$TEST_NAME$ {
function initialize(
bytes32 tr_state_before
) external returns(bytes32 tr_state_after){
) internal returns(bytes32 tr_state_after){
types.transcript_data memory tr_state;
tr_state.current_challenge = tr_state_before;
_etha = transcript.get_field_challenge(tr_state, modulus);
uint256 etha = transcript.get_field_challenge(tr_state, modulus);
require(etha == _etha, "Wrong etha");
tr_state_after = tr_state.current_challenge;
}
Expand Down Expand Up @@ -413,7 +414,7 @@ contract modular_commitment_scheme_$TEST_NAME$ {
uint256[5] memory commitments,
uint256 challenge,
bytes32 transcript_state
) external view returns (bool){
) internal view returns (bool){
types.transcript_data memory tr_state;
tr_state.current_challenge = transcript_state;
commitment_state memory state;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,9 @@ contract modular_verifier_$TEST_NAME$ is IModularVerifier{
_gate_argument_address = gate_argument_address;
_commitment_contract_address = commitment_contract_address;
ICommitmentScheme commitment_scheme = ICommitmentScheme(commitment_contract_address);
tr_state.current_challenge = commitment_scheme.initialize(tr_state.current_challenge);
// ICommitmentScheme commitment_scheme = ICommitmentScheme(commitment_contract_address);
// tr_state.current_challenge = commitment_scheme.initialize(tr_state.current_challenge);
tr_state.current_challenge = modular_commitment_scheme_$TEST_NAME$.initialize(tr_state.current_challenge);
transcript_state = tr_state.current_challenge;
}
Expand Down Expand Up @@ -169,14 +170,14 @@ contract modular_verifier_$TEST_NAME$ is IModularVerifier{
bool b = true;
//8. Commitment scheme verify_eval
{
ICommitmentScheme commitment_scheme = ICommitmentScheme(_commitment_contract_address);
// ICommitmentScheme commitment_scheme = ICommitmentScheme(_commitment_contract_address);
uint256[5] memory commitments;
commitments[0] = uint256(vk2);
for(uint16 i = 1; i < $BATCHES_NUM$;){
commitments[i] = basic_marshalling.get_uint256_be(blob, 0x9 + (i-1)*(0x28));
unchecked{i++;}
}
if(!commitment_scheme.verify_eval(
if(!modular_commitment_scheme_$TEST_NAME$.verify_eval(
blob[z_offset - 0x8:], commitments, xi, tr_state.current_challenge
)) {
console.log("Error from commitment scheme!");
Expand Down

0 comments on commit b203e04

Please sign in to comment.