Skip to content
This repository was archived by the owner on Feb 17, 2025. It is now read-only.

Commit b203e04

Browse files
ETatuzovankaskov
authored andcommitted
Internal commitment scheme#21
1 parent 3d97686 commit b203e04

File tree

3 files changed

+18
-9
lines changed

3 files changed

+18
-9
lines changed

include/nil/blueprint/transpiler/lpc_scheme_gen.hpp

+7
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,12 @@ namespace nil {
127127
}
128128
i++;
129129
}
130+
131+
std::vector<std::uint8_t> init_blob = {};
132+
nil::crypto3::zk::transcript::fiat_shamir_heuristic_sequential<typename PlaceholderParams::transcript_hash_type> transcript(init_blob);
133+
transcript(common_data.vk.constraint_system_hash);
134+
transcript(common_data.vk.fixed_values_commitment);
135+
auto etha = transcript.template challenge<typename PlaceholderParams::field_type>();
130136

131137
auto fri_params = lpc_scheme.get_fri_params();
132138
replacements["$R$"] = to_string(fri_params.r);
@@ -141,6 +147,7 @@ namespace nil {
141147
replacements["$LOOKUP_POINTS_ID$"] = to_string(lookup_point_id);
142148
replacements["$POINTS_IDS$"] = points_ids.str();
143149
replacements["$POINTS_INITIALIZATION$"] = points_initializer.str();
150+
replacements["$ETHA$"] = to_string(etha);
144151
if( PlaceholderParams::commitment_scheme_type::fri_type::use_grinding){
145152
replacements["$GRINDING_CHECK$"] = modular_commitment_grinding_check_template;
146153
} else {

include/nil/blueprint/transpiler/templates/commitment_scheme.hpp

+6-5
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ import "../../containers/merkle_verifier.sol";
3939
import "../../algebra/polynomial.sol";
4040
import "hardhat/console.sol";
4141
42-
contract modular_commitment_scheme_$TEST_NAME$ {
42+
library modular_commitment_scheme_$TEST_NAME$ {
4343
uint256 constant modulus = $MODULUS$;
4444
uint64 constant batches_num = $BATCHES_NUM$;
4545
uint256 constant r = $R$;
@@ -53,7 +53,7 @@ contract modular_commitment_scheme_$TEST_NAME$ {
5353
uint256 constant lookup_point = $LOOKUP_POINTS_ID$;
5454
bytes constant points_ids = hex"$POINTS_IDS$";
5555
uint256 constant omega = $OMEGA$;
56-
uint256 _etha;
56+
uint256 constant _etha = $ETHA$;
5757
5858
struct commitment_state{
5959
bytes leaf_data;
@@ -287,10 +287,11 @@ contract modular_commitment_scheme_$TEST_NAME$ {
287287
288288
function initialize(
289289
bytes32 tr_state_before
290-
) external returns(bytes32 tr_state_after){
290+
) internal returns(bytes32 tr_state_after){
291291
types.transcript_data memory tr_state;
292292
tr_state.current_challenge = tr_state_before;
293-
_etha = transcript.get_field_challenge(tr_state, modulus);
293+
uint256 etha = transcript.get_field_challenge(tr_state, modulus);
294+
require(etha == _etha, "Wrong etha");
294295
tr_state_after = tr_state.current_challenge;
295296
}
296297
@@ -413,7 +414,7 @@ contract modular_commitment_scheme_$TEST_NAME$ {
413414
uint256[5] memory commitments,
414415
uint256 challenge,
415416
bytes32 transcript_state
416-
) external view returns (bool){
417+
) internal view returns (bool){
417418
types.transcript_data memory tr_state;
418419
tr_state.current_challenge = transcript_state;
419420
commitment_state memory state;

include/nil/blueprint/transpiler/templates/modular_verifier.hpp

+5-4
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,9 @@ contract modular_verifier_$TEST_NAME$ is IModularVerifier{
9393
_gate_argument_address = gate_argument_address;
9494
_commitment_contract_address = commitment_contract_address;
9595
96-
ICommitmentScheme commitment_scheme = ICommitmentScheme(commitment_contract_address);
97-
tr_state.current_challenge = commitment_scheme.initialize(tr_state.current_challenge);
96+
// ICommitmentScheme commitment_scheme = ICommitmentScheme(commitment_contract_address);
97+
// tr_state.current_challenge = commitment_scheme.initialize(tr_state.current_challenge);
98+
tr_state.current_challenge = modular_commitment_scheme_$TEST_NAME$.initialize(tr_state.current_challenge);
9899
transcript_state = tr_state.current_challenge;
99100
}
100101
@@ -169,14 +170,14 @@ contract modular_verifier_$TEST_NAME$ is IModularVerifier{
169170
bool b = true;
170171
//8. Commitment scheme verify_eval
171172
{
172-
ICommitmentScheme commitment_scheme = ICommitmentScheme(_commitment_contract_address);
173+
// ICommitmentScheme commitment_scheme = ICommitmentScheme(_commitment_contract_address);
173174
uint256[5] memory commitments;
174175
commitments[0] = uint256(vk2);
175176
for(uint16 i = 1; i < $BATCHES_NUM$;){
176177
commitments[i] = basic_marshalling.get_uint256_be(blob, 0x9 + (i-1)*(0x28));
177178
unchecked{i++;}
178179
}
179-
if(!commitment_scheme.verify_eval(
180+
if(!modular_commitment_scheme_$TEST_NAME$.verify_eval(
180181
blob[z_offset - 0x8:], commitments, xi, tr_state.current_challenge
181182
)) {
182183
console.log("Error from commitment scheme!");

0 commit comments

Comments
 (0)