Skip to content

Commit

Permalink
Optimistic (#650)
Browse files Browse the repository at this point in the history
* Optimistic

* Attester incentives module

* Reverting typo

* Tests attester-incentives

* Adding test helper and lint

* Lint

* Adding tests

* Finishing positive test

* Refactor tests

* Refactor tests

* Adding negative test

* Valid challenge

* Invalid challenge

* Adding unbonding tests

* Lint fix

* Lint

* Make lint

* Make lint

* PR comments + fix tests

* Lint

* Fixing comments

* Refactoring + finishing adding tests

* Fix lint

* Fix lint

* Fixing PR comments

* Fixing important comment

* Fix nits

* Fixing multi-attestation

* Fixing nits

* Fixing nits

* Fixing lints

* Fixing all comments PR
  • Loading branch information
theochap authored and neysofu committed Aug 23, 2023
1 parent 0741530 commit d2dfc1c
Show file tree
Hide file tree
Showing 37 changed files with 2,597 additions and 131 deletions.
20 changes: 20 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ members = [
"module-system/module-implementations/sov-blob-storage",
"module-system/module-implementations/sov-evm",
"module-system/module-implementations/sov-prover-incentives",
"module-system/module-implementations/sov-attester-incentives",
"module-system/module-implementations/sov-sequencer-registry",
"module-system/module-implementations/module-template",
"module-system/module-implementations/examples/sov-value-setter",
Expand Down
12 changes: 0 additions & 12 deletions adapters/risc0/src/guest.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#[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 @@ -41,15 +40,4 @@ impl Zkvm for Risc0Guest {
// Implement this method once risc0 supports recursion: issue #633
todo!("Implement once risc0 supports recursion: https://github.com/Sovereign-Labs/sovereign-sdk/issues/633")
}

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: https://github.com/Sovereign-Labs/sovereign-sdk/issues/633")
}
}
23 changes: 0 additions & 23 deletions adapters/risc0/src/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use risc0_zkvm::{
Executor, ExecutorEnvBuilder, LocalExecutor, SegmentReceipt, Session, SessionReceipt,
};
use sov_rollup_interface::zk::{Zkvm, ZkvmHost};
use sov_rollup_interface::AddressTrait;
#[cfg(feature = "bench")]
use zk_cycle_utils::{cycle_count_callback, get_syscall_name, get_syscall_name_cycles};

Expand Down Expand Up @@ -79,16 +78,6 @@ 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 https://github.com/Sovereign-Labs/sovereign-sdk/issues/633")
}
}

pub struct Risc0Verifier;
Expand All @@ -104,18 +93,6 @@ 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
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ fn test_simple_value_setter_with_chain_state() {
let mut working_set = get_working_set(&app_template);

// Check the slot height before apply slot
let new_height_storage: u64 = app_template
let new_height_storage = app_template
.runtime
.chain_state
.get_slot_height(&mut working_set);
Expand Down Expand Up @@ -92,7 +92,7 @@ fn test_simple_value_setter_with_chain_state() {
assert_eq!(stored_root, init_root_hash.0, "Root hashes don't match");

// Check the slot height
let new_height_storage: u64 = chain_state_ref.get_slot_height(&mut working_set);
let new_height_storage = chain_state_ref.get_slot_height(&mut working_set);

assert_eq!(new_height_storage, 1, "The new height did not update");

Expand Down Expand Up @@ -139,7 +139,7 @@ fn test_simple_value_setter_with_chain_state() {
assert_eq!(stored_root, init_root_hash.0, "Root hashes don't match");

// Check the slot height
let new_height_storage: u64 = chain_state_ref.get_slot_height(&mut working_set);
let new_height_storage = chain_state_ref.get_slot_height(&mut working_set);
assert_eq!(new_height_storage, 2, "The new height did not update");

// Check the tx in progress
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
[package]
name = "sov-attester-incentives"
description = "A Sovereign SDK module for incentivizing provers"
authors = { workspace = true }
edition = { workspace = true }
homepage = { workspace = true }
license = { workspace = true }
repository = { workspace = true }
rust-version = { workspace = true }
version = { workspace = true }
readme = "README.md"
resolver = "2"

[dev-dependencies]
sov-rollup-interface = { path = "../../../rollup-interface", version = "0.1", features = ["mocks"] }
sov-modules-api = { path = "../../sov-modules-api", version = "0.1" }
tempfile = { workspace = true }

[dependencies]
anyhow = { workspace = true }
sov-bank = { path = "../sov-bank", version = "0.1", default-features = false }
sov-chain-state = { path = "../sov-chain-state", version = "0.1", default-features = false }
sov-modules-api = { path = "../../sov-modules-api", version = "0.1", default-features = false }
sov-modules-macros = { path = "../../sov-modules-macros", version = "0.1" }
sov-state = { path = "../../sov-state", version = "0.1", default-features = false }
sov-rollup-interface = { path = "../../../rollup-interface", version = "0.1" }
serde = { workspace = true }
serde_json = { workspace = true, optional = true }
thiserror = { workspace = true }
jmt = { workspace = true }
borsh = { workspace = true, features = ["rc"] }


[features]
default = ["native"]
serde = ["dep:serde_json"]
native = ["serde", "sov-modules-api/native"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Attester Incentive module

**_This module is a placeholder for the logic incentivizing attesters and challengers. This is the full node implementation of the optimistic rollup workflow_**

This module implements the logic for processing optimistic rollup attestations and challenges. Such
logic is necessary if you want to reward attesters/challengers or do anything else that's "aware" of attestation and challenge generation inside you state transition function.

This module now implements the complete attestion/challenge verification workflow, as well as the bonding and unbonding processes for attesters and challengers.
Loading

0 comments on commit d2dfc1c

Please sign in to comment.