Skip to content

Commit f28978e

Browse files
committed
Prepare to receive more public inputs
1 parent be87664 commit f28978e

3 files changed

Lines changed: 23 additions & 8 deletions

File tree

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

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
use base64::prelude::*;
22
use log::{debug, warn};
33

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;
7+
48
pub fn verify_protocol_state_proof_integrity(proof: &[u8], public_input: &[u8]) -> bool {
59
debug!("Checking Mina protocol state proof");
610
if let Err(err) = check_protocol_state_proof(proof) {
@@ -30,10 +34,21 @@ pub fn check_protocol_state_proof(protocol_state_proof_bytes: &[u8]) -> Result<(
3034

3135
pub fn check_protocol_state_pub(protocol_state_pub: &[u8]) -> Result<(), String> {
3236
// TODO(xqft): check hash and binprot deserialization
33-
let protocol_state_base64 =
34-
std::str::from_utf8(&protocol_state_pub[32..]).map_err(|err| err.to_string())?;
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())?;
44+
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)],
48+
)
49+
.map_err(|err| err.to_string())?;
3550
BASE64_STANDARD
36-
.decode(protocol_state_base64)
51+
.decode(tip_protocol_state_base64)
3752
.map_err(|err| err.to_string())?;
3853

3954
Ok(())

operator/mina/lib/src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ lazy_static! {
2323

2424
// TODO(xqft): check proof size
2525
const MAX_PROOF_SIZE: usize = 16 * 1024;
26-
const MAX_PUB_INPUT_SIZE: usize = 3 * 1024;
26+
const MAX_PUB_INPUT_SIZE: usize = 6 * 1024;
2727
const PROTOCOL_STATE_HASH_SIZE: usize = 32;
2828
// TODO(gabrielbosio): check that this length is always the same for every block
2929
const PROTOCOL_STATE_SIZE: usize = 2060;
@@ -44,10 +44,10 @@ pub extern "C" fn verify_protocol_state_proof_ffi(
4444
};
4545

4646
let (
47-
tip_protocol_state_hash,
48-
tip_protocol_state,
4947
candidate_protocol_state_hash,
5048
candidate_protocol_state,
49+
tip_protocol_state_hash,
50+
tip_protocol_state,
5151
) = match parse_protocol_state_pub(&public_input_bytes[..public_input_len]) {
5252
Ok(protocol_state_pub) => protocol_state_pub,
5353
Err(err) => {
@@ -73,7 +73,7 @@ pub extern "C" fn verify_protocol_state_proof_ffi(
7373

7474
if !verify_block(
7575
&protocol_state_proof,
76-
tip_protocol_state_hash,
76+
candidate_protocol_state_hash,
7777
&VERIFIER_INDEX,
7878
&srs,
7979
) {

operator/mina/mina.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313

1414
// TODO(xqft): check proof size
1515
const MAX_PROOF_SIZE = 16 * 1024
16-
const MAX_PUB_INPUT_SIZE = 3 * 1024
16+
const MAX_PUB_INPUT_SIZE = 6 * 1024
1717

1818
func VerifyProtocolStateProof(proofBuffer [MAX_PROOF_SIZE]byte, proofLen uint, pubInputBuffer [MAX_PUB_INPUT_SIZE]byte, pubInputLen uint) bool {
1919
proofPtr := (*C.uchar)(unsafe.Pointer(&proofBuffer[0]))

0 commit comments

Comments
 (0)