Skip to content

Commit a85d7f9

Browse files
authored
Merge pull request #22 from lambdaclass/relative_finalization
Relative finalization
2 parents ce5f842 + 0afb987 commit a85d7f9

File tree

14 files changed

+7617
-1788
lines changed

14 files changed

+7617
-1788
lines changed

batcher/Cargo.lock

Lines changed: 2151 additions & 486 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

batcher/Cargo.toml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
[workspace]
2-
members = [
3-
"aligned-batcher",
4-
"aligned-sdk",
5-
"aligned"
6-
]
2+
members = ["aligned-batcher", "aligned-sdk", "aligned"]
73
resolver = "2"
4+
5+
[patch.crates-io]
6+
ark-ff = { git = "https://github.com/openmina/algebra", branch = "openmina" }
7+
ark-ec = { git = "https://github.com/openmina/algebra", branch = "openmina" }
8+
ark-poly = { git = "https://github.com/openmina/algebra", branch = "openmina" }
9+
ark-serialize = { git = "https://github.com/openmina/algebra", branch = "openmina" }

batcher/aligned-batcher/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ edition = "2021"
55

66
[dependencies]
77
tokio-tungstenite = "0.21.0"
8+
mina_bridge_core = { git = "https://github.com/lambdaclass/mina_bridge.git", branch = "relative_finalization" }
89
futures-util = "0.3.30"
910
tokio = { version = "1.37.0", features = ["rt", "rt-multi-thread", "macros"] }
1011
log = "0.4.21"

batcher/aligned-batcher/src/mina/mod.rs

Lines changed: 7 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,86 +1,22 @@
1-
use std::array::TryFromSliceError;
2-
3-
use base64::prelude::*;
41
use log::{debug, warn};
5-
6-
const STATE_HASH_SIZE: usize = 32;
2+
use mina_bridge_core::proof::state_proof::{MinaStateProof, MinaStatePubInputs};
73

84
pub fn verify_proof_integrity(proof: &[u8], public_input: &[u8]) -> bool {
9-
debug!("Checking Mina protocol state proof");
10-
if let Err(err) = check_proof(proof) {
11-
warn!("Protocol state proof check failed: {}", err);
5+
debug!("Deserializing Mina Proof of State");
6+
if let Err(err) = bincode::deserialize::<MinaStateProof>(proof) {
7+
warn!("Couldn't deserialize Mina Proof of State: {err}");
128
return false;
139
}
1410

15-
debug!("Checking Mina protocol state public inputs");
16-
if let Err(err) = check_pub_inputs(public_input) {
17-
warn!("Protocol state public inputs check failed: {}", err);
11+
debug!("Deserializing Mina Proof of State public inputs");
12+
if let Err(err) = bincode::deserialize::<MinaStatePubInputs>(public_input) {
13+
warn!("Couldn't deserialize Mina Proof of State public inputs: {err}");
1814
return false;
1915
}
2016

2117
true
2218
}
2319

24-
pub fn check_hash(pub_inputs: &[u8], offset: &mut usize) -> Result<(), String> {
25-
pub_inputs
26-
.get(*offset..*offset + STATE_HASH_SIZE)
27-
.ok_or("Failed to slice candidate hash".to_string())?;
28-
29-
*offset += STATE_HASH_SIZE;
30-
31-
Ok(())
32-
}
33-
34-
pub fn check_state(pub_inputs: &[u8], offset: &mut usize) -> Result<(), String> {
35-
let state_len: usize = pub_inputs
36-
.get(*offset..*offset + 4)
37-
.ok_or("Failed to slice state len".to_string())
38-
.and_then(|slice| {
39-
slice
40-
.try_into()
41-
.map_err(|err: TryFromSliceError| err.to_string())
42-
})
43-
.map(u32::from_be_bytes)
44-
.and_then(|len| usize::try_from(len).map_err(|err| err.to_string()))?;
45-
46-
pub_inputs
47-
.get(*offset + 4..*offset + 4 + state_len)
48-
.ok_or("Failed to slice state".to_string())
49-
.and_then(|bytes| std::str::from_utf8(bytes).map_err(|err| err.to_string()))
50-
.and_then(|base64| {
51-
BASE64_STANDARD
52-
.decode(base64)
53-
.map_err(|err| err.to_string())
54-
})?;
55-
*offset += 4 + state_len;
56-
57-
Ok(())
58-
}
59-
60-
pub fn check_pub_inputs(pub_inputs: &[u8]) -> Result<(), String> {
61-
let mut offset = 0;
62-
63-
check_hash(pub_inputs, &mut offset)?; // candidate ledger hash
64-
check_hash(pub_inputs, &mut offset)?; // candidate state hash
65-
check_hash(pub_inputs, &mut offset)?; // tip hash
66-
67-
check_state(pub_inputs, &mut offset)?; // candidate state
68-
check_state(pub_inputs, &mut offset)?; // tip state
69-
70-
Ok(())
71-
}
72-
73-
pub fn check_proof(proof_bytes: &[u8]) -> Result<(), String> {
74-
std::str::from_utf8(proof_bytes)
75-
.map_err(|err| err.to_string())
76-
.and_then(|base64| {
77-
BASE64_URL_SAFE
78-
.decode(base64)
79-
.map_err(|err| err.to_string())
80-
})?;
81-
Ok(())
82-
}
83-
8420
#[cfg(test)]
8521
mod test {
8622
use super::verify_proof_integrity;
32.7 KB
Binary file not shown.
-3.09 KB
Binary file not shown.

0 commit comments

Comments
 (0)