Skip to content

Commit a302f04

Browse files
Mohammad Fawazclaude
authored andcommitted
fix(abi): handle imports in leo abi (#29437)
`leo abi` on a `.aleo` file that declares imports now loads each dependency from a sibling `imports/` directory (or `--imports-dir`) before disassembling. With `-o DIR`, every ABI (main and deps) is written to `<DIR>/<name>.abi.json`. Network builtins like `credits.aleo` are picked up from the snarkVM `Process` and don't need to be on disk. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1 parent f65890d commit a302f04

14 files changed

Lines changed: 906 additions & 33 deletions

File tree

crates/abi/src/aleo.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ mod tests {
177177

178178
const SIMPLE_ALEO: &str = include_str!("../../../tests/tests/cli/test_abi_from_aleo/contents/simple.aleo");
179179
const SIMPLE_ABI: &str =
180-
include_str!("../../../tests/expectations/cli/test_abi_from_aleo/contents/simple.abi.json");
180+
include_str!("../../../tests/expectations/cli/test_abi_from_aleo/contents/simple_out/simple.aleo.abi.json");
181181

182182
#[test]
183183
fn generate_from_bytecode_matches_existing_cli_fixture() {

crates/disassembler/src/lib.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,21 @@ pub fn disassemble_from_str<N: Network>(
125125
process: &mut snarkvm::prelude::Process<N>,
126126
) -> Result<AleoProgram, LeoError> {
127127
let p = Program::<N>::from_str(program).map_err(|_| crate::errors::snarkvm_parsing_error(&name))?;
128-
process.add_program(&p).map_err(|e| crate::errors::snarkvm_validation_error(&name, e))?;
129-
Ok(disassemble(p))
128+
validate_and_disassemble(name, p, process)
129+
}
130+
131+
/// Validate `program` via `process.add_program` and disassemble. Same `add_program + disassemble` tail as
132+
/// `disassemble_from_str`, but accepts an already-parsed `Program` so callers that need to peek at imports first
133+
/// (to build a topological load order, say) don't pay for a re-parse. `process` must already have all of
134+
/// `program`'s declared imports loaded.
135+
#[cfg(not(target_arch = "wasm32"))]
136+
pub fn validate_and_disassemble<N: Network>(
137+
name: impl fmt::Display,
138+
program: Program<N>,
139+
process: &mut snarkvm::prelude::Process<N>,
140+
) -> Result<AleoProgram, LeoError> {
141+
process.add_program(&program).map_err(|e| crate::errors::snarkvm_validation_error(&name, e))?;
142+
Ok(disassemble(program))
130143
}
131144

132145
/// Disassembles Aleo bytecode using the snarkVM network selected by `network`.

0 commit comments

Comments
 (0)