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

Output builtin features for bootloader support #1580

Merged

Conversation

odesenfans
Copy link
Contributor

This commit introduces the following features/changes:

  • Paging: pages can now be added to the output builtin. These pages are reflected in the public memory of the VM when exporting the public input.
  • The state of the output builtin can now be modified using the new set_state method.
  • The output builtin can now handle attributes. These are used to generate the fact topologies of the bootloader.

Checklist

  • Linked to Github Issue
  • Unit tests added
  • Integration tests added.
  • This change requires new documentation.
    • Documentation has been added/updated.
    • CHANGELOG has been updated.

@@ -41,6 +41,8 @@ pub type Pages = HashMap<usize, PublicMemoryPage>;

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)]
pub struct OutputBuiltinAdditionalData {
#[serde(skip)]
pub base: usize,
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this field needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The problem is the following: the bootloader starts by saving the VM output builtin and replaces it by a dedicated one to run the "simple" bootloader program and capture its output.

To resolve that problem, I thought about adding this field here so that we can get the full state of the output builtin in one go. We don't want to serialize it, hence the skip. But I'm open to other proposals, I could create a dedicated struct for example.

Copy link
Contributor

Choose a reason for hiding this comment

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

Why does the new output builtin need to know the base of the old one?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We just store it so that we can restore it later on.

Copy link
Contributor

Choose a reason for hiding this comment

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

The output builtin's segment index can already be found on the CairoPie itself on the CairoPie.metdata.builtin_segments map. I don't see the need to add it in the BuiltinAdditionalData too

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh, in that case the output builtin is available and you could call the base method to obtain the output's base right?
You can then choose to store it either as a tuple or a separate struct in the bootloader code itself

Copy link
Contributor

Choose a reason for hiding this comment

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

I think there is a mixup in what the output builtin's state is (base, attributes & pages) and what the additional data is (attributes & pages). The python vm has its own get_state method that has the behaviour you are adding to get_additional_data

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can definitely do that, but then the methods to retrieve/restore the output builtin state become more specific. I can either:

  1. Replace the whole builtin object
  2. Add a method that takes a base + additional data to set the builtin state
  3. Add a new struct (ex: OutputBuiltinState) and add a getter + setter for this particular struct.

What do you prefer?

Copy link
Contributor

Choose a reason for hiding this comment

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

2 & 3 are both good solutions, 2 sound simpler so I would go for that one

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I went with solution 3 and introduced an OutputBuiltinState struct.

Copy link

codecov bot commented Jan 18, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 97.65%. Comparing base (061ba87) to head (48f86ff).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1580      +/-   ##
==========================================
+ Coverage   97.63%   97.65%   +0.01%     
==========================================
  Files          92       92              
  Lines       37464    37619     +155     
==========================================
+ Hits        36579    36735     +156     
+ Misses        885      884       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@odesenfans odesenfans force-pushed the msl/output-builtin-get-set-state branch from a3b078e to a9b8545 Compare January 29, 2024 13:00
fmoletta
fmoletta previously approved these changes Feb 2, 2024
juanbono
juanbono previously approved these changes Feb 2, 2024
@fmoletta fmoletta enabled auto-merge February 2, 2024 19:02
@fmoletta fmoletta disabled auto-merge February 2, 2024 19:03
@pefontana pefontana enabled auto-merge February 2, 2024 20:39
@pefontana pefontana disabled auto-merge February 2, 2024 20:40
@pefontana
Copy link
Collaborator

@odesenfans can you solve merge conflicts so we can merge it

@odesenfans odesenfans dismissed stale reviews from juanbono and fmoletta via b20dce7 February 5, 2024 13:51
@odesenfans odesenfans force-pushed the msl/output-builtin-get-set-state branch from 9f3efea to b20dce7 Compare February 5, 2024 13:51
fmoletta
fmoletta previously approved these changes Feb 7, 2024
@odesenfans
Copy link
Contributor Author

FYI the CI/CD fails when publishing the benchmarks to Github, no idea why.

@odesenfans odesenfans force-pushed the msl/output-builtin-get-set-state branch from b3a1851 to 73167b2 Compare February 21, 2024 23:25
Copy link
Collaborator

@juanbono juanbono left a comment

Choose a reason for hiding this comment

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

@odesenfans looks like some tests are failing. Can you take a look?

This commit introduces the following features/changes:

* Paging: pages can now be added to the output builtin. These pages are
  reflected in the public memory of the VM when exporting the public
  input.
* The state of the output builtin can now be modified using
  the new `set_state` method.
* The output builtin can now handle attributes. These are used to
  generate the fact topologies of the bootloader.
The `get_state` and `set_state` methods now rely on the new
`OutputBuiltinState` struct. Rolled back the introduction of the base
field in `OutputBuiltinAdditionalData`.
@odesenfans
Copy link
Contributor Author

@juanbono I think the failures are related to #1639, I rebased on top of the latest master.

@odesenfans odesenfans force-pushed the msl/output-builtin-get-set-state branch from 73167b2 to 48f86ff Compare March 1, 2024 14:31
@pefontana pefontana added this pull request to the merge queue Mar 1, 2024
Merged via the queue into lambdaclass:main with commit 4c08af0 Mar 1, 2024
50 of 51 checks passed
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.

4 participants