diff --git a/src/domains.cairo b/src/domains.cairo index e1db84264..3e09c7909 100644 --- a/src/domains.cairo +++ b/src/domains.cairo @@ -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, @@ -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) ); @@ -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') + } +} diff --git a/src/stark.cairo b/src/stark.cairo index d868bf1c4..d20288410 100644 --- a/src/stark.cairo +++ b/src/stark.cairo @@ -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);