-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
10 changed files
with
157 additions
and
14 deletions.
There are no files selected for viewing
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
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 |
---|---|---|
@@ -1,7 +1,58 @@ | ||
use std::{env, path::PathBuf}; | ||
|
||
use axum::Json; | ||
use dry_hint_processor::syscall_handler::SyscallHandler; | ||
use types::HDPDryRunInput; | ||
use cairo_vm::{ | ||
cairo_run::{self, cairo_run_program}, | ||
types::{layout::CairoLayoutParams, layout_name::LayoutName, program::Program}, | ||
}; | ||
use dry_hint_processor::{ | ||
CustomHintProcessor, | ||
syscall_handler::{SyscallHandler, SyscallHandlerWrapper}, | ||
}; | ||
use hints::vars; | ||
use serde::Deserialize; | ||
use types::{HDPDryRunInput, error::Error}; | ||
|
||
use crate::error::AppError; | ||
|
||
#[derive(Debug, Deserialize)] | ||
pub struct DryRunRequest { | ||
params: Option<CairoLayoutParams>, | ||
layout: LayoutName, | ||
input: HDPDryRunInput, | ||
} | ||
|
||
pub async fn root(Json(value): Json<DryRunRequest>) -> Result<Json<SyscallHandler>, AppError> { | ||
// Init CairoRunConfig | ||
let cairo_run_config = cairo_run::CairoRunConfig { | ||
trace_enabled: false, | ||
relocate_mem: false, | ||
layout: value.layout, | ||
proof_mode: false, | ||
secure_run: Some(true), | ||
allow_missing_builtins: Some(true), | ||
dynamic_layout_params: value.params, | ||
..Default::default() | ||
}; | ||
|
||
// Locate the compiled program file in the `OUT_DIR` folder. | ||
let out_dir = PathBuf::from(env::var("OUT_DIR").expect("OUT_DIR is not set")); | ||
let program_file_path = out_dir.join("cairo").join("compiled.json"); | ||
|
||
let program_file = std::fs::read(program_file_path).map_err(Error::IO)?; | ||
|
||
// Load the Program | ||
let program = Program::from_bytes(&program_file, Some(cairo_run_config.entrypoint))?; | ||
|
||
let mut hint_processor = CustomHintProcessor::new(value.input); | ||
let cairo_runner = cairo_run_program(&program, &cairo_run_config, &mut hint_processor).unwrap(); | ||
|
||
pub async fn root(Json(value): Json<HDPDryRunInput>) -> Json<SyscallHandler> { | ||
todo!() | ||
Ok(Json( | ||
cairo_runner | ||
.exec_scopes | ||
.get::<SyscallHandlerWrapper>(vars::scopes::SYSCALL_HANDLER)? | ||
.syscall_handler | ||
.try_read()? | ||
.clone(), | ||
)) | ||
} |
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,25 @@ | ||
use axum::{ | ||
http::StatusCode, | ||
response::{IntoResponse, Response}, | ||
}; | ||
|
||
// Make our own error that wraps `anyhow::Error`. | ||
pub struct AppError(anyhow::Error); | ||
|
||
// Tell axum how to convert `AppError` into a response. | ||
impl IntoResponse for AppError { | ||
fn into_response(self) -> Response { | ||
(StatusCode::INTERNAL_SERVER_ERROR, format!("Something went wrong: {}", self.0)).into_response() | ||
} | ||
} | ||
|
||
// This enables using `?` on functions that return `Result<_, anyhow::Error>` to turn them into | ||
// `Result<_, AppError>`. That way you don't need to do that manually. | ||
impl<E> From<E> for AppError | ||
where | ||
E: Into<anyhow::Error>, | ||
{ | ||
fn from(err: E) -> Self { | ||
Self(err.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 |
---|---|---|
@@ -1,7 +1,19 @@ | ||
use axum::Json; | ||
use dry_hint_processor::syscall_handler::SyscallHandler; | ||
use fetcher::{Fetcher, parse_syscall_handler}; | ||
use types::ChainProofs; | ||
|
||
pub async fn root(Json(value): Json<SyscallHandler>) -> Json<Vec<ChainProofs>> { | ||
todo!() | ||
use crate::error::AppError; | ||
|
||
pub async fn root(Json(value): Json<SyscallHandler>) -> Result<Json<Vec<ChainProofs>>, AppError> { | ||
let proof_keys = parse_syscall_handler(value)?; | ||
|
||
let fetcher = Fetcher::new(&proof_keys); | ||
let (evm_proofs, starknet_proofs) = tokio::try_join!(fetcher.collect_evm_proofs(), fetcher.collect_starknet_proofs())?; | ||
let chain_proofs = vec![ | ||
ChainProofs::EthereumSepolia(evm_proofs), | ||
ChainProofs::StarknetSepolia(starknet_proofs), | ||
]; | ||
|
||
Ok(Json(chain_proofs)) | ||
} |
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,7 +1,48 @@ | ||
use std::{env, path::PathBuf}; | ||
|
||
use axum::Json; | ||
use cairo_vm::vm::runners::cairo_pie::CairoPie; | ||
use types::HDPInput; | ||
use cairo_vm::{ | ||
cairo_run::{self, cairo_run_program}, | ||
types::{layout::CairoLayoutParams, layout_name::LayoutName, program::Program}, | ||
vm::runners::cairo_pie::CairoPie, | ||
}; | ||
use serde::Deserialize; | ||
use sound_hint_processor::CustomHintProcessor; | ||
use types::{HDPInput, error::Error}; | ||
|
||
use crate::error::AppError; | ||
|
||
#[derive(Debug, Deserialize)] | ||
pub struct SoundRunRequest { | ||
params: Option<CairoLayoutParams>, | ||
layout: LayoutName, | ||
input: HDPInput, | ||
} | ||
|
||
pub async fn root(Json(value): Json<SoundRunRequest>) -> Result<Json<CairoPie>, AppError> { | ||
// Init CairoRunConfig | ||
let cairo_run_config = cairo_run::CairoRunConfig { | ||
trace_enabled: false, | ||
relocate_mem: false, | ||
layout: value.layout, | ||
proof_mode: false, | ||
secure_run: Some(true), | ||
allow_missing_builtins: Some(true), | ||
dynamic_layout_params: value.params, | ||
..Default::default() | ||
}; | ||
|
||
// Locate the compiled program file in the `OUT_DIR` folder. | ||
let out_dir = PathBuf::from(env::var("OUT_DIR").expect("OUT_DIR is not set")); | ||
let program_file_path = out_dir.join("cairo").join("compiled.json"); | ||
|
||
let program_file = std::fs::read(program_file_path).map_err(Error::IO)?; | ||
|
||
// Load the Program | ||
let program = Program::from_bytes(&program_file, Some(cairo_run_config.entrypoint))?; | ||
|
||
let mut hint_processor = CustomHintProcessor::new(value.input); | ||
let cairo_runner = cairo_run_program(&program, &cairo_run_config, &mut hint_processor).unwrap(); | ||
|
||
pub async fn root(Json(value): Json<HDPInput>) -> Json<CairoPie> { | ||
todo!() | ||
Ok(Json(cairo_runner.get_cairo_pie()?)) | ||
} |