-
Notifications
You must be signed in to change notification settings - Fork 161
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: add
MastForest::advice_map
and load it before the execution
When merging forests, merge their advice maps and return error on key collision.
- Loading branch information
Showing
17 changed files
with
217 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
use assembly::Assembler; | ||
use miden_vm::DefaultHost; | ||
use processor::{ExecutionOptions, MastForest}; | ||
use prover::{Digest, StackInputs}; | ||
use vm_core::{assert_matches, Program, ONE}; | ||
|
||
#[test] | ||
fn advice_map_loaded_before_execution() { | ||
let source = "\ | ||
begin | ||
push.1.1.1.1 | ||
adv.push_mapval | ||
dropw | ||
end"; | ||
|
||
// compile and execute program | ||
let program_without_advice_map: Program = | ||
Assembler::default().assemble_program(source).unwrap(); | ||
|
||
// Test `processor::execute` fails if no advice map provided with the program | ||
let mut host = DefaultHost::default(); | ||
match processor::execute( | ||
&program_without_advice_map, | ||
StackInputs::default(), | ||
&mut host, | ||
ExecutionOptions::default(), | ||
) { | ||
Ok(_) => panic!("Expected error"), | ||
Err(e) => { | ||
assert_matches!(e, prover::ExecutionError::AdviceMapKeyNotFound(_)); | ||
}, | ||
} | ||
|
||
// Test `processor::execute` works if advice map provided with the program | ||
let mast_forest: MastForest = (**program_without_advice_map.mast_forest()).clone(); | ||
|
||
let key = Digest::new([ONE, ONE, ONE, ONE]); | ||
let value = vec![ONE, ONE]; | ||
|
||
let mut mast_forest = mast_forest.clone(); | ||
mast_forest.advice_map_mut().insert(key, value); | ||
let program_with_advice_map = | ||
Program::new(mast_forest.into(), program_without_advice_map.entrypoint()); | ||
|
||
let mut host = DefaultHost::default(); | ||
processor::execute( | ||
&program_with_advice_map, | ||
StackInputs::default(), | ||
&mut host, | ||
ExecutionOptions::default(), | ||
) | ||
.unwrap(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.