Skip to content

Commit

Permalink
update stwo examples + add internal stwo wasm in WIP for fibo and mul…
Browse files Browse the repository at this point in the history
…ti fibo
  • Loading branch information
MSghais committed Aug 6, 2024
1 parent eee244c commit b7fc1c0
Show file tree
Hide file tree
Showing 13 changed files with 1,092 additions and 263 deletions.
6 changes: 4 additions & 2 deletions askeladd-dvm-marketplace/src/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,10 @@ export default function Home() {
claim: claim.toString()
},
program:{
contract_name:"FibonnacciProvingRequest",
internal_contract_name:"FibonnacciProvingRequest",
contract_name:"PoseidonProvingRequest",
internal_contract_name:"PoseidonrovingRequest",
// contract_name:"FibonnacciProvingRequest",
// internal_contract_name:"FibonnacciProvingRequest",
contract_reached:"InternalAskeladd",
// inputs:JSON.stringify(Object.fromEntries(inputs)),
inputs:Object.fromEntries(inputs),
Expand Down
60 changes: 31 additions & 29 deletions askeladd-dvm-marketplace/src/constants/program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,7 @@ program_map_multi_fibo.set("1","claims");

export const PROGRAM_INTERAL_REQUEST:IGenerateZKPRequestDVM[] = [

{
// Fibonnaci
request: {
log_size:0,
claim:0
},
program: {
contract_name:ProgramInternalContractName.FibonnacciProvingRequest.toString(),
internal_contract_name:ProgramInternalContractName.FibonnacciProvingRequest,
contract_reached:ContractUploadType.InternalAskeladd,
inputs:program_map_fibo
}

},


{
// Wide Fibonnaci
request: {
Expand Down Expand Up @@ -72,19 +58,35 @@ export const PROGRAM_INTERAL_REQUEST:IGenerateZKPRequestDVM[] = [

},

{
// Multi Fibonnaci
request: {
log_sizes:0,
claims:0
},
program: {
contract_name:ProgramInternalContractName.MultiFibonnacciProvingRequest.toString(),
internal_contract_name:ProgramInternalContractName.MultiFibonnacciProvingRequest,
contract_reached:ContractUploadType.InternalAskeladd,
inputs:program_map_multi_fibo
}

},
// {
// // Fibonnaci
// request: {
// log_size:0,
// claim:0
// },
// program: {
// contract_name:ProgramInternalContractName.FibonnacciProvingRequest.toString(),
// internal_contract_name:ProgramInternalContractName.FibonnacciProvingRequest,
// contract_reached:ContractUploadType.InternalAskeladd,
// inputs:program_map_fibo
// }

// },


// {
// // Multi Fibonnaci
// request: {
// log_sizes:0,
// claims:0
// },
// program: {
// contract_name:ProgramInternalContractName.MultiFibonnacciProvingRequest.toString(),
// internal_contract_name:ProgramInternalContractName.MultiFibonnacciProvingRequest,
// contract_reached:ContractUploadType.InternalAskeladd,
// inputs:program_map_multi_fibo
// }

// },

]
16 changes: 8 additions & 8 deletions crates/cli/src/dvm_customer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,14 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
};
println!("{}", "Job prepared successfully.".green());

// /// Add poseidon
let settings = Settings::new().expect("Failed to load settings");

poseidon_program(customer).await?;

let mut customer = Customer::new(settings)?;
customer.init().await?;

// ******************************************************
// ****************** SUBMIT JOB ************************
// ******************************************************
Expand Down Expand Up @@ -122,14 +130,6 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
println!("{}", "└─────────────────────────────────────┘".red());
}

// /// Add poseidon
// let settings = Settings::new().expect("Failed to load settings");

// let mut customer = Customer::new(settings)?;
// customer.init().await?;

// poseidon_program(customer).await?;

Ok(())
}

Expand Down
82 changes: 50 additions & 32 deletions crates/core/src/prover_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,26 @@ use std::fmt;
use serde_json::Result as SerdeResult;
use stwo_prover::core::backend::simd::fft::MIN_FFT_LOG_SIZE;
use stwo_prover::core::circle::M31_CIRCLE_LOG_ORDER;
use stwo_prover::core::fields::m31::{self, BaseField};
use stwo_prover::core::fields::m31::BaseField;
use stwo_prover::core::prover::ProvingError;
use stwo_prover::core::vcs::blake2_merkle::Blake2sMerkleHasher;
use stwo_prover::examples::fibonacci::{Fibonacci, MultiFibonacci};
use stwo_wasm::fibonnaci::Fibonacci;
use stwo_wasm::poseidon::{PoseidonStruct, LOG_N_LANES, N_LOG_INSTANCES_PER_ROW};
use stwo_wasm::wide_fibonnacci::WideFibStruct;
use thiserror::Error;

use crate::dvm::types::{
ContractUploadType, FibonnacciProvingRequest, FibonnacciProvingResponse,
GenericProvingResponse, MultiFibonnacciProvingRequest, PoseidonProvingRequest,
ProgramInternalContractName, ProgramParams, WideFibonnacciProvingRequest,
ContractUploadType,
FibonnacciProvingRequest,
FibonnacciProvingResponse,
GenericProvingResponse,
PoseidonProvingRequest,
ProgramInternalContractName,
ProgramParams,
WideFibonnacciProvingRequest,
// MultiFibonnacciProvingRequest
};
// use stwo_wasm::fibonnaci::multi_fibonacci::MultiFibonacci;
use crate::utils::convert_inputs_to_run_program;

#[derive(Error, Debug, Clone)]
Expand Down Expand Up @@ -110,35 +117,46 @@ impl ProverService {
Some(internal_contract) => match internal_contract {
ProgramInternalContractName::FibonnacciProvingRequest => {
println!("try check request fib");
let fib_req_res: SerdeResult<FibonnacciProvingRequest> =
serde_json::from_str(serialized_request);
let fib_req = match fib_req_res.as_ref() {
Ok(req) => req.clone(),
Err(e) => return Err(e.to_string()),
};
let fib = Fibonacci::new(fib_req.log_size, BaseField::from(fib_req.claim));
match fib.prove() {
Ok(proof) => Ok(GenericProvingResponse::new(request.clone(), proof)),
Err(e) => Err(e.to_string()),
}
// let fib_req_res: SerdeResult<FibonnacciProvingRequest> =
// serde_json::from_str(serialized_request);
// let fib_req = match fib_req_res.as_ref() {
// Ok(req) => req.clone(),
// Err(e) => return Err(e.to_string()),
// };
// println!("init fib program");

// let fib = Fibonacci::new(fib_req.log_size, BaseField::from(fib_req.claim));
// println!("try prove");

println!("WIP FIX Fibonnacci WASM");

Err(ProvingError::ConstraintsNotSatisfied.to_string())

// match fib.prove() {
// Ok(proof) => Ok(GenericProvingResponse::new(request.clone(), proof)),
// Err(e) => Err(e.to_string()),
// }
}
ProgramInternalContractName::MultiFibonnaciProvingRequest => {
let multi_fibo_res: SerdeResult<MultiFibonnacciProvingRequest> =
serde_json::from_str(serialized_request);
let mul_fib_req = match multi_fibo_res.as_ref() {
Ok(req) => req.clone(),
Err(e) => return Err(e.to_string()),
};
let claims: Vec<BaseField> = mul_fib_req
.claims
.into_iter()
.map(m31::M31::from_u32_unchecked)
.collect();
let multi_fibo = MultiFibonacci::new(mul_fib_req.log_sizes, claims);
match multi_fibo.prove() {
Ok(proof) => Ok(GenericProvingResponse::new(request.clone(), proof)),
Err(e) => Err(e.to_string()),
}
println!("WIP FIX Multi Fibonnacci WASM");

Err(ProvingError::ConstraintsNotSatisfied.to_string())
// let multi_fibo_res: SerdeResult<MultiFibonnacciProvingRequest> =
// serde_json::from_str(serialized_request);
// let mul_fib_req = match multi_fibo_res.as_ref() {
// Ok(req) => req.clone(),
// Err(e) => return Err(e.to_string()),
// };
// let claims: Vec<BaseField> = mul_fib_req
// .claims
// .into_iter()
// .map(m31::M31::from_u32_unchecked)
// .collect();
// let multi_fibo = MultiFibonacci::new(mul_fib_req.log_sizes, claims);
// match multi_fibo.prove() {
// Ok(proof) => Ok(GenericProvingResponse::new(request.clone(), proof)),
// Err(e) => Err(e.to_string()),
// }
}
ProgramInternalContractName::Custom(_) => {
println!("Custom internal contract");
Expand Down
2 changes: 1 addition & 1 deletion crates/core/src/verifier_service.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use serde::{Deserialize, Serialize};
use stwo_prover::core::fields::m31::BaseField;
use stwo_prover::core::prover::VerificationError;
use stwo_prover::examples::fibonacci::Fibonacci;
use stwo_wasm::fibonnaci::Fibonacci;

use crate::dvm::types::{FibonnacciProvingResponse, GenericProvingResponse};
// Define an enum to encapsulate possible deserialized types
Expand Down
2 changes: 2 additions & 0 deletions crates/stwo_wasm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ wasm-bindgen = "0.2.84"
serde = "1.0.204"
serde_json = "1.0.121"
getrandom = { version = "0.2", features = ["js"] }
num-traits = "0.2.17"
itertools = "0.12.0"

[dev-dependencies]
wasm-bindgen-test = "0.3.34"
Expand Down
Loading

0 comments on commit b7fc1c0

Please sign in to comment.