Skip to content
This repository was archived by the owner on Jul 28, 2025. It is now read-only.

Commit c8e91e8

Browse files
authored
Merge pull request #10 from axialabsresearch/v0.1.0-core-protocol-refactoring
V0.1.0 core protocol refactoring
2 parents 5cdd8d5 + fdcc8a6 commit c8e91e8

File tree

13 files changed

+440
-94
lines changed

13 files changed

+440
-94
lines changed

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121
uses: actions-rs/cargo@v1
2222
with:
2323
command: test
24-
args: --all-features
24+
args: --all-features --lib --bins --tests --benches
2525

2626
- name: Check formatting
2727
uses: actions-rs/cargo@v1

src/error.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ The error system implements several key components:
4444
4545
1. **Core Error Type**
4646
```rust
47+
use frost_protocol::finality::FinalityError;
4748
pub enum Error {
4849
Message(String),
4950
State(String),

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,5 +265,5 @@ pub use routing::MessageRouter;
265265
pub type Result<T> = std::result::Result<T, Error>;
266266
pub use error::Error;
267267

268-
mod error;
268+
pub mod error;
269269

src/state/error.rs

Lines changed: 53 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -41,36 +41,60 @@ The error system implements several key components:
4141
4242
1. **Error Severity**
4343
```rust
44+
use frost_protocol::state::error::ErrorSeverity;
45+
4446
pub enum ErrorSeverity {
4547
Warning,
4648
Error,
4749
Critical,
4850
}
51+
52+
// Example usage:
53+
# fn main() {
54+
let severity = ErrorSeverity::Warning;
55+
assert!(severity < ErrorSeverity::Error);
56+
assert!(severity < ErrorSeverity::Critical);
57+
# }
4958
```
50-
- Severity levels
51-
- Comparison logic
52-
- Recovery guidance
53-
- Operation handling
5459
5560
2. **State Errors**
5661
```rust
62+
use frost_protocol::state::{error::StateError, BlockRef, ChainId};
63+
5764
pub enum StateError {
5865
InvalidTransition(String),
5966
InvalidProof(String),
6067
ProofVerificationFailed(String),
6168
InvalidBlockRef(String),
62-
RootMismatch { ... },
69+
RootMismatch {
70+
block_ref: BlockRef,
71+
expected: String,
72+
actual: String,
73+
},
6374
ChainSpecific(String),
6475
Internal(String),
6576
}
77+
78+
// Example usage:
79+
# fn main() {
80+
let block_ref = BlockRef::new(
81+
ChainId::new("ethereum"),
82+
1000,
83+
[0; 32]
84+
);
85+
let error = StateError::RootMismatch {
86+
block_ref,
87+
expected: "0x123...".to_string(),
88+
actual: "0x456...".to_string(),
89+
};
90+
# }
6691
```
67-
- Error types
68-
- Error messages
69-
- Error context
70-
- Recovery options
7192
7293
3. **Proof Errors**
7394
```rust
95+
use frost_protocol::state::error::{ProofError, ProofErrorCategory, ErrorSeverity, ChainErrorContext, RetryGuidance};
96+
use std::time::Duration;
97+
7498
pub struct ProofError {
7599
category: ProofErrorCategory,
76100
severity: ErrorSeverity,
@@ -79,11 +103,27 @@ The error system implements several key components:
79103
retry: RetryGuidance,
80104
cause: Option<Box<ProofError>>,
81105
}
106+
107+
// Example usage:
108+
# fn main() {
109+
let error = ProofError::new(
110+
ProofErrorCategory::Validation,
111+
ErrorSeverity::Error,
112+
"Invalid proof format"
113+
)
114+
.with_context(ChainErrorContext {
115+
chain_id: "ethereum".to_string(),
116+
block_number: 1000,
117+
metadata: None,
118+
})
119+
.with_retry(RetryGuidance {
120+
retryable: true,
121+
retry_after: Some(Duration::from_secs(60)),
122+
max_retries: Some(3),
123+
alternatives: vec!["Try different proof type".to_string()],
124+
});
125+
# }
82126
```
83-
- Error categorization
84-
- Severity tracking
85-
- Context management
86-
- Retry handling
87127
88128
## Features
89129

src/state/mod.rs

Lines changed: 67 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,26 @@ The state system consists of several key components:
4040
4141
1. **State Transition**
4242
```rust
43+
use frost_protocol::state::{BlockId, StateTransition};
44+
4345
pub struct StateTransition {
4446
source: BlockId,
4547
target: BlockId,
4648
state_data: Vec<u8>,
4749
}
50+
51+
// Example usage:
52+
# fn main() {
53+
let source = BlockId::Number(1000);
54+
let target = BlockId::Number(1001);
55+
let data = vec![1, 2, 3];
56+
let transition = StateTransition::new(
57+
frost_protocol::state::ChainId::new("ethereum"),
58+
source,
59+
target,
60+
data
61+
);
62+
# }
4863
```
4964
- State changes
5065
- Transition validation
@@ -53,10 +68,32 @@ The state system consists of several key components:
5368
5469
2. **State Proof**
5570
```rust
71+
use frost_protocol::state::{StateTransition, StateProof, proof::ProofData};
72+
use std::time::SystemTime;
73+
5674
pub struct StateProof {
5775
transition: StateTransition,
5876
proof: ProofData,
5977
}
78+
79+
// Example usage:
80+
# fn main() {
81+
let transition = StateTransition::new(
82+
frost_protocol::state::ChainId::new("ethereum"),
83+
BlockId::Number(1000),
84+
BlockId::Number(1001),
85+
vec![1, 2, 3]
86+
);
87+
let proof_data = ProofData {
88+
proof_type: frost_protocol::state::proof::ProofType::Basic,
89+
data: vec![1, 2, 3],
90+
metadata: None,
91+
generated_at: SystemTime::now(),
92+
expires_at: None,
93+
version: 1,
94+
};
95+
let proof = StateProof::new(transition, proof_data);
96+
# }
6097
```
6198
- Proof generation
6299
- Verification
@@ -65,11 +102,23 @@ The state system consists of several key components:
65102
66103
3. **State Types**
67104
```rust
105+
use frost_protocol::state::BlockId;
106+
68107
pub enum BlockId {
69108
Hash([u8; 32]),
70109
Number(u64),
71110
Composite { number: u64, hash: [u8; 32] },
72111
}
112+
113+
// Example usage:
114+
# fn main() {
115+
let block_by_number = BlockId::Number(1000);
116+
let block_by_hash = BlockId::Hash([0; 32]);
117+
let block_composite = BlockId::Composite {
118+
number: 1000,
119+
hash: [0; 32],
120+
};
121+
# }
73122
```
74123
- Block identification
75124
- Chain references
@@ -207,26 +256,38 @@ mod tests {
207256

208257
#[test]
209258
fn test_state_transition_validation() {
259+
let chain_id = ChainId::new("test-chain");
210260
let source = BlockId::Composite {
211261
number: 1,
212-
hash: [0; 32],
262+
hash: [0; 32], // Source hash all zeros
213263
};
214264
let target = BlockId::Composite {
215-
number: 1,
216-
hash: [0; 32],
265+
number: 2,
266+
hash: [1; 32], // Target hash all ones
217267
};
218268

219269
let transition = StateTransition::new(
270+
chain_id.clone(),
220271
source,
221272
target,
222273
vec![1, 2, 3],
223274
);
224275
assert!(transition.validate());
225276

277+
// Create invalid transition with same hash (will fail validation)
278+
let invalid_source = BlockId::Composite {
279+
number: 1,
280+
hash: [0; 32],
281+
};
282+
let invalid_target = BlockId::Composite {
283+
number: 2, // Valid height difference
284+
hash: [0; 32], // Same hash as source - should fail validation
285+
};
226286
let invalid_transition = StateTransition::new(
227-
BlockId::Number(0),
228-
BlockId::Number(0),
229-
vec![],
287+
chain_id,
288+
invalid_source,
289+
invalid_target,
290+
vec![1], // Valid data
230291
);
231292
assert!(!invalid_transition.validate());
232293
}

src/state/proof.rs

Lines changed: 82 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ The proof system implements several key components:
4141
4242
1. **Proof Data**
4343
```rust
44+
use frost_protocol::state::proof::{ProofData, ProofType};
45+
use std::time::SystemTime;
46+
use serde_json::json;
47+
4448
pub struct ProofData {
4549
pub proof_type: ProofType,
4650
pub data: Vec<u8>,
@@ -49,37 +53,103 @@ The proof system implements several key components:
4953
pub expires_at: Option<SystemTime>,
5054
pub version: u32,
5155
}
56+
57+
// Example usage:
58+
# fn main() {
59+
let proof_data = ProofData {
60+
proof_type: ProofType::Basic,
61+
data: vec![1, 2, 3],
62+
metadata: Some(json!({
63+
"chain": "ethereum",
64+
"block": 1000
65+
})),
66+
generated_at: SystemTime::now(),
67+
expires_at: None,
68+
version: 1,
69+
};
70+
# }
5271
```
53-
- Proof content
54-
- Metadata handling
55-
- Time tracking
56-
- Version control
5772
5873
2. **State Proof**
5974
```rust
75+
use frost_protocol::state::{
76+
proof::{StateProof, ProofData, ProofType, VerificationResult},
77+
StateTransition,
78+
ChainId,
79+
BlockId,
80+
};
81+
use std::time::SystemTime;
82+
6083
pub struct StateProof {
6184
pub transition: StateTransition,
6285
pub proof: ProofData,
6386
pub verification_history: Vec<VerificationResult>,
6487
}
88+
89+
// Example usage:
90+
# fn main() {
91+
let transition = StateTransition::new(
92+
ChainId::new("ethereum"),
93+
BlockId::Number(1000),
94+
BlockId::Number(1001),
95+
vec![1, 2, 3],
96+
);
97+
98+
let proof_data = ProofData {
99+
proof_type: ProofType::Basic,
100+
data: vec![1, 2, 3],
101+
metadata: None,
102+
generated_at: SystemTime::now(),
103+
expires_at: None,
104+
version: 1,
105+
};
106+
107+
let proof = StateProof::new(transition, proof_data);
108+
# }
65109
```
66-
- Transition binding
67-
- Proof storage
68-
- History tracking
69-
- Result management
70110
71111
3. **Proof Registry**
72112
```rust
113+
use frost_protocol::state::proof::{ProofRegistry, ProofType, VerificationResult};
114+
use dashmap::DashMap;
115+
use std::sync::Arc;
116+
73117
pub struct ProofRegistry {
74118
generators: DashMap<ProofType, Arc<dyn ProofGenerator>>,
75119
verifiers: DashMap<ProofType, Arc<dyn ProofVerifier>>,
76120
verification_cache: DashMap<String, VerificationResult>,
77121
}
122+
123+
// Example usage:
124+
# fn main() {
125+
let registry = ProofRegistry::new();
126+
127+
// Register a custom generator
128+
struct BasicGenerator;
129+
impl ProofGenerator for BasicGenerator {
130+
fn proof_type(&self) -> ProofType {
131+
ProofType::Basic
132+
}
133+
134+
async fn generate_proof(
135+
&self,
136+
transition: &StateTransition,
137+
_context: Option<&serde_json::Value>,
138+
) -> Result<ProofData, StateError> {
139+
Ok(ProofData {
140+
proof_type: ProofType::Basic,
141+
data: vec![1, 2, 3],
142+
metadata: None,
143+
generated_at: SystemTime::now(),
144+
expires_at: None,
145+
version: 1,
146+
})
147+
}
148+
}
149+
150+
registry.register_generator(Arc::new(BasicGenerator));
151+
# }
78152
```
79-
- Generator management
80-
- Verifier management
81-
- Cache handling
82-
- Concurrent access
83153
84154
## Features
85155

0 commit comments

Comments
 (0)