-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #507 from chainwayxyz/ozan/old-circuits/cleanup
Old circuits cleanup
- Loading branch information
Showing
40 changed files
with
2,732 additions
and
1,000 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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
name: 'Install risc0' | ||
description: 'Installs risc0 toolchain' | ||
|
||
inputs: | ||
github_token: | ||
description: 'GitHub token for authentication' | ||
required: true | ||
|
||
runs: | ||
using: "composite" | ||
steps: | ||
- name: Install cargo-risczero | ||
uses: taiki-e/install-action@v2 | ||
with: | ||
tool: [email protected] | ||
|
||
- name: Install risc0-zkvm toolchain | ||
shell: bash | ||
env: | ||
GITHUB_TOKEN: ${{ inputs.github_token }} | ||
run: cargo risczero install --version r0.1.81.0 |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,12 +1,12 @@ | ||
[package] | ||
name = "clementine-circuits" | ||
version = "0.0.0" | ||
name = "circuits-lib" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[dependencies] | ||
crypto-bigint = { workspace = true } | ||
k256 = { workspace = true, features = ["arithmetic", "serde", "expose-field", "ecdsa"] } | ||
sha2 = { workspace = true } | ||
serde = { workspace = true, features = ["derive"] } | ||
lazy_static = { workspace = true, features = ["spin_no_std"] } | ||
tracing = { workspace = true, default-features = false } | ||
risc0-zkvm = {version = "1.2.0", default-features = false, features = ["std"]} | ||
borsh = {version = "1.5.3", features = ["derive"] } |
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,2 @@ | ||
/// Constant bridge amount in sats | ||
pub const BRIDGE_AMOUNT_SATS: u64 = 1_000_000_000; |
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,23 @@ | ||
use sha2::{Digest, Sha256}; | ||
|
||
pub fn calculate_double_sha256(input: &[u8]) -> [u8; 32] { | ||
let mut hasher = Sha256::default(); | ||
hasher.update(input); | ||
let result = hasher.finalize_reset(); | ||
hasher.update(result); | ||
hasher.finalize().into() | ||
} | ||
|
||
pub fn calculate_sha256(input: &[u8]) -> [u8; 32] { | ||
let mut hasher = Sha256::default(); | ||
hasher.update(input); | ||
hasher.finalize().into() | ||
} | ||
|
||
/// Utility function to hash two nodes together | ||
pub fn hash_pair(left: [u8; 32], right: [u8; 32]) -> [u8; 32] { | ||
let mut hasher = Sha256::default(); | ||
hasher.update(left); | ||
hasher.update(right); | ||
hasher.finalize().into() | ||
} |
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,3 @@ | ||
pub mod constants; | ||
pub mod hashes; | ||
pub mod zkvm; |
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,60 @@ | ||
use std::io::Write; | ||
|
||
use borsh::BorshDeserialize; | ||
use risc0_zkvm::guest::env::{self}; | ||
|
||
pub trait ZkvmGuest { | ||
fn read_from_host<T: borsh::BorshDeserialize>(&self) -> T; | ||
fn commit<T: borsh::BorshSerialize>(&self, item: &T); | ||
fn verify<T: borsh::BorshSerialize>(&self, method_id: [u32; 8], journal: &T); | ||
} | ||
|
||
#[derive(Debug, Clone)] | ||
pub struct Proof { | ||
pub method_id: [u32; 8], | ||
pub journal: Vec<u8>, | ||
} | ||
|
||
pub trait ZkvmHost { | ||
// Adding data to the host | ||
fn write<T: borsh::BorshSerialize>(&self, value: &T); | ||
|
||
fn add_assumption(&self, proof: Proof); | ||
|
||
// Proves with the given data | ||
fn prove(&self, elf: &[u32]) -> Proof; | ||
} | ||
|
||
#[derive(Debug, Clone)] | ||
pub struct Risc0Guest; | ||
|
||
impl Risc0Guest { | ||
pub fn new() -> Self { | ||
Self {} | ||
} | ||
} | ||
|
||
impl Default for Risc0Guest { | ||
fn default() -> Self { | ||
Self::new() | ||
} | ||
} | ||
|
||
impl ZkvmGuest for Risc0Guest { | ||
fn read_from_host<T: borsh::BorshDeserialize>(&self) -> T { | ||
let mut reader = env::stdin(); | ||
BorshDeserialize::deserialize_reader(&mut reader) | ||
.expect("Failed to deserialize input from host") | ||
} | ||
|
||
fn commit<T: borsh::BorshSerialize>(&self, item: &T) { | ||
// use risc0_zkvm::guest::env::Write as _; | ||
let buf = borsh::to_vec(item).expect("Serialization to vec is infallible"); | ||
let mut journal = env::journal(); | ||
journal.write_all(&buf).unwrap(); | ||
} | ||
|
||
fn verify<T: borsh::BorshSerialize>(&self, method_id: [u32; 8], output: &T) { | ||
env::verify(method_id, &borsh::to_vec(output).unwrap()).unwrap(); | ||
} | ||
} |
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,26 @@ | ||
pub mod common; | ||
pub mod operator; | ||
pub mod watchtower; | ||
|
||
use common::zkvm::ZkvmGuest; | ||
// use operator::{OperatorCircuitInput, OperatorCircuitOutput}; | ||
// use watchtower::{WatchtowerCircuitInput, WatchtowerCircuitOutput}; | ||
pub use risc0_zkvm; | ||
|
||
pub fn operator_circuit(_guest: &impl ZkvmGuest) { | ||
// let start = risc0_zkvm::guest::env::cycle_count(); | ||
// let input: OperatorCircuitInput = guest.read_from_host(); | ||
// TODO: Implement operator circuit | ||
// guest.commit(&OperatorCircuitOutput {}); | ||
// let end = risc0_zkvm::guest::env::cycle_count(); | ||
// println!("Operator circuit took {:?} cycles", end - start); | ||
} | ||
|
||
pub fn watchtower_circuit(_guest: &impl ZkvmGuest) { | ||
// let start = risc0_zkvm::guest::env::cycle_count(); | ||
// let input: WatchtowerCircuitInput = guest.read_from_host(); | ||
// TODO: Implement watchtower circuit | ||
// guest.commit(&WatchtowerCircuitOutput {}); | ||
// let end = risc0_zkvm::guest::env::cycle_count(); | ||
// println!("Operator circuit took {:?} cycles", end - start); | ||
} |
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,8 @@ | ||
use borsh::{BorshDeserialize, BorshSerialize}; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
#[derive(Serialize, Deserialize, Eq, PartialEq, Clone, Debug, BorshDeserialize, BorshSerialize)] | ||
pub struct OperatorCircuitInput {} | ||
|
||
#[derive(Serialize, Deserialize, Eq, PartialEq, Clone, Debug, BorshDeserialize, BorshSerialize)] | ||
pub struct OperatorCircuitOutput {} |
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,8 @@ | ||
use borsh::{BorshDeserialize, BorshSerialize}; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
#[derive(Serialize, Deserialize, Eq, PartialEq, Clone, Debug, BorshDeserialize, BorshSerialize)] | ||
pub struct WatchtowerCircuitInput {} | ||
|
||
#[derive(Serialize, Deserialize, Eq, PartialEq, Clone, Debug, BorshDeserialize, BorshSerialize)] | ||
pub struct WatchtowerCircuitOutput {} |
Oops, something went wrong.