forked from 0xProject/OpenZKP
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fibonacci proof branch (0xProject#7)
* Added abstract proofs library, multi threading, and improved other systems
- Loading branch information
Showing
14 changed files
with
2,491 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
# IDEs | ||
.vscode | ||
.DS_Store | ||
|
||
# Generated by Cargo | ||
# will have compiled files and executables | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
use hex_literal::*; | ||
use rayon::prelude; | ||
use starkcrypto::fibonacci::*; | ||
use starkcrypto::field::FieldElement; | ||
use starkcrypto::proofs::*; | ||
use starkcrypto::u256::*; | ||
use starkcrypto::u256h; | ||
use std::env; | ||
use std::time::Instant; | ||
|
||
fn main() { | ||
let args: Vec<String> = env::args().collect(); | ||
rayon::ThreadPoolBuilder::new() | ||
.num_threads(args[1].parse::<usize>().unwrap()) | ||
.build_global() | ||
.unwrap(); | ||
|
||
let claim_index = 1000000_u64; | ||
let witness = FieldElement::from(u256h!( | ||
"00000000000000000000000000000000000000000000000000000000cafebabe" | ||
)); | ||
let trace_table = get_trace_table(1048576, witness.clone()); | ||
let claim_fib = trace_table.elements[2000000].clone(); | ||
let start = Instant::now(); | ||
let potential_proof = stark_proof( | ||
&trace_table, | ||
&get_constraint(), | ||
claim_index, | ||
claim_fib, | ||
2_u64.pow(4), | ||
); | ||
let duration = start.elapsed(); | ||
println!("{:?}", potential_proof.digest); | ||
println!("Time elapsed in proof function is: {:?}", duration); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
use hex_literal::*; | ||
use starkcrypto::fibonacci::*; | ||
use starkcrypto::field::FieldElement; | ||
use starkcrypto::proofs::*; | ||
use starkcrypto::u256::*; | ||
use starkcrypto::u256h; | ||
use std::env; | ||
use std::time::Instant; | ||
|
||
fn main() { | ||
let claim_index = 1000_u64; | ||
let claim_fib = FieldElement::from(u256h!( | ||
"0142c45e5d743d10eae7ebb70f1526c65de7dbcdb65b322b6ddc36a812591e8f" | ||
)); | ||
let witness = FieldElement::from(u256h!( | ||
"00000000000000000000000000000000000000000000000000000000cafebabe" | ||
)); | ||
let trace_table = get_trace_table(1024, witness.clone()); | ||
let start = Instant::now(); | ||
let potential_proof = stark_proof( | ||
&trace_table, | ||
&get_constraint(), | ||
claim_index, | ||
claim_fib, | ||
2_u64.pow(4), | ||
); | ||
let duration = start.elapsed(); | ||
println!("{:?}", potential_proof.digest); | ||
println!("Time elapsed in proof function is: {:?}", duration); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
use crate::field::*; | ||
use crate::u256::U256; | ||
use crate::u256h; | ||
use hex_literal::*; | ||
use tiny_keccak::Keccak; | ||
|
||
#[derive(PartialEq, Eq, Clone, Default)] | ||
pub struct Channel { | ||
pub digest: [u8; 32], | ||
pub counter: u64, | ||
pub proof: Vec<u8>, | ||
} | ||
|
||
impl Channel { | ||
pub fn new(data: &[u8]) -> Self { | ||
let mut digest: [u8; 32] = [0; 32]; | ||
let mut sha3 = Keccak::new_keccak256(); | ||
sha3.update(data); | ||
sha3.finalize(&mut digest); | ||
let counter = 0; | ||
let proof = data.to_vec(); | ||
Self { | ||
digest, | ||
counter, | ||
proof, | ||
} | ||
} | ||
pub fn write(&mut self, data: &[u8]) { | ||
self.proof.extend_from_slice(data); | ||
let mut res: [u8; 32] = [0; 32]; | ||
let mut sha3 = Keccak::new_keccak256(); | ||
sha3.update(&self.digest); | ||
sha3.update(data); | ||
sha3.finalize(&mut res); | ||
self.digest = res; | ||
self.counter = 0; | ||
} | ||
pub fn write_element(&mut self, data: &FieldElement) { | ||
self.write(&data.0.to_bytes_be()); | ||
} | ||
pub fn write_element_list(&mut self, data: &[FieldElement]) { | ||
let mut container = Vec::with_capacity(32 * data.len()); | ||
for element in data { | ||
for byte in U256::to_bytes_be(&element.0).iter() { | ||
container.push(byte.clone()); | ||
} | ||
} | ||
self.write(&container.as_slice()); | ||
} | ||
pub fn element(&mut self) -> FieldElement { | ||
loop { | ||
let mut res: [u8; 32] = [0; 32]; | ||
let zero = [0_u8; 24]; | ||
let mut sha3 = Keccak::new_keccak256(); | ||
sha3.update(&self.digest); | ||
sha3.update(&zero); | ||
sha3.update(&self.counter.to_be_bytes()); | ||
sha3.finalize(&mut res); | ||
self.counter += 1; | ||
let seed = U256::from_bytes_be(&res) | ||
% u256h!("1000000000000000000000000000000000000000000000000000000000000000"); //2^256 | ||
if seed < MODULUS { | ||
return FieldElement::from(seed) | ||
/ FieldElement::from(u256h!( | ||
"07fffffffffffdf0ffffffffffffffffffffffffffffffffffffffffffffffe1" | ||
)); | ||
} | ||
} | ||
} | ||
pub fn bytes(&mut self) -> [u8; 32] { | ||
let mut res = [0; 32]; | ||
let zero = [0_u8; 24]; | ||
let mut sha3 = Keccak::new_keccak256(); | ||
|
||
sha3.update(&self.digest); | ||
sha3.update(&zero); | ||
sha3.update(&self.counter.to_be_bytes()); | ||
sha3.finalize(&mut res); | ||
self.counter += 1; | ||
res | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.