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

Feature: Implement Secp Syscalls #279

Closed
wants to merge 9 commits into from
Closed
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
509 changes: 271 additions & 238 deletions Cargo.lock

Large diffs are not rendered by default.

8 changes: 6 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,19 @@ version = "0.1.0"

[dependencies]
anyhow = "1.0.75"
ark-ec = "0.4.2"
ark-ff = "0.4.2"
ark-secp256k1 = "0.4"
ark-secp256r1 = "0.4"
assert_matches = "1.5.0"
base64 = "0.21.3"
bitvec = { version = "1.0.1", features = ["serde"] }
blockifier = { git = "https://github.com/Moonsong-Labs/blockifier", branch = "msl/derive-clone", features = ["testing"] }
blockifier = { git = "https://github.com/Moonsong-Labs/blockifier", branch = "herman/msl/derive-clone-fix-pub-secp", features = ["testing"] }
cairo-lang-starknet = { version = "2.6.3" }
cairo-lang-starknet-classes = { version = "2.6.3" }
cairo-lang-casm = { version = "2.6.3" }
cairo-type-derive = { version = "0.1.0", path = "cairo-type-derive" }
cairo-vm = { git = "https://github.com/lambdaclass/cairo-vm", features = ["extensive_hints", "cairo-1-hints"] }
cairo-vm = { git = "https://github.com/lambdaclass/cairo-vm", features = ["extensive_hints", "cairo-1-hints"], tag = "v1.0.0-rc5" }
env_logger = "0.11.3"
futures = "0.3.30"
futures-util = "0.3.30"
Expand Down
2 changes: 1 addition & 1 deletion bin/hint_tool/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ version = "0.1.0"

[dependencies]
blockifier = { git = "https://github.com/Moonsong-Labs/blockifier", branch = "msl/derive-clone", features = ["testing"] }
cairo-vm = { git = "https://github.com/lambdaclass/cairo-vm", features = ["extensive_hints", "cairo-1-hints"] }
cairo-vm = { git = "https://github.com/lambdaclass/cairo-vm", features = ["extensive_hints", "cairo-1-hints"], tag = "v1.0.0-rc5" }
clap = { version = "4.5.4", features = ["derive"] }
serde = { version = "1.0.188", features = ["derive"] }
serde_json = { version = "1.0.105", features = ["arbitrary_precision"] }
Expand Down
12 changes: 6 additions & 6 deletions scripts/setup-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ echo -e "compiling starknet contracts...\n"
mkdir -p build/contracts
mkdir -p build/pie
ln -sf cairo-lang/src/starkware starkware
starknet-compile-deprecated tests/integration/contracts/token_for_testing.cairo --output build/contracts/token_for_testing.json --cairo_path cairo-lang/src --account_contract
starknet-compile-deprecated tests/integration/contracts/dummy_account.cairo --output build/contracts/dummy_account.json --cairo_path cairo-lang/src --account_contract
starknet-compile-deprecated tests/integration/contracts/dummy_token.cairo --output build/contracts/dummy_token.json --cairo_path cairo-lang/src --account_contract
starknet-compile-deprecated tests/integration/contracts/delegate_proxy.cairo --output build/contracts/delegate_proxy.json --cairo_path cairo-lang/src
starknet-compile-deprecated tests/integration/contracts/test_contract.cairo --output build/contracts/test_contract.json --cairo_path cairo-lang/src
starknet-compile-deprecated tests/integration/contracts/test_contract2.cairo --output build/contracts/test_contract2.json --cairo_path cairo-lang/src
starknet-compile-deprecated tests/integration/contracts/os_itest_contracts/token_for_testing.cairo --output build/contracts/token_for_testing.json --cairo_path cairo-lang/src --account_contract
starknet-compile-deprecated tests/integration/contracts/os_itest_contracts/dummy_account.cairo --output build/contracts/dummy_account.json --cairo_path cairo-lang/src --account_contract
starknet-compile-deprecated tests/integration/contracts/os_itest_contracts/dummy_token.cairo --output build/contracts/dummy_token.json --cairo_path cairo-lang/src --account_contract
starknet-compile-deprecated tests/integration/contracts/os_itest_contracts/delegate_proxy.cairo --output build/contracts/delegate_proxy.json --cairo_path cairo-lang/src
starknet-compile-deprecated tests/integration/contracts/os_itest_contracts/test_contract.cairo --output build/contracts/test_contract.json --cairo_path cairo-lang/src
starknet-compile-deprecated tests/integration/contracts/os_itest_contracts/test_contract2.cairo --output build/contracts/test_contract2.json --cairo_path cairo-lang/src
14 changes: 0 additions & 14 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,3 @@ pub enum SnOsError {
#[error("SnOs Deprecated Syscall Error: {0}")]
InvalidDeprecatedSyscallSelector(Felt252),
}

#[derive(thiserror::Error, Clone, Debug)]
pub enum CommitmentInfoError {
#[error("Inconsistent tree heights : {0} {1}.")]
InconsistentTreeHeights(usize, usize),
#[error("Inconsistent tree roots, actual : {0} , expected : {1}.")]
InconsistentTreeRoots(Felt252, Felt252),
}

#[derive(thiserror::Error, Clone, Debug)]
pub enum FactTreeError {
#[error("Unexpected result on single leaf index : {0}")]
UnexpectedResult(Felt252),
}
34 changes: 31 additions & 3 deletions src/execution/helper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use std::vec::IntoIter;
use blockifier::context::BlockContext;
use blockifier::execution::call_info::CallInfo;
use blockifier::execution::entry_point_execution::CallResult;
use blockifier::execution::syscalls::secp::SecpHintProcessor as SecpSyscallProcessor;
use blockifier::transaction::objects::TransactionExecutionInfo;
use cairo_vm::types::relocatable::Relocatable;
use cairo_vm::vm::errors::hint_errors::HintError;
Expand All @@ -23,7 +24,6 @@ use crate::storage::storage::StorageError;
pub type ContractStorageMap<S, H> = HashMap<Felt252, OsSingleStarknetStorage<S, H>>;

/// Maintains the info for executing txns in the OS
#[derive(Debug)]
pub struct ExecutionHelper {
pub _prev_block_context: Option<BlockContext>,
// Pointer tx execution info
Expand Down Expand Up @@ -52,6 +52,31 @@ pub struct ExecutionHelper {
pub execute_code_read_iter: IntoIter<Felt252>,
// Per-contract storage
pub storage_by_address: ContractStorageMap<DictStorage, PedersenHash>,

// Secp syscall processors.
pub secp256k1_syscall_processor: SecpSyscallProcessor<ark_secp256k1::Config>,
pub secp256r1_syscall_processor: SecpSyscallProcessor<ark_secp256r1::Config>,
}

impl std::fmt::Debug for ExecutionHelper {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("ExecutionHelper")
.field("_prev_block_context", &self._prev_block_context)
.field("tx_execution_info_iter", &self.tx_execution_info_iter)
.field("tx_execution_info", &self.tx_execution_info)
.field("tx_info_ptr", &self.tx_info_ptr)
.field("call_execution_info_ptr", &self.call_execution_info_ptr)
.field("old_block_number_and_hash", &self.old_block_number_and_hash)
.field("call_iter", &self.call_iter)
.field("call_info", &self.call_info)
.field("result_iter", &self.result_iter)
.field("deployed_contracts_iter", &self.deployed_contracts_iter)
.field("execute_code_read_iter", &self.execute_code_read_iter)
.field("storage_by_address", &self.storage_by_address)
.field("secp256k1_syscall_processor", &"SecpHintProcessor<ark_secp256k1::Config>")
.field("secp256r1_syscall_processor", &"SecpHintProcessor<ark_secp256r1::Config>")
.finish()
}
}

/// ExecutionHelper is wrapped in Rc<RefCell<_>> in order
Expand Down Expand Up @@ -91,6 +116,8 @@ impl ExecutionHelperWrapper {
deployed_contracts_iter: vec![].into_iter(),
execute_code_read_iter: vec![].into_iter(),
storage_by_address: contract_storage_map,
secp256k1_syscall_processor: SecpSyscallProcessor::<ark_secp256k1::Config>::default(),
secp256r1_syscall_processor: SecpSyscallProcessor::<ark_secp256r1::Config>::default(),
})),
}
}
Expand Down Expand Up @@ -212,6 +239,7 @@ impl ExecutionHelperWrapper {

let mut commitments = HashMap::new();
for (key, storage) in storage_by_address.iter_mut() {
log::debug!("key: {} ({})", key.to_hex_string(), key.to_string());
let commitment_info = storage.compute_commitment().await?;
commitments.insert(*key, commitment_info);
}
Expand All @@ -226,8 +254,8 @@ fn assert_iterators_exhausted(eh_ref: &ExecutionHelper) {
assert!(eh_ref.execute_code_read_iter.clone().peekable().peek().is_none());
}

/// Required for recursive interation on 'inner_calls'
trait GenCallIter {
/// Required for recursive iteration on 'inner_calls'
pub trait GenCallIter {
fn gen_call_iterator(&self) -> IntoIter<CallInfo>;
}

Expand Down
1 change: 1 addition & 0 deletions src/execution/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ mod constants;
pub mod deprecated_syscall_handler;
pub mod execute_syscalls;
pub mod helper;
pub mod secp_handler;
pub mod syscall_handler;
pub mod syscall_handler_utils;
Loading