Skip to content
This repository has been archived by the owner on Jul 22, 2024. It is now read-only.

Sandboxed cairo native #1209

Draft
wants to merge 18 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 12 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
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,6 @@ lcov.info
.rusty-hook.toml
!/starknet_programs/raw_contract_classes/*.json
cairo-*.tar
starknet-pypy-env/
starknet-pypy-env/

executor_logs/
77 changes: 74 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 15 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ metrics = []
# Disclaimer: This feature enables state modifications being applied on reverted and failings txs, and also disables address availability check when deploying contracts.
# Only use for benchmarking using the replay binary
replay_benchmark = []
cairo-native = ["dep:ipc-channel", "dep:tracing-appender", "dep:cairo-native", "dep:uuid"]

[workspace]
members = [
Expand Down Expand Up @@ -40,8 +41,10 @@ cairo-lang-casm = { workspace = true }
cairo-lang-sierra = { workspace = true }
cairo-lang-starknet = { workspace = true }
cairo-lang-utils = { workspace = true }
cairo-native = { git = "https://github.com/lambdaclass/cairo_native", rev = "67a8c4e9853f588d4e8cb898f3fda37b7bdae5f1", optional = true }

cairo-native = { git = "https://github.com/lambdaclass/cairo_native", rev = "66d16af0db37ba6769d4576a49e12a40af14f565", features = ["with-serde"], optional = true }
ipc-channel = { version = "0.18.0", features = ["memfd"], optional = true }
tracing-appender = { version = "0.2.3", optional = true}
uuid = { version = "1.6.1", features = ["serde", "v4"], optional = true }

cairo-vm = { workspace = true }
flate2 = "1.0.25"
Expand All @@ -67,6 +70,7 @@ starknet_api = { workspace = true }
starknet-crypto = "0.6.1"
thiserror = { workspace = true }
tracing = "0.1.37"
tracing-subscriber = "0.3.17"

[dev-dependencies]
assert_matches = "1.5.0"
Expand All @@ -85,11 +89,20 @@ path = "src/bin/native_bench.rs"
name = "cairo_native"
required-features = ["cairo-native"]

[[bin]]
path = "src/bin/native_executor.rs"
name = "cairo_native_executor"
required-features = ["cairo-native"]

[[bench]]
path = "bench/yas.rs"
name = "yas"
harness = false

[[example]]
name = "sandbox"
required-features = ["cairo-native"]

[profile.release]
codegen-units = 1
lto = "fat"
10 changes: 10 additions & 0 deletions bench/internals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ pub fn deploy_account(
block_context,
#[cfg(feature = "cairo-native")]
Some(program_cache.clone()),
#[cfg(feature = "cairo-native")]
None,
)
})
.unwrap();
Expand Down Expand Up @@ -158,6 +160,8 @@ pub fn declare(
block_context,
#[cfg(feature = "cairo-native")]
Some(program_cache.clone()),
#[cfg(feature = "cairo-native")]
None,
)
})
.unwrap();
Expand Down Expand Up @@ -207,6 +211,8 @@ pub fn deploy(
block_context,
#[cfg(feature = "cairo-native")]
Some(program_cache.clone()),
#[cfg(feature = "cairo-native")]
None,
)
})
.unwrap();
Expand Down Expand Up @@ -254,6 +260,8 @@ pub fn invoke(
block_context,
#[cfg(feature = "cairo-native")]
Some(program_cache.clone()),
#[cfg(feature = "cairo-native")]
None,
)
.unwrap();

Expand Down Expand Up @@ -282,6 +290,8 @@ pub fn invoke(
2_000_000,
#[cfg(feature = "cairo-native")]
Some(program_cache.clone()),
#[cfg(feature = "cairo-native")]
None,
)
})
.unwrap();
Expand Down
26 changes: 26 additions & 0 deletions bench/yas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,8 @@ where
&BlockContext::default(),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

did you re-run the benchmarks? in that case please share the numbers

#[cfg(feature = "cairo-native")]
Some(program_cache),
#[cfg(feature = "cairo-native")]
None,
)?;

// Ensure the execution was successful.
Expand Down Expand Up @@ -426,6 +428,8 @@ where
&BlockContext::default(),
#[cfg(feature = "cairo-native")]
Some(program_cache),
#[cfg(feature = "cairo-native")]
None,
)?;

// Ensure the execution was successful.
Expand Down Expand Up @@ -467,6 +471,8 @@ where
&BlockContext::default(),
#[cfg(feature = "cairo-native")]
Some(program_cache),
#[cfg(feature = "cairo-native")]
None,
)?;

// Ensure the execution was successful.
Expand Down Expand Up @@ -508,6 +514,8 @@ where
&BlockContext::default(),
#[cfg(feature = "cairo-native")]
Some(program_cache),
#[cfg(feature = "cairo-native")]
None,
)?;

// Ensure the execution was successful.
Expand Down Expand Up @@ -560,6 +568,8 @@ where
u64::MAX.into(),
#[cfg(feature = "cairo-native")]
Some(program_cache),
#[cfg(feature = "cairo-native")]
None,
)?;

// Ensure the execution was successful.
Expand Down Expand Up @@ -607,6 +617,8 @@ where
u64::MAX.into(),
#[cfg(feature = "cairo-native")]
Some(program_cache),
#[cfg(feature = "cairo-native")]
None,
)?;

// Ensure the execution was successful.
Expand Down Expand Up @@ -646,6 +658,8 @@ where
u64::MAX.into(),
#[cfg(feature = "cairo-native")]
Some(program_cache),
#[cfg(feature = "cairo-native")]
None,
)?;

// Ensure the execution was successful.
Expand Down Expand Up @@ -701,6 +715,8 @@ where
u64::MAX.into(),
#[cfg(feature = "cairo-native")]
Some(program_cache),
#[cfg(feature = "cairo-native")]
None,
)?;

// Ensure the execution was successful.
Expand Down Expand Up @@ -752,6 +768,8 @@ where
u64::MAX.into(),
#[cfg(feature = "cairo-native")]
Some(program_cache),
#[cfg(feature = "cairo-native")]
None,
)?;

// Ensure the execution was successful.
Expand Down Expand Up @@ -801,6 +819,8 @@ where
u64::MAX.into(),
#[cfg(feature = "cairo-native")]
Some(program_cache),
#[cfg(feature = "cairo-native")]
None,
)?;

// Ensure the execution was successful.
Expand Down Expand Up @@ -859,6 +879,8 @@ where
u64::MAX.into(),
#[cfg(feature = "cairo-native")]
Some(program_cache),
#[cfg(feature = "cairo-native")]
None,
)?;

// Ensure the execution was successful.
Expand Down Expand Up @@ -919,6 +941,8 @@ where
u64::MAX.into(),
#[cfg(feature = "cairo-native")]
Some(program_cache),
#[cfg(feature = "cairo-native")]
None,
)?;

// Ensure the execution was successful.
Expand Down Expand Up @@ -967,6 +991,8 @@ where
u64::MAX.into(),
#[cfg(feature = "cairo-native")]
Some(program_cache),
#[cfg(feature = "cairo-native")]
None,
)?;

// Ensure the execution was successful.
Expand Down
Loading
Loading