Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
223 changes: 17 additions & 206 deletions Cargo.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,7 @@ ethexe-sdk = { path = "ethexe/sdk", default-features = false }
ethexe-service = { path = "ethexe/service", default-features = false }
ethexe-service-utils = { path = "ethexe/service/utils", default-features = false }
ethexe-consensus = { path = "ethexe/consensus", default-features = false }
ethexe-dkg-roast = { path = "ethexe/dkg-roast", default-features = false }
ethexe-ethereum = { path = "ethexe/ethereum", default-features = false }
ethexe-runtime-common = { path = "ethexe/runtime/common", default-features = false }
ethexe-prometheus = { path = "ethexe/prometheus", default-features = false }
Expand Down
1 change: 0 additions & 1 deletion common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ sp-runtime.workspace = true
frame-support.workspace = true
frame-system = { workspace = true, optional = true }
frame-benchmarking = { workspace = true, optional = true }
gear-workspace-hack.workspace = true

[target.'cfg(fuzz)'.dependencies]
fail = { workspace = true, features = [ "failpoints" ] }
Expand Down
1 change: 0 additions & 1 deletion common/codegen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,3 @@ proc-macro = true
[dependencies]
quote.workspace = true
syn.workspace = true
gear-workspace-hack.workspace = true
1 change: 0 additions & 1 deletion common/numerated/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ derive_more.workspace = true
scale-info = { workspace = true, features = ["derive"] }
log = { workspace = true, optional = true }
proptest = { workspace = true, optional = true }
gear-workspace-hack.workspace = true

[dev-dependencies]
proptest.workspace = true
Expand Down
1 change: 0 additions & 1 deletion core-backend/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ bytemuck = { workspace = true, features = ["const_zeroed"] }
log.workspace = true
derive_more.workspace = true
parity-scale-codec.workspace = true
gear-workspace-hack.workspace = true

[dev-dependencies]
parity-scale-codec.workspace = true
Expand Down
1 change: 0 additions & 1 deletion core-errors/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ scale-encode = { workspace = true, optional = true }
scale-decode = { workspace = true, optional = true }
serde = { workspace = true, features = ["derive"], optional = true }
thiserror.workspace = true
gear-workspace-hack.workspace = true

[features]
codec = ["parity-scale-codec", "scale-info", "scale-encode", "scale-decode"]
Expand Down
1 change: 0 additions & 1 deletion core-processor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ log.workspace = true
derive_more.workspace = true
actor-system-error.workspace = true
parity-scale-codec = { workspace = true, features = ["derive"] }
gear-workspace-hack.workspace = true

[dev-dependencies]
enum-iterator.workspace = true
Expand Down
1 change: 0 additions & 1 deletion core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ numerated.workspace = true
# Optional dependencies
serde = { workspace = true, features = ["derive"], optional = true }
impl-serde = { workspace = true, optional = true }
gear-workspace-hack.workspace = true

[package.metadata.cargo-shear]
ignored = ["impl-serde"]
Expand Down
1 change: 0 additions & 1 deletion ethexe/blob-loader/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ reqwest = { workspace = true, features = ["default-tls", "json"] }
futures.workspace = true
log.workspace = true
tokio = { workspace = true, features = ["rt-multi-thread", "fs"] }
gear-workspace-hack.workspace = true

[dev-dependencies]
gprimitives = { workspace = true, features = ["ethexe", "std"] }
Expand Down
1 change: 1 addition & 0 deletions ethexe/blob-loader/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,7 @@ mod tests {
.await
.unwrap()
.with_validators(vec![alice_address].try_into().unwrap())
.with_generated_verifiable_secret_sharing_commitment()
.deploy()
.await
.unwrap();
Expand Down
1 change: 0 additions & 1 deletion ethexe/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ tempfile.workspace = true
tokio = { workspace = true, features = ["macros", "rt-multi-thread"] }
toml.workspace = true
thiserror.workspace = true
gear-workspace-hack.workspace = true

[lints]
workspace = true
1 change: 0 additions & 1 deletion ethexe/common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ nonempty.workspace = true
# mock deps
itertools = { workspace = true, optional = true }
tap = { workspace = true, optional = true }
gear-workspace-hack.workspace = true

[dev-dependencies]
gprimitives = { workspace = true, features = ["ethexe"] }
Expand Down
140 changes: 139 additions & 1 deletion ethexe/common/src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
//! Common db types and traits.

use crate::{
Announce, BlockHeader, CodeBlobInfo, Digest, HashOf, ProgramStates, ProtocolTimelines,
Address, Announce, BlockHeader, CodeBlobInfo, Digest, HashOf, ProgramStates, ProtocolTimelines,
Schedule, SimpleBlockData, ValidatorsVec,
events::BlockEvent,
gear::StateTransition,
Expand Down Expand Up @@ -226,3 +226,141 @@ pub struct ComputedAnnounceData {
pub outcome: Vec<StateTransition>,
pub schedule: Schedule,
}

// DKG storage types

use crate::crypto::{
DkgComplaint, DkgIdentifier, DkgJustification, DkgKeyPackage, DkgPublicKeyPackage, DkgRound1,
DkgRound2, DkgRound2Culprits, DkgSessionId, DkgShare, DkgVssCommitment, PreNonceCommitment,
SignAggregate, SignNonceCommit, SignSessionRequest, SignShare,
};

/// DKG session state - stores all messages for a DKG session
#[derive(Debug, Clone, Default, Encode, Decode, PartialEq, Eq)]
pub struct DkgSessionState {
/// Address to identifier mapping for this DKG session
pub identifier_map: Vec<(Address, DkgIdentifier)>,
/// Round 1 commitments from all participants
pub round1_packages: Vec<DkgRound1>,
/// Round 2 packages from all participants
pub round2_packages: Vec<DkgRound2>,
/// Complaints reported during DKG
pub complaints: Vec<DkgComplaint>,
/// Justifications for reported complaints
pub justifications: Vec<DkgJustification>,
/// Culprits reported during round 2 verification
pub round2_culprits: Vec<DkgRound2Culprits>,
/// Whether DKG is completed successfully
pub completed: bool,
}

/// ROAST signing session state
#[derive(Debug, Clone, Default, Encode, Decode, PartialEq, Eq)]
pub struct SignSessionState {
/// The initial signing request
pub request: Option<SignSessionRequest>,
/// Nonce commitments from participants
pub nonce_commits: Vec<SignNonceCommit>,
/// Partial signatures from participants
pub sign_shares: Vec<SignShare>,
/// Final aggregated signature (if completed)
pub aggregate: Option<SignAggregate>,
/// Whether signing is completed successfully
pub completed: bool,
}

/// Read-only DKG storage operations
#[auto_impl::auto_impl(&, Box)]
pub trait DkgStorageRO {
/// Get DKG session state for a specific session
fn dkg_session_state(&self, session_id: DkgSessionId) -> Option<DkgSessionState>;

/// Get the final PublicKeyPackage for a completed DKG session
fn public_key_package(&self, era_index: u64) -> Option<DkgPublicKeyPackage>;

/// Get the KeyPackage (secret share) for a completed DKG session
fn dkg_key_package(&self, era_index: u64) -> Option<DkgKeyPackage>;

/// Get the DKG share details for a completed DKG session
fn dkg_share(&self, era_index: u64) -> Option<DkgShare>;

/// Get the aggregated VSS commitment for a completed DKG session
fn dkg_vss_commitment(&self, era_index: u64) -> Option<DkgVssCommitment>;

/// Check if DKG is completed for an era
fn dkg_completed(&self, era_index: u64) -> bool;
}

/// Read-write DKG storage operations
#[auto_impl::auto_impl(&)]
pub trait DkgStorageRW: DkgStorageRO {
/// Set DKG session state
fn set_dkg_session_state(&self, session_id: DkgSessionId, state: DkgSessionState);

/// Mutate DKG session state
fn mutate_dkg_session_state(
&self,
session_id: DkgSessionId,
f: impl FnOnce(&mut DkgSessionState),
);

/// Set the final PublicKeyPackage for an era
fn set_public_key_package(&self, era_index: u64, package: DkgPublicKeyPackage);

/// Set the KeyPackage (secret share) for an era
fn set_dkg_key_package(&self, era_index: u64, package: DkgKeyPackage);

/// Set the DKG share details for an era
fn set_dkg_share(&self, share: DkgShare);

/// Set the aggregated VSS commitment for an era
fn set_dkg_vss_commitment(&self, era_index: u64, commitment: DkgVssCommitment);
}

/// Read-only ROAST signing storage operations
#[auto_impl::auto_impl(&, Box)]
pub trait SignStorageRO {
/// Get signing session state by message hash and era
fn sign_session_state(&self, msg_hash: H256, era_index: u64) -> Option<SignSessionState>;

/// Get cached aggregate signature for era/target/message
fn signature_cache(
&self,
era_index: u64,
target: ActorId,
msg_hash: H256,
) -> Option<SignAggregate>;

/// Get cached pre-nonces for era/target.
fn pre_nonce_cache(&self, era_index: u64, target: ActorId) -> Option<Vec<PreNonceCommitment>>;

/// Check if signing is completed for a specific message
fn sign_completed(&self, msg_hash: H256, era_index: u64) -> bool;
}

/// Read-write ROAST signing storage operations
#[auto_impl::auto_impl(&)]
pub trait SignStorageRW: SignStorageRO {
/// Set signing session state
fn set_sign_session_state(&self, msg_hash: H256, era_index: u64, state: SignSessionState);

/// Cache aggregate signature for era/target/message
fn set_signature_cache(
&self,
era_index: u64,
target: ActorId,
msg_hash: H256,
aggregate: SignAggregate,
);

/// Store cached pre-nonces for era/target.
fn set_pre_nonce_cache(&self, era_index: u64, target: ActorId, cache: Vec<PreNonceCommitment>);

/// Mutate signing session state
fn mutate_sign_session_state(
&self,
msg_hash: H256,
era_index: u64,
f: impl FnOnce(&mut SignSessionState),
);
}
17 changes: 15 additions & 2 deletions ethexe/common/src/gear.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,13 +239,25 @@ impl ToDigest for ValidatorsCommitment {
fn update_hasher(&self, hasher: &mut sha3::Keccak256) {
let ValidatorsCommitment {
aggregated_public_key,
verifiable_secret_sharing_commitment: _, // TODO: add to digest
verifiable_secret_sharing_commitment,
validators,
era_index,
} = self;

// Include aggregated public key coordinates
hasher.update(<[u8; 32]>::from(aggregated_public_key.x));
hasher.update(<[u8; 32]>::from(aggregated_public_key.y));

// Include hash of VSS commitment
// This matches Solidity: keccak256(abi.encodePacked(..., keccak256(vss), ...))
let vss_bytes = verifiable_secret_sharing_commitment
.serialize()
.expect("VSS commitment serialization failed")
.concat();
let vss_hash = sha3::Keccak256::digest(&vss_bytes);
hasher.update(vss_hash);

// Include validators (each address as 32 bytes)
hasher.update(
validators
.iter()
Expand All @@ -258,6 +270,7 @@ impl ToDigest for ValidatorsCommitment {
.collect::<Vec<u8>>(),
);

// Include era index as U256 big-endian
let bytes = AlloyU256::from(*era_index).to_be_bytes::<32>();
hasher.update(bytes);
}
Expand Down Expand Up @@ -368,7 +381,7 @@ pub struct StateTransition {
/// and each zero byte costs 4 gas (see <https://evm.codes/about#gascosts>).
///
/// Negative numbers will be stored like this:
/// ```
/// ```text
/// $ cast
/// > -1 ether
/// Type: int256
Expand Down
2 changes: 2 additions & 0 deletions ethexe/common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
extern crate alloc;

pub mod consensus;
#[path = "../../dkg-roast/src/crypto/mod.rs"]
pub mod crypto;
pub mod db;
pub mod events;
pub mod gear;
Expand Down
Loading
Loading