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

Remove all preinit memory #1610

Merged
merged 85 commits into from
May 8, 2024
Merged

Conversation

spiral-ladder
Copy link
Contributor

@spiral-ladder spiral-ladder commented Apr 24, 2024

Remove (non-ELF) pre-init memory from both runner and circuits.

Overall, this cuts out all the pre-init tables (-5) but adds a new table for self_prog_id (+1) (which we no longer have access to via pre-init memory), so we save 4 tables in total.

A huge chunk of the diff is adding the template code (constraints, generation, etc.) that we add for a new StorageDeviceStark for self prog id, and removing all the template code for the preinit starks.

The key thing to review here is the logic to populate SystemTape from ecalls, which is found in sdk.

@spiral-ladder spiral-ladder self-assigned this Apr 24, 2024
@spiral-ladder
Copy link
Contributor Author

Reverted SDK changes in e3c4ece - seems too big for this PR. I'll focus on runner changes for now, and leave SDK alone.

supragya and others added 17 commits April 25, 2024 09:25
Cached would incorrectly call self.evaluator.expr_tree, which would
prevent it from checking if nested nodes are already in value_cache.

We also prevent clippy from suggesting to use entry API for HashMap as
the function body is impossible to implement using entry API.
We can't actually specify `git` dependencies twice.  So only do it once.
supercedes #1552

Due to some limitations, the previous CLI PR used 2 plans instead of 1,
which should be the correct approach.

Additionally, instead of a _plan_, we use the system tape as the plan
instead, because we have everything we need there.

Few changes you might notice:

- The first program is implied to be the entrypoint program. This is
where we get the call tape hash.
- We now only require `--system-tape <SYSTEM_TAPE>` to build a
transaction bundle. (You can test this with the test script committed in
this PR.)
- We only dump the tape and its debug version now. Removed `ProofBundle`
and the plan output completely.
- Important to note that we also rely entirely on the ECALL tables - not
the init tables for bundling.
- You may see some redundant usages of `RuntimeArguments`... these are
for preinit-memory, but since they are not of concern this PR, we will
just blindly use them for now (even if there's no effect), and remove
these usages in a followup PR.

---------

Co-authored-by: Matthias Görgens <[email protected]>
fns.

Now that we don't have preinit memory, we no longer need these structs.
Also delete all code related to initialization with preinit memory -
this includes all helpers and other rkyv code.
};

// Populate partial buf from newly fetched bytes via `ECALL`
buf[populatable_from_internal_buf..].clone_from_slice(&self.internal_buf[old_len..]);
Copy link
Collaborator

Choose a reason for hiding this comment

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

This seems very weird. Why don't you just point the ecall at the portion of the buffer you are now copying into?

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 pointed the ecall to the internal_buf, which allows for seekability later on, unless i'm missing your point here

Copy link
Collaborator

Choose a reason for hiding this comment

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

OK, that makes sense (if you believe that the internal buffer makes sense..)

@matthiasgoergens matthiasgoergens changed the title [wip] Remove all preinit memory Remove all preinit memory May 8, 2024
pub struct RandomAccessPreinitMemTape {
pub tape: Box<[u8]>,
pub struct RandomAccessEcallTape {
pub ecall_id: u32,
Copy link
Collaborator

Choose a reason for hiding this comment

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

What is this good for? (And should it be an enum instead?)

Copy link
Contributor Author

@spiral-ladder spiral-ladder May 8, 2024

Choose a reason for hiding this comment

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

It's not an enum, because our VM requires it in u32. I tried refactoring this before, and it resulted in a lot of ugly .into() code.

Otherwise, we can also do the same for the rest of the ecall constants declared as u32s, which I would honestly prefer, since we have a few match statements in the code that match on ecalls and an enum would allow us to catch missing ecalls at compile-time. I shot myself in the foot with this by forgetting to include one of the ecalls in our few match statements before.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As for what this is good for, we tie it to the tape involved so that we can call invoke its id for its corresponding ecall, so that whoever is writing the guest doesn't have to think about this.

Copy link
Collaborator

@matthiasgoergens matthiasgoergens left a comment

Choose a reason for hiding this comment

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

The SDK needs a massive overhaul. But we can get this across the line for now.

Copy link
Contributor

@codeblooded1729 codeblooded1729 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 to me. Just a minor modification suggested for hardcoding self prog id ecall's requested bytes length. Nice work!

Comment on lines +128 to +130
let raw_tapes = raw_tapes_from_system_tape(system_tape, self_prog_id.unwrap().into());
let program = load_program(elf).unwrap();
let state: State<F> = State::new(program.clone(), raw_tapes);
Copy link
Contributor

Choose a reason for hiding this comment

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

this looks much neater now! 👍

"ecall",
in ("a0") SELF_PROG_ID_TAPE,
in ("a1") buf_ptr,
in ("a2") buf_len,
Copy link
Contributor

Choose a reason for hiding this comment

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

buf_len could be hardcoded here, isn't it?

@spiral-ladder spiral-ladder merged commit e5007e9 into main May 8, 2024
10 checks passed
@spiral-ladder spiral-ladder deleted the bing/obliterate-preinit-memory branch May 8, 2024 11:26
spiral-ladder added a commit that referenced this pull request May 9, 2024
… digest (#1683)

We used the magic number `32`, or in other places as `COMMITMENT_SIZE`,
in various places.

This PR creates a public module `constants` in `sdk/common` and
re-exports `DIGEST_BYTES`
found in the `poseidon2hash` module as a pub const.

Addresses
#1610 (comment) as
well

---------

Co-authored-by: Kapil <[email protected]>
Co-authored-by: codeblooded1729 <[email protected]>
matthiasgoergens added a commit that referenced this pull request May 28, 2024
A simple cleanup to make #1610
easier to review.

---------

Co-authored-by: bing <[email protected]>
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