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

Hint IO in the SDK #631

Open
wants to merge 41 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 35 commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
53db5a5
Hints in linker
matthiasgoergens Dec 5, 2024
612befb
Snapshot
matthiasgoergens Dec 6, 2024
efde5b3
Clean up
matthiasgoergens Dec 6, 2024
d7949a6
Snapshot
matthiasgoergens Dec 6, 2024
e002be2
Clean up
matthiasgoergens Dec 6, 2024
8a4906f
Clean up
matthiasgoergens Dec 6, 2024
b789f43
Clean up
matthiasgoergens Dec 6, 2024
d0af9d8
Clean up
matthiasgoergens Dec 6, 2024
8333331
Remove commented out code
matthiasgoergens Dec 6, 2024
8597909
Clarify comment
matthiasgoergens Dec 6, 2024
1b14291
taplo fmt
matthiasgoergens Dec 6, 2024
7f67dae
Merge remote-tracking branch 'origin/master' into matthias/ceno_host
matthiasgoergens Dec 10, 2024
9280a9f
Clean up
matthiasgoergens Dec 10, 2024
1ac5c7c
Fix
matthiasgoergens Dec 10, 2024
c00a5cb
Expect
matthiasgoergens Dec 10, 2024
2b2a48c
Simpler
matthiasgoergens Dec 10, 2024
1ba9692
Simpler
matthiasgoergens Dec 10, 2024
35bacc3
Explain
matthiasgoergens Dec 10, 2024
c27881f
Explain
matthiasgoergens Dec 10, 2024
ef10c0a
Minimise diff
matthiasgoergens Dec 10, 2024
fecac1a
Minimise diff
matthiasgoergens Dec 10, 2024
42da8da
Doc
matthiasgoergens Dec 10, 2024
8fdb803
Don't hardcode the size of the region
matthiasgoergens Dec 10, 2024
1e16d24
Simpler
matthiasgoergens Dec 10, 2024
2f78d46
Deduplicate
matthiasgoergens Dec 10, 2024
39280bf
Done TODO
matthiasgoergens Dec 10, 2024
31805f6
Strings
matthiasgoergens Dec 10, 2024
5091d3d
Just for fun
matthiasgoergens Dec 10, 2024
10de0da
Simpler
matthiasgoergens Dec 10, 2024
bc3dba4
Merge remote-tracking branch 'origin/master' into matthias/ceno_host
matthiasgoergens Dec 13, 2024
ea77dbd
Show hint example
matthiasgoergens Dec 13, 2024
c438b43
Formatting
matthiasgoergens Dec 13, 2024
9a746bc
Remove pedantic
matthiasgoergens Dec 13, 2024
9d76268
Use bool as test case
matthiasgoergens Dec 13, 2024
863f3ad
Suggestion
matthiasgoergens Dec 13, 2024
4d8f924
Reshuffle crates
matthiasgoergens Dec 13, 2024
0d2e317
Merge remote-tracking branch 'origin/master' into matthias/flat-struc…
matthiasgoergens Dec 13, 2024
8b6c167
Merge remote-tracking branch 'origin/master' into matthias/ceno_host
matthiasgoergens Dec 13, 2024
5a95f70
Fix
matthiasgoergens Dec 13, 2024
77df864
Merge branch 'matthias/flat-structure-again' into matthias/ceno_host
matthiasgoergens Dec 13, 2024
4d43dca
Merge remote-tracking branch 'origin/master' into matthias/ceno_host
matthiasgoergens Dec 14, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
142 changes: 141 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@
exclude = ["guest"]
members = [
"ceno_emul",
"ceno_host",
"ceno_zkvm",
"examples-builder",
"mpcs",
"multilinear_extensions",
"poseidon",
"sumcheck",
"transcript",
"ceno_zkvm",
"poseidon",
]
resolver = "2"

Expand All @@ -22,6 +23,7 @@ repository = "https://github.com/scroll-tech/ceno"
version = "0.1.0"

[workspace.dependencies]
anyhow = { version = "1.0", default-features = false }
ark-std = "0.4"
cfg-if = "1.0"
criterion = { version = "0.5", features = ["html_reports"] }
Expand Down
5 changes: 1 addition & 4 deletions ceno_emul/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ repository.workspace = true
version.workspace = true

[dependencies]
anyhow = { version = "1.0", default-features = false }
anyhow.workspace = true
elf = "0.7"
itertools.workspace = true
num-derive.workspace = true
Expand All @@ -20,9 +20,6 @@ strum.workspace = true
strum_macros.workspace = true
tracing.workspace = true

[dev-dependencies]
ceno-examples = { path = "../examples-builder" }

[features]
default = ["forbid_overflow"]
forbid_overflow = []
13 changes: 13 additions & 0 deletions ceno_emul/src/addr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

use std::{
fmt,
iter::Step,
ops::{self, Range},
};

Expand Down Expand Up @@ -106,6 +107,18 @@ impl WordAddr {
}
}

impl Step for WordAddr {
fn steps_between(start: &Self, end: &Self) -> (usize, Option<usize>) {
u32::steps_between(&start.0, &end.0)
}
fn forward_checked(start: Self, count: usize) -> Option<Self> {
u32::forward_checked(start.0, count).map(Self)
}
fn backward_checked(start: Self, count: usize) -> Option<Self> {
u32::backward_checked(start.0, count).map(Self)
}
}

impl fmt::Debug for ByteAddr {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "0x{:08x}", self.0)
Expand Down
32 changes: 32 additions & 0 deletions ceno_emul/src/host_utils.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
use std::iter::from_fn;

use crate::{ByteAddr, EmuContext, VMState, WordAddr};

const WORD_SIZE: usize = 4;
const INFO_OUT_ADDR: WordAddr = ByteAddr(0xC000_0000).waddr();
Copy link
Member

Choose a reason for hiding this comment

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

is this a placeholder for now until we have the public IO?

Copy link
Collaborator Author

@matthiasgoergens matthiasgoergens Dec 13, 2024

Choose a reason for hiding this comment

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

It's a placeholder of sorts, but for debug output, not for public IO.

We have an open issue to improve debug output.

I just moved the existing functionality around in this PR, because I want to make it accessible to other crates, instead of just using it in the internal tests. But I didn't actually change how it works here.


pub fn read_all_messages(state: &VMState) -> Vec<String> {
let mut offset: WordAddr = WordAddr::from(0);
from_fn(move || match read_message(state, offset) {
out if out.is_empty() => None,
out => {
offset += out.len().div_ceil(WORD_SIZE) as u32 + 1;
Some(out)
}
})
.collect()
}

fn read_message(state: &VMState, offset: WordAddr) -> String {
let out_addr = INFO_OUT_ADDR + offset;
let byte_len = state.peek_memory(out_addr) as usize;

String::from_utf8_lossy(
&(out_addr + 1_usize..)
.map(|memory| state.peek_memory(memory))
.flat_map(u32::to_le_bytes)
.take(byte_len)
.collect::<Vec<_>>(),
)
.to_string()
}
2 changes: 2 additions & 0 deletions ceno_emul/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#![deny(clippy::cargo)]
#![feature(step_trait)]
mod addr;
pub use addr::*;

Expand All @@ -20,3 +21,4 @@ mod elf;
pub use elf::Program;

pub mod disassemble;
pub mod host_utils;
20 changes: 20 additions & 0 deletions ceno_host/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[package]
categories.workspace = true
description = "Support for the host port of a Ceno application"
edition.workspace = true
keywords.workspace = true
license.workspace = true
name = "ceno_host"
readme.workspace = true
repository.workspace = true
version.workspace = true

[dependencies]
anyhow.workspace = true
ceno_emul = { path = "../ceno_emul" }
itertools.workspace = true
rkyv = { version = "0.8.9", default-features = false, features = ["alloc", "bytecheck"] }

[dev-dependencies]
ceno-examples = { path = "../examples-builder" }
rand.workspace = true
Loading