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

feat: add no-std to rollup-interface #1077

Merged
merged 37 commits into from
Oct 25, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
99f2e16
feat: add `no-std` to `rollup-interface`
vlopes11 Oct 19, 2023
955a38a
update fmt
vlopes11 Oct 19, 2023
5bf9608
add to_string to mock da test
vlopes11 Oct 19, 2023
70283d8
fix sov-schema-db
vlopes11 Oct 19, 2023
dcaa01f
Merge branch 'nightly' into vlopes11/feature/no-std-rollup-interface
vlopes11 Oct 20, 2023
a9a3944
add `no-std` to `sov-schema-db`
vlopes11 Oct 20, 2023
5839568
restore test-data
vlopes11 Oct 20, 2023
dd65550
fix format on sov-schema-db
vlopes11 Oct 20, 2023
4018ec1
add no-std directive to sov-schema-db
vlopes11 Oct 20, 2023
90047cb
add `no-std` to `sov-db`
vlopes11 Oct 20, 2023
b8ca399
add tokio to sov-stf-runner/sov-db
vlopes11 Oct 20, 2023
7243c70
Merge branch 'nightly' into vlopes11/feature/no-std-rollup-interface
vlopes11 Oct 20, 2023
5dd592b
add default-features to byteorder
vlopes11 Oct 20, 2023
5542288
add `tokio` as default feature of `sov-db`
vlopes11 Oct 20, 2023
74f5760
restore nightly json files
vlopes11 Oct 20, 2023
2f1d537
restore more json files
vlopes11 Oct 20, 2023
fbaf396
Merge branch 'nightly' into vlopes11/feature/no-std-rollup-interface
vlopes11 Oct 20, 2023
0739250
Merge branch 'nightly' into vlopes11/feature/no-std-rollup-interface
vlopes11 Oct 20, 2023
cf3b9a9
Merge branch 'nightly' into vlopes11/feature/no-std-rollup-interface
vlopes11 Oct 20, 2023
a97a8d0
Merge branch 'nightly' into vlopes11/feature/no-std-rollup-interface
vlopes11 Oct 23, 2023
fd94d80
Merge branch 'nightly' into vlopes11/feature/no-std-rollup-interface
vlopes11 Oct 24, 2023
5c5e320
move std feature shield bloat code to dedicated sub-modules
vlopes11 Oct 24, 2023
ae46f73
move bloat feature shield to dedicated use_std modules
vlopes11 Oct 24, 2023
1296c19
Update rollup-interface/src/state_machine/mocks/zk_vm.rs
vlopes11 Oct 24, 2023
b687b0c
revert sov-db & sov-schema-db
vlopes11 Oct 24, 2023
0fe421d
restore split impl for std bincode
vlopes11 Oct 24, 2023
57eee14
reorg sov-schema-db manifest w/ default-features
vlopes11 Oct 24, 2023
cf50df4
move da-mock-service to its own module
vlopes11 Oct 24, 2023
e788931
Merge branch 'nightly' into vlopes11/feature/no-std-rollup-interface
vlopes11 Oct 24, 2023
ed95780
upd cargo lock
vlopes11 Oct 24, 2023
31e4245
remote stall file
vlopes11 Oct 25, 2023
5320fd8
add no-std CI check
vlopes11 Oct 25, 2023
ce08b86
Merge branch 'nightly' into vlopes11/feature/no-std-rollup-interface
vlopes11 Oct 25, 2023
3ea1235
fix cargo docs
vlopes11 Oct 25, 2023
31939ea
require borsh features for sov-db
vlopes11 Oct 25, 2023
c3dcf91
add check_no_std to required all-green ci jobs
vlopes11 Oct 25, 2023
fce8c53
clean check_no_std ci cache commands
vlopes11 Oct 25, 2023
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
22 changes: 22 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,28 @@ jobs:
echo "Linting or formatting errors detected, please run 'make lint-fix' to fix it";
exit 1
fi

check_no_std:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Install Rust
uses: actions-rs/toolchain@v1
with:
toolchain: stable
target: thumbv6m-none-eabi
override: true
- uses: Swatinem/rust-cache@v2
with:
cache-provider: "buildjet"
shared-key: cargo-check-cache
save-if: ${{ github.ref == 'refs/heads/nightly' }}
workspaces: |
.
fuzz
vlopes11 marked this conversation as resolved.
Show resolved Hide resolved
- name: Run check
run: make check-no-std

# Check that every combination of features is working properly.
hack:
name: features
Expand Down
1 change: 0 additions & 1 deletion Cargo.lock

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

5 changes: 2 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ jmt = "0.8.0"
async-trait = "0.1.71"
anyhow = { version = "1.0.68", default-features = false }
arbitrary = { version = "1.3.1", features = ["derive"] }
borsh = { version = "0.10.3", default-features = false, features = ["rc", "bytes"] }
borsh = { version = "0.10.3", default-features = false }
# TODO: Consider replacing this serialization format
# https://github.com/Sovereign-Labs/sovereign-sdk/issues/283
bincode = "1.3.3"
Expand All @@ -80,10 +80,9 @@ proptest-derive = "0.3.0"
rand = "0.8"
rayon = "1.8.0"
rocksdb = { version = "0.21.0", features = ["lz4"] }
serde = { version = "1.0.188", default-features = false, features = ["alloc", "derive", "rc"] }
serde = { version = "1.0.188", default-features = false, features = ["alloc", "derive"] }
serde_json = { version = "1.0", default-features = false, features = ["alloc"] }
sha2 = { version = "0.10.6", default-features = false }
spin = "0.9.8"
thiserror = "1.0.50"
tiny-keccak = "2.0.2"
tracing = { version = "0.1.40", default-features = false }
Expand Down
16 changes: 16 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# no-std packages to be checked
NO_STD := "sov-rollup-interface"

.PHONY: help

help: ## Display this help message
Expand All @@ -23,6 +26,7 @@ install-dev-tools: ## Installs all necessary cargo helpers
cargo install cargo-nextest --locked
cargo install cargo-risczero
cargo risczero install
rustup target add thumbv6m-none-eabi

lint: ## cargo check and clippy. Skip clippy on guest code since it's not supported by risc0
## fmt first, because it's the cheapest
Expand All @@ -42,6 +46,18 @@ check-features: ## Checks that project compiles with all combinations of feature
check-fuzz: ## Checks that fuzz member compiles
$(MAKE) -C fuzz check

check-no-std: ## Checks that project compiles without std
@for package in $(NO_STD); do \
echo "Checking no-std $${package}..."; \
cargo check -p $$package \
--target thumbv6m-none-eabi \
--no-default-features ; \
cargo check -p $$package \
--target thumbv6m-none-eabi \
--no-default-features \
--features native ; \
done

find-unused-deps: ## Prints unused dependencies for project. Note: requires nightly
cargo udeps --all-targets --all-features

Expand Down
26 changes: 0 additions & 26 deletions examples/demo-rollup/provers/risc0/guest-celestia/Cargo.lock

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

26 changes: 0 additions & 26 deletions examples/demo-rollup/provers/risc0/guest-mock/Cargo.lock

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

4 changes: 2 additions & 2 deletions module-system/sov-state/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ resolver = "2"
[dependencies]
anyhow = { workspace = true }
arbitrary = { workspace = true, optional = true }
borsh = { workspace = true }
borsh = { workspace = true, features = ["rc", "bytes"] }
bcs = { workspace = true }
proptest = { workspace = true, optional = true }
proptest-derive = { workspace = true, optional = true }
serde = { workspace = true }
serde = { workspace = true, features = ["rc"] }
serde_json = { workspace = true }
thiserror = { workspace = true }
sov-rollup-interface = { path = "../../rollup-interface", version = "0.3" }
Expand Down
8 changes: 4 additions & 4 deletions rollup-interface/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,11 @@ exclude = [
anyhow = { workspace = true, default-features = false }
async-trait = { workspace = true }
borsh = { workspace = true }
bytes = { workspace = true }
bytes = { workspace = true, optional = true, default-features = true }
digest = { workspace = true }
hex = { workspace = true }
serde = { workspace = true }
sha2 = { workspace = true, optional = true }
spin = { workspace = true }
thiserror = { workspace = true, optional = true }
tokio = { workspace = true, optional = true }

Expand All @@ -45,13 +44,14 @@ proptest-derive = { workspace = true }
[features]
default = ["std"]
native = []
fuzzing = ["proptest", "proptest-derive", "sha2"]
fuzzing = ["proptest", "proptest-derive", "sha2", "std"]
mocks = ["sha2", "bytes/serde"]
std = [
"anyhow/default",
"bincode",
"borsh/default",
"bytes/default",
"borsh/bytes",
"bytes",
"digest/default",
"hex/default",
"proptest?/default",
Expand Down
16 changes: 6 additions & 10 deletions rollup-interface/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#![cfg_attr(not(feature = "std"), no_std)]
#![deny(missing_docs)]

extern crate alloc;

mod state_machine;
pub use state_machine::*;

Expand All @@ -16,15 +18,9 @@ pub use {anyhow, digest};

/// A facade for the `std` crate.
pub mod maybestd {
pub use borsh::maybestd::{borrow, boxed, collections, format, io, rc, string, vec};

/// A facade for the `sync` std module.
pub mod sync {
#[cfg(feature = "std")]
pub use std::sync::Mutex;
// sync will be available only when the target supports atomic operations
#[cfg(target_has_atomic = "ptr")]
pub use alloc::sync;

pub use borsh::maybestd::sync::*;
#[cfg(not(feature = "std"))]
pub use spin::Mutex;
}
pub use borsh::maybestd::{borrow, boxed, collections, format, io, string, vec};
}
11 changes: 5 additions & 6 deletions rollup-interface/src/state_machine/da.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
//! Defines traits and types used by the rollup to verify claims about the
//! DA layer.
use core::cmp::min;
use core::fmt::Debug;

use borsh::{BorshDeserialize, BorshSerialize};
use bytes::Buf;
use serde::de::DeserializeOwned;
use serde::{Deserialize, Serialize};

use crate::maybestd::vec::Vec;
use crate::zk::ValidityCondition;
use crate::BasicAddress;

Expand Down Expand Up @@ -70,12 +67,13 @@ pub trait DaVerifier {
) -> Result<<Self::Spec as DaSpec>::ValidityCondition, Self::Error>;
}

#[cfg(feature = "std")]
#[derive(Debug, Clone, Serialize, Deserialize, BorshDeserialize, BorshSerialize, PartialEq)]
/// Simple structure that implements the Read trait for a buffer and counts the number of bytes read from the beginning.
/// Useful for the partial blob reading optimization: we know for each blob how many bytes have been read from the beginning.
///
/// Because of soundness issues we cannot implement the Buf trait because the prover could get unproved blob data using the chunk method.
pub struct CountedBufReader<B: Buf> {
pub struct CountedBufReader<B: bytes::Buf> {
/// The original blob data.
inner: B,

Expand All @@ -84,7 +82,8 @@ pub struct CountedBufReader<B: Buf> {
accumulator: Vec<u8>,
}

impl<B: Buf> CountedBufReader<B> {
#[cfg(feature = "std")]
impl<B: bytes::Buf> CountedBufReader<B> {
/// Creates a new buffer reader with counter from an objet that implements the buffer trait
pub fn new(inner: B) -> Self {
let buf_size = inner.remaining();
Expand All @@ -104,7 +103,7 @@ impl<B: Buf> CountedBufReader<B> {
}
// `Buf::advance` would panic if `num_bytes` was greater than the length of the remaining unverified data,
// but we just advance to the end of the buffer.
let num_to_read = min(remaining, requested);
let num_to_read = core::cmp::min(remaining, requested);
// Extend the inner vector with zeros (copy_to_slice requires the vector to have
// the correct *length* not just capacity)
self.accumulator
Expand Down
Loading