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

Don't hardcode program ROM hashes #1344

Open
matthiasgoergens opened this issue Mar 8, 2024 · 1 comment
Open

Don't hardcode program ROM hashes #1344

matthiasgoergens opened this issue Mar 8, 2024 · 1 comment

Comments

@matthiasgoergens
Copy link
Collaborator

In examples/token/main_native.rs we need to create a call-tape for our cross program calls. As part of that we need to specify sender and receiver of calls via their ProgramIdentifier. That ProgramIdentifier changes when you make any change to the guest programs, but we have hard-coded the identifiers.

To fix this, the native executable needs to get access to the guest executable, so it can determine its hash. We can do that via eg std::include_bytes like we do in circuits/tests/riscv_tests.rs or in examples-builder/build.rs.

@eightfilms
Copy link
Contributor

eightfilms commented Mar 10, 2024

Long-term proposal

To facilitate this, i propose we eventually standardize our Cargo.toml format for guest programs. Having main_native.rs and main_mozak.rs in guest programs works - then we can (with some level of assurance) provide a functionality in the SDK to read the Cargo.toml, find such a pattern:

[[bin]]
name = "tokenbin"
path = "main_mozak.rs"

If we find some main_mozak.rs, we know the accompanying name is the name of the mozakvm executable, which we can then hash to get its ProgramIdentifier.

Stopgap

One downside of the above approach is that this relies on the assumption of some organization of the Cargo.toml (though I suppose this is easily circumvented once we provide some external facing CLI functionality e.g. cargo mozak init, then we can alter the Cargo.toml on init.

We're early enough in development that we should probably not lock ourselves into any one approach. So for now we can have a single function in the sdk to simulate this for now:

fn hash_guest_program(path: Path) -> ProgramIdentifier { ... }

This can be used like so in a guest program:

pub fn main() {
  let this_program = mozak_sdk::sys::hash_guest_program(PathBuf::new("/path/to/my/guest/program")); 
}

When we automate this, I imagine this can be as simple as just importing a const from the sdk which we can init via a proc macro:

use mozak_sdk::sys::SELF_PROG_ID;

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

No branches or pull requests

2 participants