Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: use stateless execution in the rpc api #615

Merged
merged 8 commits into from
Apr 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
176 changes: 119 additions & 57 deletions Cargo.lock

Large diffs are not rendered by default.

11 changes: 8 additions & 3 deletions crates/experimental-api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
description = "JSON-RPC server & client auto-generated from the OpenRPC specification"
edition = "2021"
name = "beerus-experimental-api"
version = "0.3.0"
version = "0.1.0"

[dependencies]
serde = { version = "1.0", features = ["derive"] }
Expand All @@ -18,10 +18,15 @@ tracing.workspace = true
thiserror.workspace = true

starknet-crypto = "0.6.1"
blockifier = { git = "https://github.com/starkware-libs/blockifier", tag = "v0.5.0-rc.2" }
starknet_api = "0.8.0"
blockifier = { git = "https://github.com/starkware-libs/blockifier", tag = "v0.5.0" }
sergey-melnychuk marked this conversation as resolved.
Show resolved Hide resolved
starknet_api = "0.10.0"
cairo-vm = "0.9.2"
hex = "0.4.3"

base64 = "0.22.0"
flate2 = "1.0.28"
cairo-lang-starknet-classes = "2.6.3"
ureq = { version = "2.9.6", features = ["json"] }
sergey-melnychuk marked this conversation as resolved.
Show resolved Hide resolved

[dev-dependencies]
tracing-subscriber.workspace = true
2 changes: 1 addition & 1 deletion crates/experimental-api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ USAGE:
cd /path/to/beerus

cd ..
git clone https://github.com/sergey-melnychuk/iamgroot.git --branch v0.2.6
git clone https://github.com/sergey-melnychuk/iamgroot.git --branch v0.2.7
cd iamgroot && cargo build --release
cp ./target/release/iamgroot ../beerus/tmp
cd ../beerus
Expand Down
12 changes: 12 additions & 0 deletions crates/experimental-api/src/exe/err.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use cairo_lang_starknet_classes::casm_contract_class::StarknetSierraCompilationError;
use thiserror::Error as ThisError;

#[derive(Debug, ThisError)]
Expand All @@ -24,6 +25,8 @@ pub enum Error {
),
#[error("Program error: {0:?}")]
Program(#[from] cairo_vm::types::errors::program_errors::ProgramError),
#[error("Sierra compilation error: {0:?}")]
sergey-melnychuk marked this conversation as resolved.
Show resolved Hide resolved
SierraCompilation(#[from] StarknetSierraCompilationError),
#[error("{0}")]
Custom(&'static str),
}
Expand All @@ -41,3 +44,12 @@ impl From<Error> for blockifier::state::errors::StateError {
))
}
}

impl From<Error> for iamgroot::jsonrpc::Error {
fn from(error: Error) -> Self {
match error {
Error::IamGroot(e) => e,
e => iamgroot::jsonrpc::Error { code: 500, message: e.to_string() },
}
}
}
23 changes: 19 additions & 4 deletions crates/experimental-api/src/exe/map.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use blockifier::execution::contract_class::{ContractClassV0, ContractClassV1};
use blockifier::execution::contract_class::ContractClassV0;
use cairo_lang_starknet_classes::casm_contract_class::CasmContractClass;
use cairo_lang_starknet_classes::contract_class::ContractClass as CairoContractClass;

use self::gen::DeprecatedContractClass;

Expand Down Expand Up @@ -40,10 +42,23 @@ impl TryFrom<gen::GetClassResult> for ContractClass {
type Error = Error;

fn try_from(value: gen::GetClassResult) -> Result<Self, Self::Error> {
let json = serde_json::to_string(&value)?;
Ok(match value {
gen::GetClassResult::ContractClass(_) => {
let class = ContractClassV1::try_from_json_string(&json)?;
gen::GetClassResult::ContractClass(ref class) => {
let mut json = serde_json::to_value(&value)?;
if let Some(abi) = class.abi.as_ref() {
let abi: serde_json::Value = serde_json::from_str(abi)?;
json["abi"] = abi;
}
let contract_class: CairoContractClass =
serde_json::from_value(json)?;
let casm_contract_class =
CasmContractClass::from_contract_class(
contract_class,
/*add_pythonic_hints=*/ false,
/*max_bytecode_size=*/ u16::MAX as usize,
)?;
let class = casm_contract_class.try_into()?;

ContractClass::V1(class)
}
gen::GetClassResult::DeprecatedContractClass(class) => {
Expand Down
7 changes: 4 additions & 3 deletions crates/experimental-api/src/exe/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ pub mod map;

use err::Error;

pub fn exec(
pub fn call(
client: &gen::client::blocking::Client,
call: gen::FunctionCall,
function_call: gen::FunctionCall,
) -> Result<CallInfo, Error> {
let gen::FunctionCall { calldata, contract_address, entry_point_selector } =
call;
function_call;

let calldata: Result<Vec<StarkFelt>, _> =
calldata.into_iter().map(|felt| felt.try_into()).collect();
Expand Down Expand Up @@ -135,6 +135,7 @@ pub fn exec(
let call_info =
call_entry_point.execute(&mut proxy, &mut resources, &mut context)?;

tracing::debug!(?call_info, "call completed");
Ok(call_info)
}

Expand Down
Loading
Loading