Skip to content

Commit

Permalink
Merge pull request #24 from FuzzingLabs/dev/antonin
Browse files Browse the repository at this point in the history
Implement new detectors & Refactoring
  • Loading branch information
Rog3rSm1th authored Oct 10, 2024
2 parents 148c275 + 0f08b40 commit d0ea269
Show file tree
Hide file tree
Showing 15 changed files with 1,468 additions and 6,892 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ clap = { version = "4.0.0-rc.1", features = [ "derive" ] }
serde = "1.0.209"
serde_json = "1.0.116"
tokio = "1.37.0"
cairo-lang-sierra = "~2.7.1"
cairo-lang-starknet-classes = "~2.7.1"
cairo-lang-sierra = "~2.8.4"
cairo-lang-starknet-classes = "~2.8.4"
sierra-analyzer-lib = { path = "./lib" }

4 changes: 2 additions & 2 deletions bin/sierra-decompiler/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
cairo-lang-sierra = "~2.7.1"
cairo-lang-starknet-classes = "~2.7.1"
cairo-lang-sierra = "~2.8.4"
cairo-lang-starknet-classes = "~2.8.4"
clap = { version = "4.0.0-rc.1", features = [ "derive" ] }
serde_json = "1.0.116"
sierra-analyzer-lib = { path = "../../lib" }
Expand Down
36 changes: 31 additions & 5 deletions bin/sierra-decompiler/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,16 +158,42 @@ async fn load_remote_program(args: &Args) -> Result<SierraProgram, String> {
/// Load the Sierra program from a local file
fn load_local_program(args: &Args) -> Result<SierraProgram, String> {
let sierra_file = args.sierra_file.as_ref().unwrap();

// Open the file
let mut file = File::open(sierra_file).map_err(|e| format!("Failed to open file: {}", e))?;

// Read the file content into a string
let mut content = String::new();
file.read_to_string(&mut content)
.map_err(|e| format!("Failed to read file: {}", e))?;

let program_string = serde_json::from_str::<ContractClass>(&content)
.ok()
.and_then(|prog| prog.extract_sierra_program().ok())
.map_or_else(|| content.clone(), |prog_sierra| prog_sierra.to_string());
Ok(SierraProgram::new(program_string))
// Deserialize the JSON content into a ContractClass
let contract_class: Result<ContractClass, _> = serde_json::from_str(&content);

let program_string = match contract_class {
Ok(ref prog) => {
// Extract the Sierra program from the ContractClass
match prog.extract_sierra_program() {
Ok(prog_sierra) => prog_sierra.to_string(),
Err(e) => {
eprintln!("Error extracting Sierra program: {}", e);
content.clone()
}
}
}
Err(ref _e) => content.clone(),
};

// Initialize a new SierraProgram with the deserialized Sierra program content
let mut program = SierraProgram::new(program_string);

// Set the program ABI if deserialization was successful
if let Ok(ref contract_class) = contract_class {
let abi = contract_class.abi.clone();
program.set_abi(abi.unwrap());
}

Ok(program)
}

/// Get the file stem based on the remote address or the Sierra file
Expand Down
6,862 changes: 0 additions & 6,862 deletions examples/sierra/mintable.sierra

This file was deleted.

Loading

0 comments on commit d0ea269

Please sign in to comment.