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 the command line compiler in gateway #599

Merged
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
3 changes: 3 additions & 0 deletions crates/gateway/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Sets up the environment variable OUT_DIR, which holds the cairo compiler binary.
// The binary is dowloaded to OUT_DIR by the starknet_sierra_compile crate.
fn main() {}
6 changes: 6 additions & 0 deletions crates/gateway/src/compilation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use starknet_api::contract_class::ClassInfo;
use starknet_api::core::CompiledClassHash;
use starknet_api::rpc_transaction::RpcDeclareTransaction;
use starknet_sierra_compile::cairo_lang_compiler::CairoLangSierraToCasmCompiler;
use starknet_sierra_compile::command_line_compiler::CommandLineCompiler;
use starknet_sierra_compile::config::SierraToCasmCompilationConfig;
use starknet_sierra_compile::utils::into_contract_class_for_compilation;
use starknet_sierra_compile::SierraToCasmCompiler;
Expand All @@ -24,6 +25,11 @@ pub struct GatewayCompiler {
}

impl GatewayCompiler {
pub fn new_command_line_compiler(config: SierraToCasmCompilationConfig) -> Self {
Self { sierra_to_casm_compiler: Arc::new(CommandLineCompiler::new(config)) }
}

// TODO(Arni): Cosider deleting `CairoLangSierraToCasmCompiler`.
pub fn new_cairo_lang_compiler(config: SierraToCasmCompilationConfig) -> Self {
Self { sierra_to_casm_compiler: Arc::new(CairoLangSierraToCasmCompiler { config }) }
}
Expand Down
11 changes: 6 additions & 5 deletions crates/gateway/src/compilation_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use crate::errors::GatewaySpecError;

#[fixture]
fn gateway_compiler() -> GatewayCompiler {
GatewayCompiler::new_cairo_lang_compiler(SierraToCasmCompilationConfig::default())
GatewayCompiler::new_command_line_compiler(SierraToCasmCompilationConfig::default())
}

#[fixture]
Expand Down Expand Up @@ -58,14 +58,15 @@ fn test_compile_contract_class_compiled_class_hash_mismatch(
#[rstest]
fn test_compile_contract_class_bytecode_size_validation(declare_tx_v3: RpcDeclareTransactionV3) {
let gateway_compiler =
GatewayCompiler::new_cairo_lang_compiler(SierraToCasmCompilationConfig {
GatewayCompiler::new_command_line_compiler(SierraToCasmCompilationConfig {
max_bytecode_size: 1,
});

let result = gateway_compiler.process_declare_tx(&RpcDeclareTransaction::V3(declare_tx_v3));
assert_matches!(result.unwrap_err(), GatewaySpecError::CompilationFailed);
let expected_compilation_error =
CompilationUtilError::CompilationError("Code size limit exceeded.".to_owned());
let expected_compilation_error = CompilationUtilError::CompilationError(
"Error: Compilation failed.\n\nCaused by:\n Code size limit exceeded.\n".to_owned(),
);
assert!(logs_contain(format!("Compilation failed: {:?}", expected_compilation_error).as_str()));
}

Expand All @@ -84,7 +85,7 @@ fn test_compile_contract_class_bad_sierra(
assert_eq!(err, GatewaySpecError::CompilationFailed);

let expected_compilation_error =
CompilationUtilError::CompilationError("Invalid Sierra program.".to_owned());
CompilationUtilError::CompilationError("Error: Invalid Sierra program.\n".to_owned());
assert!(logs_contain(format!("Compilation failed: {:?}", expected_compilation_error).as_str()));
}

Expand Down
2 changes: 1 addition & 1 deletion crates/gateway/src/gateway.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ pub fn create_gateway(
mempool_client: SharedMempoolClient,
) -> Gateway {
let state_reader_factory = Arc::new(RpcStateReaderFactory { config: rpc_state_reader_config });
let gateway_compiler = GatewayCompiler::new_cairo_lang_compiler(compiler_config);
let gateway_compiler = GatewayCompiler::new_command_line_compiler(compiler_config);

Gateway::new(config, state_reader_factory, gateway_compiler, mempool_client)
}
Expand Down
2 changes: 1 addition & 1 deletion crates/gateway/src/gateway_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ pub fn app_state(
stateful_tx_validator: Arc::new(StatefulTransactionValidator {
config: StatefulTransactionValidatorConfig::create_for_testing(),
}),
gateway_compiler: GatewayCompiler::new_cairo_lang_compiler(
gateway_compiler: GatewayCompiler::new_command_line_compiler(
SierraToCasmCompilationConfig::default(),
),
state_reader_factory: Arc::new(state_reader_factory),
Expand Down
3 changes: 3 additions & 0 deletions crates/tests-integration/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Sets up the environment variable OUT_DIR, which holds the cairo compiler binary.
// The binary is dowloaded to OUT_DIR by the starknet_sierra_compile crate.
fn main() {}
Loading