Skip to content

Commit

Permalink
domains test (#89)
Browse files Browse the repository at this point in the history
  • Loading branch information
neotheprogramist authored Jan 23, 2024
1 parent 6c7d5a9 commit cdbcfcc
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 6 deletions.
34 changes: 29 additions & 5 deletions src/domains.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use cairo_verifier::{
};

// Information about the domains that are used in the stark proof.
#[derive(Drop, Copy)]
#[derive(Drop, Copy, PartialEq)]
struct StarkDomains {
// Log2 of the evaluation domain size.
log_eval_domain_size: felt252,
Expand All @@ -23,14 +23,14 @@ struct StarkDomains {

#[generate_trait]
impl StarkDomainsImpl of StarkDomainsTrait {
fn new(stark_config: @StarkConfig) -> StarkDomains {
fn new(log_trace_domain_size: felt252, log_n_cosets: felt252) -> StarkDomains {
// Compute stark_domains.
let log_eval_domain_size = *stark_config.log_trace_domain_size + *stark_config.log_n_cosets;
let log_eval_domain_size = log_trace_domain_size + log_n_cosets;
let eval_domain_size = pow(2, log_eval_domain_size);
let eval_generator = pow(
FIELD_GENERATOR, STARK_PRIME_MINUS_ONE * mul_inverse(eval_domain_size)
);
let trace_domain_size = pow(2, *stark_config.log_trace_domain_size);
let trace_domain_size = pow(2, log_trace_domain_size);
let trace_generator = pow(
FIELD_GENERATOR, STARK_PRIME_MINUS_ONE * mul_inverse(trace_domain_size)
);
Expand All @@ -39,9 +39,33 @@ impl StarkDomainsImpl of StarkDomainsTrait {
log_eval_domain_size,
eval_domain_size,
eval_generator,
log_trace_domain_size: *stark_config.log_trace_domain_size,
log_trace_domain_size,
trace_domain_size,
trace_generator,
}
}
}

#[cfg(test)]
mod tests {
use cairo_verifier::domains::{StarkDomains, StarkDomainsTrait};
// test generated based on cairo0-verifier run on fib proof from stone-prover
#[test]
#[available_gas(9999999999)]
fn test_domain_creation() {
let log_trace_domain_size = 0x12;
let log_n_cosets = 0x4;
let expected_result = StarkDomains {
log_eval_domain_size: 0x16,
eval_domain_size: 0x400000,
eval_generator: 0x3e4383531eeac7c9822fb108d24a344d841544dd6482f17ead331453e3a2f4b,
log_trace_domain_size: 0x12,
trace_domain_size: 0x40000,
trace_generator: 0x4768803ef85256034f67453635f87997ff61841e411ee63ce7b0a8b9745a046,
};

let result = StarkDomainsTrait::new(log_trace_domain_size, log_n_cosets);

assert(result == expected_result, 'Domain creation failed')
}
}
4 changes: 3 additions & 1 deletion src/stark.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ struct StarkProof {
impl StarkProofImpl of StarkProofTrait {
fn verify(self: @StarkProof) {
self.config.validate(SECURITY_BITS);
let stark_domains = StarkDomainsImpl::new(self.config);
let stark_domains = StarkDomainsImpl::new(
*self.config.log_trace_domain_size, *self.config.log_n_cosets
);

let digest = self.public_input.get_public_input_hash();
let mut channel = ChannelImpl::new(digest);
Expand Down

0 comments on commit cdbcfcc

Please sign in to comment.