Skip to content

Commit 4c49ddf

Browse files
committed
Revert "Add state size in pub input deserialization"
This reverts commit 43fb3c3.
1 parent 43fb3c3 commit 4c49ddf

2 files changed

Lines changed: 37 additions & 46 deletions

File tree

  • batcher/aligned-batcher/src/mina
  • operator/mina/lib/src

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

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
use base64::prelude::*;
22
use log::{debug, warn};
33

4-
const PROTOCOL_STATE_HASH_SIZE: usize = 32;
4+
const STATE_HASH_SIZE: usize = 32;
5+
// TODO(gabrielbosio): check that this length is always the same for every block
6+
const PROTOCOL_STATE_SIZE: usize = 2060;
57

68
pub fn verify_protocol_state_proof_integrity(proof: &[u8], public_input: &[u8]) -> bool {
79
debug!("Checking Mina protocol state proof");
@@ -31,31 +33,25 @@ pub fn check_protocol_state_proof(protocol_state_proof_bytes: &[u8]) -> Result<(
3133
}
3234

3335
pub fn check_protocol_state_pub(protocol_state_pub: &[u8]) -> Result<(), String> {
34-
let candidate_offset = parse_protocol_state_with_hash(&protocol_state_pub)?;
35-
36-
let _ = parse_protocol_state_with_hash(&protocol_state_pub[candidate_offset..])?;
37-
38-
Ok(())
39-
}
40-
41-
fn parse_protocol_state_with_hash(protocol_state_pub: &[u8]) -> Result<usize, String> {
4236
// TODO(xqft): check hash and binprot deserialization
43-
let mut protocol_state_size_bytes = [0u8; 4];
44-
protocol_state_size_bytes.copy_from_slice(
45-
&protocol_state_pub[PROTOCOL_STATE_HASH_SIZE..(PROTOCOL_STATE_HASH_SIZE + 4)],
46-
);
47-
let protocol_state_size = u32::from_be_bytes(protocol_state_size_bytes) as usize;
37+
let candidate_protocol_state_base64 = std::str::from_utf8(
38+
&protocol_state_pub[STATE_HASH_SIZE..(STATE_HASH_SIZE + PROTOCOL_STATE_SIZE)],
39+
)
40+
.map_err(|err| err.to_string())?;
41+
BASE64_STANDARD
42+
.decode(candidate_protocol_state_base64)
43+
.map_err(|err| err.to_string())?;
4844

49-
let protocol_state_base64 = std::str::from_utf8(
50-
&protocol_state_pub
51-
[(PROTOCOL_STATE_HASH_SIZE + 4)..(PROTOCOL_STATE_HASH_SIZE + 4 + protocol_state_size)],
45+
let tip_protocol_state_base64 = std::str::from_utf8(
46+
&protocol_state_pub[(STATE_HASH_SIZE + PROTOCOL_STATE_SIZE) + STATE_HASH_SIZE
47+
..((STATE_HASH_SIZE + PROTOCOL_STATE_SIZE) * 2)],
5248
)
5349
.map_err(|err| err.to_string())?;
5450
BASE64_STANDARD
55-
.decode(protocol_state_base64)
51+
.decode(tip_protocol_state_base64)
5652
.map_err(|err| err.to_string())?;
5753

58-
Ok(PROTOCOL_STATE_HASH_SIZE + 4 + protocol_state_size)
54+
Ok(())
5955
}
6056

6157
#[cfg(test)]

operator/mina/lib/src/lib.rs

Lines changed: 22 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ lazy_static! {
2525
const MAX_PROOF_SIZE: usize = 16 * 1024;
2626
const MAX_PUB_INPUT_SIZE: usize = 6 * 1024;
2727
const PROTOCOL_STATE_HASH_SIZE: usize = 32;
28+
// TODO(gabrielbosio): check that this length is always the same for every block
29+
const PROTOCOL_STATE_SIZE: usize = 2060;
2830

2931
#[no_mangle]
3032
pub extern "C" fn verify_protocol_state_proof_ffi(
@@ -108,13 +110,14 @@ pub fn parse_protocol_state_pub(
108110
),
109111
String,
110112
> {
111-
let (tip_protocol_state_hash, tip_protocol_state, candidate_offset) =
112-
parse_protocol_state_with_hash(&protocol_state_pub)?;
113+
let (tip_protocol_state_hash, tip_protocol_state) = parse_protocol_state_with_hash(
114+
&protocol_state_pub[..(PROTOCOL_STATE_HASH_SIZE + PROTOCOL_STATE_SIZE)],
115+
)?;
113116

114-
let (candidate_protocol_state_hash, candidate_protocol_state, protocol_state_pub_len) =
115-
parse_protocol_state_with_hash(&protocol_state_pub[candidate_offset..])?;
116-
117-
debug_assert_eq!(protocol_state_pub_len, protocol_state_pub.len());
117+
let (candidate_protocol_state_hash, candidate_protocol_state) = parse_protocol_state_with_hash(
118+
&protocol_state_pub[(PROTOCOL_STATE_HASH_SIZE + PROTOCOL_STATE_SIZE)
119+
..((PROTOCOL_STATE_HASH_SIZE + PROTOCOL_STATE_SIZE) * 2)],
120+
)?;
118121

119122
Ok((
120123
tip_protocol_state_hash,
@@ -126,33 +129,25 @@ pub fn parse_protocol_state_pub(
126129

127130
fn parse_protocol_state_with_hash(
128131
protocol_state_pub: &[u8],
129-
) -> Result<(Fp, MinaStateProtocolStateValueStableV2, usize), String> {
130-
let protocol_state_hash = Fp::from_bytes(&protocol_state_pub[..PROTOCOL_STATE_HASH_SIZE])
131-
.map_err(|err| err.to_string())?;
132-
133-
let mut protocol_state_size_bytes = [0u8; 4];
134-
protocol_state_size_bytes.copy_from_slice(
135-
&protocol_state_pub[PROTOCOL_STATE_HASH_SIZE..(PROTOCOL_STATE_HASH_SIZE + 4)],
136-
);
137-
let protocol_state_size = u32::from_be_bytes(protocol_state_size_bytes) as usize;
138-
139-
let protocol_state_base64 = std::str::from_utf8(
140-
&protocol_state_pub
141-
[(PROTOCOL_STATE_HASH_SIZE + 4)..(PROTOCOL_STATE_HASH_SIZE + 4 + protocol_state_size)],
142-
)
143-
.map_err(|err| err.to_string())?;
132+
) -> Result<
133+
(
134+
ark_ff::Fp256<mina_curves::pasta::fields::FpParameters>,
135+
MinaStateProtocolStateValueStableV2,
136+
),
137+
String,
138+
> {
139+
let protocol_state_hash =
140+
Fp::from_bytes(&protocol_state_pub[..32]).map_err(|err| err.to_string())?;
141+
let protocol_state_base64 =
142+
std::str::from_utf8(&protocol_state_pub[32..]).map_err(|err| err.to_string())?;
144143
let protocol_state_binprot = BASE64_STANDARD
145144
.decode(protocol_state_base64)
146145
.map_err(|err| err.to_string())?;
147146
let protocol_state =
148147
MinaStateProtocolStateValueStableV2::binprot_read(&mut protocol_state_binprot.as_slice())
149148
.map_err(|err| err.to_string())?;
150149

151-
Ok((
152-
protocol_state_hash,
153-
protocol_state,
154-
PROTOCOL_STATE_HASH_SIZE + 4 + protocol_state_size,
155-
))
150+
Ok((protocol_state_hash, protocol_state))
156151
}
157152

158153
#[cfg(test)]
@@ -164,7 +159,7 @@ mod test {
164159
const PROTOCOL_STATE_PUB_BYTES: &[u8] =
165160
include_bytes!("../../../../batcher/aligned/test_files/mina/protocol_state.pub");
166161
const BAD_PROTOCOL_STATE_PUB_BYTES: &[u8] =
167-
include_bytes!("../../../../batcher/aligned/test_files/mina/protocol_state_bad_hash.pub");
162+
include_bytes!("../../../../batcher/aligned/test_files/mina/bad_protocol_state.pub");
168163
// BAD_PROTOCOL_STATE_PUB_BYTES has an invalid hash.
169164

170165
#[test]

0 commit comments

Comments
 (0)