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

Add MastForest::advice_map for the data required in the advice provider before execution #1574

Merged
merged 4 commits into from
Nov 21, 2024

Conversation

greenhat
Copy link
Contributor

@greenhat greenhat commented Nov 14, 2024

This PR implements VM-facing part of #1547 and adds advice map to the MastForest that is loaded in the advice provider when the MastForest executed.

This PR contains changes exposing AdviceProvider in Host (see commit) introduced in #1572 (see comment)

@greenhat greenhat force-pushed the greenhat/i1547-mastforest-add-advicemap branch from f1fd68b to a36a9af Compare November 15, 2024 11:36
@greenhat greenhat force-pushed the greenhat/i1547-mastforest-add-advicemap branch from d890a6a to fe7a7da Compare November 15, 2024 12:15
@greenhat greenhat changed the base branch from main to next November 15, 2024 14:45
@greenhat greenhat force-pushed the greenhat/i1547-mastforest-add-advicemap branch 4 times, most recently from c9860b6 to eda4a01 Compare November 18, 2024 13:58
@greenhat greenhat changed the title Add MastForest::advice_map for the data required in the advice provider before execution [1/2] Add MastForest::advice_map for the data required in the advice provider before execution Nov 19, 2024
@greenhat greenhat force-pushed the greenhat/i1547-mastforest-add-advicemap branch from eda4a01 to 006e03a Compare November 19, 2024 14:40
@greenhat greenhat changed the title [1/2] Add MastForest::advice_map for the data required in the advice provider before execution Add MastForest::advice_map for the data required in the advice provider before execution Nov 19, 2024
@greenhat greenhat marked this pull request as ready for review November 19, 2024 14:52
@greenhat greenhat requested review from bobbinth and plafer November 19, 2024 14:52
Copy link
Contributor

@plafer plafer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for taking this on!

core/src/mast/serialization/mod.rs Outdated Show resolved Hide resolved
core/src/mast/merger/mod.rs Outdated Show resolved Hide resolved
processor/src/lib.rs Outdated Show resolved Hide resolved
@@ -163,6 +167,17 @@ impl MastForestMerger {
Ok(())
}

fn merge_advice_map(&mut self, other_forest: &MastForest) -> Result<(), MastForestError> {
for (key, value) in other_forest.advice_map.clone().into_iter() {
if self.mast_forest.advice_map().get(&key).is_some() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be a bit more forgiving to only return an error if the advice maps have different values at the same key

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point! Done.
My line of thinking was that keys in the advice map are expected to be so unique (hashes) that any collision would mean that something is off and we better fail early. I suppose we can cut some slack when values are the same (user sets the values twice?).

@@ -253,6 +253,18 @@ where
return Err(ExecutionError::ProgramAlreadyExecuted);
}

// Load the program's advice data into the advice provider
for (digest, values) in program.mast_forest().advice_map().clone().into_iter() {
if self.host.borrow().advice_provider().get_mapped_values(&digest).is_some() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similarly here, could be return an error only if the values are different at the same key?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Since the behavior if the key is already present is to replace the value
with the new one there is no other error that can possibly arise in this
method.
@greenhat greenhat force-pushed the greenhat/i1547-mastforest-add-advicemap branch 2 times, most recently from 92f3309 to 6dcac60 Compare November 20, 2024 09:56
@greenhat greenhat requested a review from plafer November 20, 2024 10:03
@greenhat
Copy link
Contributor Author

@plafer Thank you for the review! I addressed all the comments. Please do another round.

@greenhat greenhat force-pushed the greenhat/i1547-mastforest-add-advicemap branch from 6dcac60 to 2f8f3fe Compare November 20, 2024 10:28
Copy link
Contributor

@plafer plafer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Just a few nits but we're basically there.

Let's hold off on merging this temporarily while we figure out with #1572 how we want the Host/AdviceProvider API to look like

core/src/mast/merger/mod.rs Outdated Show resolved Hide resolved
processor/src/host/mod.rs Outdated Show resolved Hide resolved
processor/src/lib.rs Outdated Show resolved Hide resolved
When merging forests, merge their advice maps and return error on key
collision.
@greenhat greenhat force-pushed the greenhat/i1547-mastforest-add-advicemap branch from 2f8f3fe to 93869ef Compare November 20, 2024 12:41
@greenhat
Copy link
Contributor Author

Let's hold off on merging this temporarily while we figure out with #1572 how we want the Host/AdviceProvider API to look like

No problem! I'll keep an eye on #1572

Copy link
Contributor

@plafer plafer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thank you!

@plafer plafer merged commit 9f56203 into next Nov 21, 2024
9 checks passed
@plafer plafer deleted the greenhat/i1547-mastforest-add-advicemap branch November 21, 2024 12:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants