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

Chain state module #598

Merged
merged 107 commits into from
Aug 10, 2023
Merged
Show file tree
Hide file tree
Changes from 85 commits
Commits
Show all changes
107 commits
Select commit Hold shift + click to select a range
b998eec
WIP: Add optimsitic sync
preston-evans98 Jun 22, 2023
08e8d88
WIP: implement chain state module
preston-evans98 Jun 30, 2023
6411a8d
WIP: Add attester incentives
preston-evans98 Jun 30, 2023
578f4d6
Merging with main
theochap Jul 5, 2023
7f68c02
Can compile
theochap Jul 6, 2023
fd4a64d
Does compile
theochap Jul 6, 2023
eaaac02
Start working on attester incentives
theochap Jul 7, 2023
76f79c8
Implement attestation processing
theochap Jul 7, 2023
1d85189
Finish unbonding
theochap Jul 10, 2023
de3fb92
Improve events
theochap Jul 10, 2023
54a0224
Rename sov-attester-incentives to optimistic-workflow
theochap Jul 10, 2023
c03476d
Refactor
theochap Jul 10, 2023
b69f877
Start working on apply_sync_data_blob
theochap Jul 11, 2023
2c5503f
Refactoring apply_tx_blob
theochap Jul 11, 2023
0536ef2
Refactoring files
theochap Jul 11, 2023
ecda2e9
Merging with main
theochap Jul 11, 2023
6042163
Rewriting unbonding
theochap Jul 15, 2023
09f5cd7
Refactor attestation processing
theochap Jul 15, 2023
6469151
Refactor process challenge
theochap Jul 15, 2023
99e7285
Refactoring
theochap Jul 15, 2023
6b0ece9
Fixing compile issues
theochap Jul 15, 2023
5e35c50
Does compile
theochap Jul 15, 2023
f570d6b
Everything compiles
theochap Jul 15, 2023
26edc19
Add 2 phase unbonding back
theochap Jul 17, 2023
8a802b9
Updating tests
theochap Jul 18, 2023
24178de
Changing bonding proof
theochap Jul 21, 2023
5b3f223
Changing bonding proof
theochap Jul 21, 2023
99c4601
Fixing get_with_proof
theochap Jul 21, 2023
67c9686
Fixing chain updates
theochap Jul 29, 2023
5a02c38
Change STF interface to work on slot level
citizen-stig Jul 25, 2023
3464910
Adding chain state
theochap Aug 1, 2023
ca3e04b
Merge branch 'feature/change_stf_signature_for_handling_whole_block' …
theochap Aug 1, 2023
184d3da
Starting chain state
theochap Aug 1, 2023
1bc406a
Does compile
theochap Aug 1, 2023
7c5dd26
Fix lint
theochap Aug 1, 2023
0df1160
Fixing warnings
theochap Aug 1, 2023
880f6ee
Integrating slot hooks
theochap Aug 1, 2023
040a950
Populating todos
theochap Aug 1, 2023
e214ec1
Adding data generation for different modules
theochap Aug 2, 2023
e8298aa
Implementing automatic bank data generation
theochap Aug 2, 2023
074217d
Fixing stf
theochap Aug 2, 2023
79af97f
Compiles
theochap Aug 3, 2023
8a77f73
Fixing chain-state test, adding EncodeCall trait
theochap Aug 3, 2023
a233c35
Fixing lints
theochap Aug 3, 2023
370fa85
Chain state testing
theochap Aug 4, 2023
5c86b93
Simple chain state module tests
theochap Aug 4, 2023
2f0ceff
Merging with main
theochap Aug 4, 2023
631c6f5
All tests pass
theochap Aug 4, 2023
5b6c47e
Fixing lints
theochap Aug 4, 2023
0b0b929
Fixing comments PR
theochap Aug 4, 2023
67734b5
Fixing comments PR
theochap Aug 4, 2023
8b27dfc
nit fix
theochap Aug 4, 2023
0aa613e
Fixing PR comments
theochap Aug 7, 2023
d18c933
Deleting borsh compat
theochap Aug 7, 2023
cc57631
Adding back github and config files
theochap Aug 7, 2023
1423880
Specifying commit for jmt
theochap Aug 7, 2023
d5b3462
Update module-system/sov-state/src/storage.rs
theochap Aug 7, 2023
4dc84f3
Fixing comments PR
theochap Aug 7, 2023
63895c8
Merge branch 'chain-state' of github.com:Sovereign-Labs/sovereign int…
theochap Aug 7, 2023
ca36177
Update adapters/risc0/src/host.rs
theochap Aug 8, 2023
afd46e2
Update adapters/risc0/src/host.rs
theochap Aug 8, 2023
1b4df99
Fixing error handling
theochap Aug 8, 2023
6d2b92a
Merge branch 'chain-state' of github.com:Sovereign-Labs/sovereign int…
theochap Aug 8, 2023
ae1f941
Merging with main
theochap Aug 8, 2023
8cfe7b6
Fixing lints
theochap Aug 8, 2023
9dfc94d
Merging with main
theochap Aug 8, 2023
612e679
Fixing lints
theochap Aug 8, 2023
c6da4fb
Fix lints
theochap Aug 8, 2023
63184d4
Update rollup-interface/src/state_machine/mocks.rs
theochap Aug 9, 2023
a99f575
Addressing PR comments
theochap Aug 9, 2023
2180ef4
Merge branch 'chain-state' of github.com:Sovereign-Labs/sovereign int…
theochap Aug 9, 2023
6769022
Including PR comments
theochap Aug 9, 2023
fc7db10
Update Cargo.toml
theochap Aug 9, 2023
0f04e1e
Update adapters/risc0/src/guest.rs
theochap Aug 9, 2023
ad5ccd5
Update adapters/risc0/src/host.rs
theochap Aug 9, 2023
6108e2f
Update adapters/risc0/src/host.rs
theochap Aug 9, 2023
1df9c50
Adding back genesis and call
theochap Aug 9, 2023
f659430
Merge branch 'chain-state' of github.com:Sovereign-Labs/sovereign int…
theochap Aug 9, 2023
8eb9b79
Fix lints
theochap Aug 9, 2023
6b1de1d
Merge branch 'nightly' into chain-state
theochap Aug 9, 2023
270097a
Lint
theochap Aug 9, 2023
8c8632d
Merge branch 'nightly' into chain-state
theochap Aug 9, 2023
aa1d1f5
Restoring default context
theochap Aug 9, 2023
6cecdc9
Merge branch 'chain-state' of github.com:Sovereign-Labs/sovereign int…
theochap Aug 9, 2023
c8355eb
Fixing imports
theochap Aug 9, 2023
4015b19
Fixing prover compiles
citizen-stig Aug 9, 2023
c83af72
Fix prover compiles
citizen-stig Aug 9, 2023
e85d4c8
Fixing end slot hook
theochap Aug 9, 2023
26558ec
Reorganizing integration tests
theochap Aug 10, 2023
b5a32c8
Reorganizing integration tests
theochap Aug 10, 2023
fc4f20e
Reorganizing integration tests
theochap Aug 10, 2023
f9ae3eb
Adding unit tests for chain-state
theochap Aug 10, 2023
5796a7e
Update chain state tests
theochap Aug 10, 2023
5857473
Update apply slot signature
theochap Aug 10, 2023
1fea05e
Fix demo-prover
theochap Aug 10, 2023
5d7cae0
Update adapters/risc0/src/guest.rs
theochap Aug 10, 2023
da9edbf
Update adapters/risc0/src/host.rs
theochap Aug 10, 2023
80d5340
Merge with nightly
theochap Aug 10, 2023
5713a28
Fix lints
theochap Aug 10, 2023
7e1e039
Format demo-prover
theochap Aug 10, 2023
4882d3b
Fix feature data generators
theochap Aug 10, 2023
8000947
Update examples/demo-stf/Cargo.toml
theochap Aug 10, 2023
603a1fd
Update adapters/risc0/src/guest.rs
theochap Aug 10, 2023
5a666c9
Fixing pr comments
theochap Aug 10, 2023
8cb5ae8
Merge branch 'chain-state' of github.com:Sovereign-Labs/sovereign int…
theochap Aug 10, 2023
85ebe59
Fix lint
theochap Aug 10, 2023
00c3046
Removing call from chain-state because provided by blanket
theochap Aug 10, 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
41 changes: 39 additions & 2 deletions Cargo.lock

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

5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ members = [
"module-system/sov-modules-api",
"module-system/module-schemas",
"module-system/utils/sov-first-read-last-write-cache",
"module-system/utils/sov-data-generators",
"module-system/module-implementations/sov-accounts",
"module-system/module-implementations/sov-bank",
"module-system/module-implementations/sov-chain-state",
"module-system/module-implementations/sov-blob-storage",
"module-system/module-implementations/sov-evm",
"module-system/module-implementations/sov-prover-incentives",
Expand All @@ -48,7 +50,8 @@ rust-version = "1.66"

[workspace.dependencies]
# Dependencies maintained by sovereign
jmt = "0.6.0"
# TODO: replace by release number once available on crates.io: tracking issue https://github.com/Sovereign-Labs/sovereign-sdk/issues/632
jmt = { git = "https://github.com/penumbra-zone/jmt", commit = "46b4b00" }
theochap marked this conversation as resolved.
Show resolved Hide resolved

# External dependencies
async-trait = "0.1.71"
Expand Down
11 changes: 10 additions & 1 deletion adapters/celestia/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use base64::Engine;
use borsh::{BorshDeserialize, BorshSerialize};
pub use nmt_rs::NamespaceId;
use serde::{Deserialize, Serialize};
use sov_rollup_interface::da::BlockHeaderTrait;
use sov_rollup_interface::services::da::SlotData;
use sov_rollup_interface::Bytes;
use tendermint::crypto::default::Sha256;
Expand All @@ -14,7 +15,7 @@ use tendermint::merkle;
use crate::pfb::MsgPayForBlobs;
use crate::shares::{NamespaceGroup, Share};
use crate::utils::BoxError;
use crate::verifier::PARITY_SHARES_NAMESPACE;
use crate::verifier::{ChainValidityCondition, PARITY_SHARES_NAMESPACE};
use crate::{CelestiaHeader, TxPosition};

#[derive(Debug, PartialEq, Clone, Deserialize, Serialize)]
Expand Down Expand Up @@ -81,6 +82,7 @@ pub struct FilteredCelestiaBlock {

impl SlotData for FilteredCelestiaBlock {
type BlockHeader = CelestiaHeader;
type Condition = ChainValidityCondition;

fn hash(&self) -> [u8; 32] {
match self.header.header.hash() {
Expand All @@ -92,6 +94,13 @@ impl SlotData for FilteredCelestiaBlock {
fn header(&self) -> &Self::BlockHeader {
&self.header
}

fn validity_condition(&self) -> ChainValidityCondition {
ChainValidityCondition {
prev_hash: *self.header().prev_hash().inner(),
block_hash: self.hash(),
}
}
}

impl FilteredCelestiaBlock {
Expand Down
20 changes: 16 additions & 4 deletions adapters/celestia/src/verifier/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use borsh::{BorshDeserialize, BorshSerialize};
use nmt_rs::NamespaceId;
use serde::{Deserialize, Serialize};
use sov_rollup_interface::da::{
Expand Down Expand Up @@ -97,14 +98,27 @@ impl DaSpec for CelestiaSpec {
type CompletenessProof = Vec<RelevantRowProof>;

type ChainParams = RollupParams;

type ValidityCondition = ChainValidityCondition;
}

#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct RollupParams {
pub namespace: NamespaceId,
}

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Hash)]
#[derive(
Debug,
Clone,
Copy,
PartialEq,
Eq,
Serialize,
Deserialize,
Hash,
BorshDeserialize,
BorshSerialize,
)]
/// A validity condition expressing that a chain of DA layer blocks is contiguous and canonical
pub struct ChainValidityCondition {
pub prev_hash: [u8; 32],
Expand All @@ -131,8 +145,6 @@ impl da::DaVerifier for CelestiaVerifier {

type Error = ValidationError;

type ValidityCondition = ChainValidityCondition;

fn new(params: <Self::Spec as DaSpec>::ChainParams) -> Self {
Self {
rollup_namespace: params.namespace,
Expand All @@ -145,7 +157,7 @@ impl da::DaVerifier for CelestiaVerifier {
txs: &[<Self::Spec as DaSpec>::BlobTransaction],
inclusion_proof: <Self::Spec as DaSpec>::InclusionMultiProof,
completeness_proof: <Self::Spec as DaSpec>::CompletenessProof,
) -> Result<Self::ValidityCondition, Self::Error> {
) -> Result<<Self::Spec as DaSpec>::ValidityCondition, Self::Error> {
// Validate that the provided DAH is well-formed
block_header.validate_dah()?;
let validity_condition = ChainValidityCondition {
Expand Down
16 changes: 14 additions & 2 deletions adapters/risc0/src/guest.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#[cfg(target_os = "zkvm")]
use risc0_zkvm::guest::env;
use sov_rollup_interface::zk::{Zkvm, ZkvmGuest};
use sov_rollup_interface::AddressTrait;

use crate::Risc0MethodId;

Expand Down Expand Up @@ -37,7 +38,18 @@ impl Zkvm for Risc0Guest {
_serialized_proof: &'a [u8],
_code_commitment: &Self::CodeCommitment,
) -> Result<&'a [u8], Self::Error> {
// Implement this method once risc0 supports recursion
todo!()
// Implement this method once risc0 supports recursion: issue #633
todo!("Implement once risc0 supports recursion")
theochap marked this conversation as resolved.
Show resolved Hide resolved
}

fn verify_and_extract_output<
C: sov_rollup_interface::zk::ValidityCondition,
Add: AddressTrait,
>(
_serialized_proof: &[u8],
_code_commitment: &Self::CodeCommitment,
) -> Result<sov_rollup_interface::zk::StateTransition<C, Add>, Self::Error> {
// Implement this method once risc0 supports recursion: issue https://github.com/Sovereign-Labs/sovereign-sdk/issues/633
todo!("Implement once risc0 supports recursion")
theochap marked this conversation as resolved.
Show resolved Hide resolved
theochap marked this conversation as resolved.
Show resolved Hide resolved
}
}
23 changes: 23 additions & 0 deletions adapters/risc0/src/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use risc0_zkvm::{
Executor, ExecutorEnvBuilder, LocalExecutor, SegmentReceipt, Session, SessionReceipt,
};
use sov_rollup_interface::zk::{Zkvm, ZkvmHost};
use sov_rollup_interface::AddressTrait;

use crate::Risc0MethodId;

Expand Down Expand Up @@ -55,6 +56,16 @@ impl<'prover> Zkvm for Risc0Host<'prover> {
) -> Result<&'a [u8], Self::Error> {
verify_from_slice(serialized_proof, code_commitment)
}

fn verify_and_extract_output<
C: sov_rollup_interface::zk::ValidityCondition,
Add: AddressTrait,
>(
_serialized_proof: &[u8],
_code_commitment: &Self::CodeCommitment,
) -> Result<sov_rollup_interface::zk::StateTransition<C, Add>, Self::Error> {
todo!("Implement once risc0 supports recursion, issue #633")
theochap marked this conversation as resolved.
Show resolved Hide resolved
}
}

pub struct Risc0Verifier;
Expand All @@ -70,6 +81,18 @@ impl Zkvm for Risc0Verifier {
) -> Result<&'a [u8], Self::Error> {
verify_from_slice(serialized_proof, code_commitment)
}

fn verify_and_extract_output<
C: sov_rollup_interface::zk::ValidityCondition,
Add: AddressTrait,
>(
_serialized_proof: &[u8],
_code_commitment: &Self::CodeCommitment,
) -> Result<sov_rollup_interface::zk::StateTransition<C, Add>, Self::Error> {
// Method to implement: not clear how to deserialize the proof output.
// Issue https://github.com/Sovereign-Labs/sovereign-sdk/issues/621
todo!("not clear how to deserialize the proof output. Issue https://github.com/Sovereign-Labs/sovereign-sdk/issues/621")
}
}

fn verify_from_slice<'a>(
Expand Down
1 change: 1 addition & 0 deletions examples/demo-nft-module/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ sov-state = { path = "../../module-system/sov-state", default-features = false }

[dev-dependencies]
sov-rollup-interface = { path = "../../rollup-interface" }
sov-data-generators = { path = "../../module-system/utils/sov-data-generators" }
tempfile = { workspace = true }


Expand Down
23 changes: 10 additions & 13 deletions examples/demo-nft-module/tests/nft_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use demo_nft_module::call::CallMessage;
use demo_nft_module::query::OwnerResponse;
use demo_nft_module::{NonFungibleToken, NonFungibleTokenConfig};
use sov_modules_api::default_context::DefaultContext;
use sov_modules_api::test_utils::generate_address as gen_addr_generic;
use sov_modules_api::utils::generate_address as gen_addr_generic;
use sov_modules_api::{Address, Context, Module};
use sov_rollup_interface::stf::Event;
use sov_state::{DefaultStorageSpec, ProverStorage, WorkingSet};
Expand All @@ -21,7 +21,7 @@ fn genesis_and_mint() {
let owner2 = generate_address("owner2");
let config: NonFungibleTokenConfig<C> = NonFungibleTokenConfig {
admin,
owners: vec![(0, owner1.clone())],
owners: vec![(0, owner1)],
};

let tmpdir = tempfile::tempdir().unwrap();
Expand All @@ -40,7 +40,7 @@ fn genesis_and_mint() {

// Mint, anybody can mint
let mint_message = CallMessage::Mint { id: 1 };
let owner2_context = C::new(owner2.clone());
let owner2_context = C::new(owner2);
nft.call(mint_message.clone(), &owner2_context, &mut working_set)
.expect("Minting failed");

Expand All @@ -63,23 +63,20 @@ fn genesis_and_mint() {
fn transfer() {
// Preparation
let admin = generate_address("admin");
let admin_context = C::new(admin.clone());
let admin_context = C::new(admin);
let owner1 = generate_address("owner2");
let owner1_context = C::new(owner1.clone());
let owner1_context = C::new(owner1);
let owner2 = generate_address("owner2");
let config: NonFungibleTokenConfig<C> = NonFungibleTokenConfig {
admin: admin.clone(),
owners: vec![(0, admin.clone()), (1, owner1.clone()), (2, owner2.clone())],
admin,
owners: vec![(0, admin), (1, owner1), (2, owner2)],
};
let tmpdir = tempfile::tempdir().unwrap();
let mut working_set = WorkingSet::new(ProverStorage::with_path(tmpdir.path()).unwrap());
let nft = NonFungibleToken::default();
nft.genesis(&config, &mut working_set).unwrap();

let transfer_message = CallMessage::Transfer {
id: 1,
to: owner2.clone(),
};
let transfer_message = CallMessage::Transfer { id: 1, to: owner2 };

// admin cannot transfer token of the owner1
let transfer_attempt = nft.call(transfer_message.clone(), &admin_context, &mut working_set);
Expand Down Expand Up @@ -122,9 +119,9 @@ fn transfer() {
fn burn() {
// Preparation
let admin = generate_address("admin");
let admin_context = C::new(admin.clone());
let admin_context = C::new(admin);
let owner1 = generate_address("owner2");
let owner1_context = C::new(owner1.clone());
let owner1_context = C::new(owner1);
let config: NonFungibleTokenConfig<C> = NonFungibleTokenConfig {
admin,
owners: vec![(0, owner1)],
Expand Down
Loading