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

Add missing docs to rollup-interface. Cleanup module structure. #483

Merged
merged 3 commits into from
Jul 10, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
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
20 changes: 7 additions & 13 deletions adapters/celestia/src/celestia.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@ use nmt_rs::NamespacedHash;
use prost::bytes::Buf;
use prost::Message;
use serde::{Deserialize, Serialize};
use sov_rollup_interface::da::CountedBufReader;
use sov_rollup_interface::traits::{
AddressTrait as Address, BlockHeaderTrait as BlockHeader, CanonicalHash,
};
use sov_rollup_interface::da::{BlockHeaderTrait as BlockHeader, CountedBufReader};
use sov_rollup_interface::AddressTrait;
pub use tendermint::block::Header as TendermintHeader;
use tendermint::crypto::default::Sha256;
use tendermint::merkle::simple_hash_from_byte_vectors;
Expand Down Expand Up @@ -248,14 +246,6 @@ impl CelestiaHeader {
}
}

impl CanonicalHash for CelestiaHeader {
type Output = TmHash;

fn hash(&self) -> Self::Output {
TmHash(self.header.hash())
}
}

#[derive(PartialEq, Clone, Debug, Serialize, Deserialize, BorshDeserialize, BorshSerialize)]
pub struct BlobWithSender {
pub blob: CountedBufReader<BlobIterator>,
Expand Down Expand Up @@ -283,6 +273,10 @@ impl BlockHeader for CelestiaHeader {
*cached_hash = Some(TmHash(hash));
TmHash(hash)
}

fn hash(&self) -> Self::Hash {
TmHash(self.header.hash())
}
}

#[derive(Deserialize, Serialize, PartialEq, Debug, Clone)]
Expand Down Expand Up @@ -341,7 +335,7 @@ impl Display for H160 {
}
}

impl Address for H160 {}
impl AddressTrait for H160 {}

pub fn parse_pfb_namespace(
group: NamespaceGroup,
Expand Down
2 changes: 1 addition & 1 deletion adapters/celestia/src/verifier/address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::str::FromStr;

use borsh::{BorshDeserialize, BorshSerialize};
use serde::{Deserialize, Serialize};
use sov_rollup_interface::traits::AddressTrait;
use sov_rollup_interface::AddressTrait;

const HRP: &str = "celestia";

Expand Down
6 changes: 3 additions & 3 deletions adapters/celestia/src/verifier/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ use nmt_rs::NamespaceId;
use serde::{Deserialize, Serialize};
use sov_rollup_interface::crypto::SimpleHasher;
use sov_rollup_interface::da::{
self, BlobTransactionTrait, BlockHashTrait as BlockHash, CountedBufReader, DaSpec,
self, BlobTransactionTrait, BlockHashTrait as BlockHash, BlockHeaderTrait, CountedBufReader,
DaSpec,
};
use sov_rollup_interface::traits::{BlockHeaderTrait, CanonicalHash};
use sov_rollup_interface::zk::traits::ValidityCondition;
use sov_rollup_interface::zk::ValidityCondition;
use sov_rollup_interface::Buf;
use thiserror::Error;

Expand Down
2 changes: 1 addition & 1 deletion adapters/risc0/src/guest.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#[cfg(target_os = "zkvm")]
use risc0_zkvm::guest::env;
use sov_rollup_interface::zk::traits::{Zkvm, ZkvmGuest};
use sov_rollup_interface::zk::{Zkvm, ZkvmGuest};

use crate::Risc0MethodId;

Expand Down
2 changes: 1 addition & 1 deletion adapters/risc0/src/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use risc0_zkvm::receipt::verify_with_hal;
use risc0_zkvm::serde::to_vec;
use risc0_zkvm::sha::Impl;
use risc0_zkvm::{Prover, Receipt};
use sov_rollup_interface::zk::traits::{Zkvm, ZkvmHost};
use sov_rollup_interface::zk::{Zkvm, ZkvmHost};

use crate::Risc0MethodId;

Expand Down
2 changes: 1 addition & 1 deletion adapters/risc0/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use risc0_zkvm::sha::Digest;
use serde::{Deserialize, Serialize};
use sov_rollup_interface::zk::traits::Matches;
use sov_rollup_interface::zk::Matches;

pub mod guest;
#[cfg(feature = "native")]
Expand Down
2 changes: 1 addition & 1 deletion examples/demo-prover/host/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use sov_modules_api::RpcRunner;
use sov_rollup_interface::services::da::DaService;
use sov_rollup_interface::services::stf_runner::StateTransitionRunner;
use sov_rollup_interface::stf::StateTransitionFunction;
use sov_rollup_interface::zk::traits::ZkvmHost;
use sov_rollup_interface::zk::ZkvmHost;
use sov_state::Storage;
use tracing::{info, Level};

Expand Down
2 changes: 1 addition & 1 deletion examples/demo-prover/methods/guest/src/bin/rollup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use sov_rollup_interface::crypto::NoOpHasher;
use sov_rollup_interface::da::{DaSpec, DaVerifier};
use sov_rollup_interface::services::stf_runner::StateTransitionRunner;
use sov_rollup_interface::stf::{StateTransitionFunction, ZkConfig};
use sov_rollup_interface::zk::traits::{StateTransition, ZkvmGuest};
use sov_rollup_interface::zk::{StateTransition, ZkvmGuest};

// The rollup stores its data in the namespace b"sov-test" on Celestia
const ROLLUP_NAMESPACE: NamespaceId = NamespaceId(ROLLUP_NAMESPACE_RAW);
Expand Down
5 changes: 2 additions & 3 deletions examples/demo-rollup/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,11 @@ use risc0_adapter::host::Risc0Verifier;
use sov_db::ledger_db::{LedgerDB, SlotCommit};
use sov_modules_api::RpcRunner;
use sov_rollup_interface::crypto::NoOpHasher;
use sov_rollup_interface::da::DaVerifier;
use sov_rollup_interface::da::{BlockHeaderTrait, DaVerifier};
use sov_rollup_interface::services::da::{DaService, SlotData};
use sov_rollup_interface::services::stf_runner::StateTransitionRunner;
use sov_rollup_interface::stf::StateTransitionFunction;
use sov_rollup_interface::traits::CanonicalHash;
use sov_rollup_interface::zk::traits::ValidityConditionChecker;
use sov_rollup_interface::zk::ValidityConditionChecker;
// RPC related imports
use sov_sequencer::get_sequencer_rpc;
use sov_state::Storage;
Expand Down
2 changes: 1 addition & 1 deletion examples/demo-simple-stf/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::io::Read;
use sha2::Digest;
use sov_rollup_interface::da::BlobTransactionTrait;
use sov_rollup_interface::stf::{BatchReceipt, StateTransitionFunction};
use sov_rollup_interface::zk::traits::Zkvm;
use sov_rollup_interface::zk::Zkvm;

#[derive(PartialEq, Debug, Clone, Eq, serde::Serialize, serde::Deserialize)]

Expand Down
2 changes: 1 addition & 1 deletion examples/demo-simple-stf/tests/stf_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::fmt::Display;
use demo_simple_stf::{ApplyBlobResult, CheckHashPreimageStf};
use sov_rollup_interface::mocks::{MockZkvm, TestBlob};
use sov_rollup_interface::stf::StateTransitionFunction;
use sov_rollup_interface::traits::AddressTrait;
use sov_rollup_interface::AddressTrait;

#[derive(PartialEq, Debug, Clone, Eq, serde::Serialize, serde::Deserialize)]
pub struct DaAddress {
Expand Down
2 changes: 1 addition & 1 deletion examples/demo-stf/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use sov_rollup_interface::services::stf_runner::StateTransitionRunner;
#[cfg(feature = "native")]
use sov_rollup_interface::stf::ProverConfig;
use sov_rollup_interface::stf::ZkConfig;
use sov_rollup_interface::zk::traits::Zkvm;
use sov_rollup_interface::zk::Zkvm;
#[cfg(feature = "native")]
use sov_state::ProverStorage;
use sov_state::{Storage, ZkStorage};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use anyhow::Result;
use borsh::{BorshDeserialize, BorshSerialize};
use sov_bank::Coins;
use sov_modules_api::CallResponse;
use sov_rollup_interface::zk::traits::Zkvm;
use sov_rollup_interface::zk::Zkvm;
use sov_state::WorkingSet;

use crate::ProverIncentives;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use anyhow::Result;
use sov_rollup_interface::zk::traits::Zkvm;
use sov_rollup_interface::zk::Zkvm;
use sov_state::WorkingSet;

use crate::ProverIncentives;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub mod query;
use borsh::{BorshDeserialize, BorshSerialize};
use sov_modules_api::{Context, Error};
use sov_modules_macros::ModuleInfo;
use sov_rollup_interface::zk::traits::Zkvm;
use sov_rollup_interface::zk::Zkvm;
use sov_state::WorkingSet;

pub struct ProverIncentivesConfig<C: Context, Vm: Zkvm> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use serde::{Deserialize, Serialize};
use sov_rollup_interface::zk::traits::Zkvm;
use sov_rollup_interface::zk::Zkvm;
use sov_state::WorkingSet;

use super::ProverIncentives;
Expand Down
3 changes: 2 additions & 1 deletion module-system/sov-modules-api/src/default_context.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
#[cfg(feature = "native")]
use serde::{Deserialize, Serialize};
use sov_rollup_interface::crypto::SimpleHasher;
use sov_rollup_interface::AddressTrait;
#[cfg(feature = "native")]
use sov_state::ProverStorage;
use sov_state::{ArrayWitness, DefaultStorageSpec, ZkStorage};

use crate::default_signature::{DefaultPublicKey, DefaultSignature};
use crate::{Address, AddressTrait, Context, PublicKey, Spec};
use crate::{Address, Context, PublicKey, Spec};

#[cfg(feature = "native")]
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
Expand Down
2 changes: 1 addition & 1 deletion module-system/sov-modules-api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub use prefix::Prefix;
pub use response::CallResponse;
use serde::{Deserialize, Serialize};
pub use sov_rollup_interface::crypto::SimpleHasher as Hasher;
pub use sov_rollup_interface::traits::AddressTrait;
pub use sov_rollup_interface::AddressTrait;
use sov_state::{Storage, Witness, WorkingSet};
use thiserror::Error;

Expand Down
7 changes: 2 additions & 5 deletions module-system/sov-modules-stf-template/src/app_template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use sov_modules_api::hooks::{ApplyBlobHooks, TxHooks};
use sov_modules_api::{Context, DispatchCall, Genesis};
use sov_rollup_interface::da::{BlobTransactionTrait, CountedBufReader};
use sov_rollup_interface::stf::{BatchReceipt, TransactionReceipt};
use sov_rollup_interface::traits::BatchTrait;
use sov_rollup_interface::Buf;
use sov_state::StateCheckpoint;
use tracing::{debug, error};
Expand Down Expand Up @@ -256,11 +255,9 @@ where
match Batch::deserialize_reader(blob_data) {
Ok(batch) => Ok(batch),
Err(e) => {
let data_so_far = blob_data.acc();
error!(
"Unable to deserialize batch provided by the sequencer {}: 0x{}",
e,
hex::encode(data_so_far),
"Unable to deserialize batch provided by the sequencer {}",
e
);
Err(SlashingReason::InvalidBatchEncoding)
}
Expand Down
14 changes: 4 additions & 10 deletions module-system/sov-modules-stf-template/src/batch.rs
Original file line number Diff line number Diff line change
@@ -1,26 +1,20 @@
use borsh::{BorshDeserialize, BorshSerialize};
use serde::{Deserialize, Serialize};
use sov_rollup_interface::traits::{BatchTrait, TransactionTrait};

// use sov_rollup_interface::traits::TransactionTrait;
use crate::tx_verifier::RawTx;

#[derive(Debug, PartialEq, Clone, BorshDeserialize, BorshSerialize, Serialize, Deserialize)]
pub struct Batch {
pub txs: Vec<RawTx>,
}

impl BatchTrait for Batch {
type Transaction = RawTx;

fn transactions(&self) -> &[Self::Transaction] {
impl Batch {
pub fn transactions(&self) -> &[RawTx] {
&self.txs
}

fn take_transactions(self) -> Vec<Self::Transaction> {
pub fn take_transactions(self) -> Vec<RawTx> {
self.txs
}
}

impl TransactionTrait for RawTx {
type Hash = [u8; 32];
}
2 changes: 1 addition & 1 deletion module-system/sov-modules-stf-template/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pub use batch::Batch;
use sov_modules_api::hooks::{ApplyBlobHooks, TxHooks};
use sov_modules_api::{Context, DispatchCall, Genesis, Spec};
use sov_rollup_interface::stf::{BatchReceipt, StateTransitionFunction};
use sov_rollup_interface::zk::traits::Zkvm;
use sov_rollup_interface::zk::Zkvm;
use sov_state::{StateCheckpoint, Storage};
pub use tx_verifier::RawTx;

Expand Down
6 changes: 6 additions & 0 deletions rollup-interface/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
//! This crate defines the core traits and types used by all Sovereign SDK rollups.
//! It specifies the interfaces which allow the same "business logic" to run on different
//! DA layers and be proven with different zkVMS, all while retaining compatibility
//! with the same basic full node implementation.
#![deny(missing_docs)]
mod state_machine;
pub use state_machine::*;

mod node;

pub use borsh::maybestd;
pub use node::*;
3 changes: 3 additions & 0 deletions rollup-interface/src/node/mod.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
//! The `node` module defines types traits which are used by the full node but
//! are not part of the rollup's state machine. These types/traits are never invoked
//! inside of a zkVM, so they may be non-deterministic, have access to networking/disk, etc.
pub mod rpc;
pub mod services;
Loading