Skip to content

Commit 1dcd2d9

Browse files
authored
Merge pull request #14 from lambdaclass/mina_flow
Fix Mina operator flow for proof of new node
2 parents 65ace03 + c18e513 commit 1dcd2d9

4 files changed

Lines changed: 41 additions & 40 deletions

File tree

Makefile

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -335,24 +335,24 @@ batcher_send_mina_task:
335335
@echo "Sending Mina state task to Batcher..."
336336
@cd batcher/aligned/ && cargo run --release -- submit \
337337
--proving_system Mina \
338-
--proof test_files/mina/protocol_state_proof.proof \
339-
--public_input test_files/mina/protocol_state_hash.pub \
338+
--proof test_files/mina/protocol_state.proof \
339+
--public_input test_files/mina/protocol_state.pub \
340340
--proof_generator_addr 0x66f9664f97F2b50F62D13eA064982f936dE76657
341341

342342
batcher_send_mina_task_bad:
343343
@echo "Sending Mina state task to Batcher..."
344344
@cd batcher/aligned/ && cargo run --release -- submit \
345345
--proving_system Mina \
346-
--proof test_files/mina/protocol_state_proof.proof \
347-
--public_input test_files/mina/bad_protocol_state_hash.pub \
346+
--proof test_files/mina/protocol_state.proof \
347+
--public_input test_files/mina/bad_protocol_state.pub \
348348
--proof_generator_addr 0x66f9664f97F2b50F62D13eA064982f936dE76657
349349

350350
batcher_send_mina_burst:
351351
@echo "Sending Mina state task to Batcher..."
352352
@cd batcher/aligned/ && cargo run --release -- submit \
353353
--proving_system Mina \
354-
--proof test_files/mina/protocol_state_proof.proof \
355-
--public_input test_files/mina/protocol_state_hash.pub \
354+
--proof test_files/mina/protocol_state.proof \
355+
--public_input test_files/mina/protocol_state.pub \
356356
--repetitions 15 \
357357
--proof_generator_addr 0x66f9664f97F2b50F62D13eA064982f936dE76657
358358

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

Lines changed: 32 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2,56 +2,57 @@ use base64::prelude::*;
22
use log::{debug, warn};
33

44
pub fn verify_protocol_state_proof_integrity(proof: &[u8], public_input: &[u8]) -> bool {
5-
debug!("Reading Mina protocol state proof base64");
6-
let protocol_state_proof_base64 =
7-
if let Ok(protocol_state_proof_base64) = std::str::from_utf8(proof) {
8-
protocol_state_proof_base64
9-
} else {
10-
return false;
11-
};
12-
debug!("Reading Mina protocol state hash base58");
13-
let protocol_state_hash_base58 =
14-
if let Ok(protocol_state_hash_base58) = std::str::from_utf8(public_input) {
15-
protocol_state_hash_base58
16-
} else {
17-
return false;
18-
};
19-
20-
debug!("Decoding Mina protocol state proof base64");
21-
if BASE64_URL_SAFE
22-
.decode(protocol_state_proof_base64.trim_end())
23-
.is_err()
24-
{
25-
warn!("Failed to decode Mina protocol state proof base64");
5+
debug!("Checking Mina protocol state proof");
6+
if let Err(err) = check_protocol_state_proof(proof) {
7+
warn!("Protocol state proof check failed: {}", err);
268
return false;
279
}
2810

29-
debug!("Decoding Mina protocol state hash base58");
30-
if bs58::decode(protocol_state_hash_base58.trim_end())
31-
.into_vec()
32-
.is_err()
33-
{
34-
warn!("Failed to decode Mina protocol state hash base58");
11+
debug!("Checking Mina protocol state public inputs");
12+
if let Err(err) = check_protocol_state_pub(public_input) {
13+
warn!("Protocol state public inputs check failed: {}", err);
3514
return false;
3615
}
3716

3817
true
3918
}
4019

20+
pub fn check_protocol_state_proof(protocol_state_proof_bytes: &[u8]) -> Result<(), String> {
21+
// TODO(xqft): check binprot deserialization
22+
let protocol_state_proof_base64 =
23+
std::str::from_utf8(protocol_state_proof_bytes).map_err(|err| err.to_string())?;
24+
BASE64_URL_SAFE
25+
.decode(protocol_state_proof_base64)
26+
.map_err(|err| err.to_string())?;
27+
28+
Ok(())
29+
}
30+
31+
pub fn check_protocol_state_pub(protocol_state_pub: &[u8]) -> Result<(), String> {
32+
// 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())?;
35+
BASE64_STANDARD
36+
.decode(protocol_state_base64)
37+
.map_err(|err| err.to_string())?;
38+
39+
Ok(())
40+
}
41+
4142
#[cfg(test)]
4243
mod test {
4344
use super::verify_protocol_state_proof_integrity;
4445

4546
const PROTOCOL_STATE_PROOF_BYTES: &[u8] =
46-
include_bytes!("../../../../batcher/aligned/test_files/mina/protocol_state_proof.proof");
47-
const PROTOCOL_STATE_HASH_BYTES: &[u8] =
48-
include_bytes!("../../../../batcher/aligned/test_files/mina/protocol_state_hash.pub");
47+
include_bytes!("../../../../batcher/aligned/test_files/mina/protocol_state.proof");
48+
const PROTOCOL_STATE_PUB_BYTES: &[u8] =
49+
include_bytes!("../../../../batcher/aligned/test_files/mina/protocol_state.pub");
4950

5051
#[test]
5152
fn verify_protocol_state_proof_integrity_does_not_fail() {
5253
assert!(verify_protocol_state_proof_integrity(
5354
PROTOCOL_STATE_PROOF_BYTES,
54-
PROTOCOL_STATE_HASH_BYTES,
55+
PROTOCOL_STATE_PUB_BYTES,
5556
));
5657
}
5758
}

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 = 1024
16+
const MAX_PUB_INPUT_SIZE = 3 * 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]))

operator/mina/mina_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010

1111
func TestMinaStateProofVerifies(t *testing.T) {
1212
fmt.Println(os.Getwd())
13-
proofFile, err := os.Open("../../batcher/aligned/test_files/mina/protocol_state_proof.proof")
13+
proofFile, err := os.Open("../../batcher/aligned/test_files/mina/protocol_state.proof")
1414
if err != nil {
1515
t.Errorf("could not open mina state proof file")
1616
}
@@ -21,7 +21,7 @@ func TestMinaStateProofVerifies(t *testing.T) {
2121
t.Errorf("could not read bytes from mina state proof file")
2222
}
2323

24-
pubInputFile, err := os.Open("../../batcher/aligned/test_files/mina/protocol_state_hash.pub")
24+
pubInputFile, err := os.Open("../../batcher/aligned/test_files/mina/protocol_state.pub")
2525
if err != nil {
2626
t.Errorf("could not open mina state hash file")
2727
}

0 commit comments

Comments
 (0)