Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -335,24 +335,24 @@ batcher_send_mina_task:
@echo "Sending Mina state task to Batcher..."
@cd batcher/aligned/ && cargo run --release -- submit \
--proving_system Mina \
--proof test_files/mina/protocol_state_proof.proof \
--public_input test_files/mina/protocol_state_hash.pub \
--proof test_files/mina/protocol_state.proof \
--public_input test_files/mina/protocol_state.pub \
--proof_generator_addr 0x66f9664f97F2b50F62D13eA064982f936dE76657

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

batcher_send_mina_burst:
@echo "Sending Mina state task to Batcher..."
@cd batcher/aligned/ && cargo run --release -- submit \
--proving_system Mina \
--proof test_files/mina/protocol_state_proof.proof \
--public_input test_files/mina/protocol_state_hash.pub \
--proof test_files/mina/protocol_state.proof \
--public_input test_files/mina/protocol_state.pub \
--repetitions 15 \
--proof_generator_addr 0x66f9664f97F2b50F62D13eA064982f936dE76657

Expand Down
63 changes: 32 additions & 31 deletions batcher/aligned-batcher/src/mina/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,56 +2,57 @@ use base64::prelude::*;
use log::{debug, warn};

pub fn verify_protocol_state_proof_integrity(proof: &[u8], public_input: &[u8]) -> bool {
debug!("Reading Mina protocol state proof base64");
let protocol_state_proof_base64 =
if let Ok(protocol_state_proof_base64) = std::str::from_utf8(proof) {
protocol_state_proof_base64
} else {
return false;
};
debug!("Reading Mina protocol state hash base58");
let protocol_state_hash_base58 =
if let Ok(protocol_state_hash_base58) = std::str::from_utf8(public_input) {
protocol_state_hash_base58
} else {
return false;
};

debug!("Decoding Mina protocol state proof base64");
if BASE64_URL_SAFE
.decode(protocol_state_proof_base64.trim_end())
.is_err()
{
warn!("Failed to decode Mina protocol state proof base64");
debug!("Checking Mina protocol state proof");
if let Err(err) = check_protocol_state_proof(proof) {
warn!("Protocol state proof check failed: {}", err);
return false;
}

debug!("Decoding Mina protocol state hash base58");
if bs58::decode(protocol_state_hash_base58.trim_end())
.into_vec()
.is_err()
{
warn!("Failed to decode Mina protocol state hash base58");
debug!("Checking Mina protocol state public inputs");
if let Err(err) = check_protocol_state_pub(public_input) {
warn!("Protocol state public inputs check failed: {}", err);
return false;
}

true
}

pub fn check_protocol_state_proof(protocol_state_proof_bytes: &[u8]) -> Result<(), String> {
// TODO(xqft): check binprot deserialization
let protocol_state_proof_base64 =
std::str::from_utf8(protocol_state_proof_bytes).map_err(|err| err.to_string())?;
BASE64_URL_SAFE
.decode(protocol_state_proof_base64)
.map_err(|err| err.to_string())?;

Ok(())
}

pub fn check_protocol_state_pub(protocol_state_pub: &[u8]) -> Result<(), String> {
// TODO(xqft): check hash and binprot deserialization
let protocol_state_base64 =
std::str::from_utf8(&protocol_state_pub[32..]).map_err(|err| err.to_string())?;
BASE64_STANDARD
.decode(protocol_state_base64)
.map_err(|err| err.to_string())?;

Ok(())
}

#[cfg(test)]
mod test {
use super::verify_protocol_state_proof_integrity;

const PROTOCOL_STATE_PROOF_BYTES: &[u8] =
include_bytes!("../../../../batcher/aligned/test_files/mina/protocol_state_proof.proof");
const PROTOCOL_STATE_HASH_BYTES: &[u8] =
include_bytes!("../../../../batcher/aligned/test_files/mina/protocol_state_hash.pub");
include_bytes!("../../../../batcher/aligned/test_files/mina/protocol_state.proof");
const PROTOCOL_STATE_PUB_BYTES: &[u8] =
include_bytes!("../../../../batcher/aligned/test_files/mina/protocol_state.pub");

#[test]
fn verify_protocol_state_proof_integrity_does_not_fail() {
assert!(verify_protocol_state_proof_integrity(
PROTOCOL_STATE_PROOF_BYTES,
PROTOCOL_STATE_HASH_BYTES,
PROTOCOL_STATE_PUB_BYTES,
));
}
}
2 changes: 1 addition & 1 deletion operator/mina/mina.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (

// TODO(xqft): check proof size
const MAX_PROOF_SIZE = 16 * 1024
const MAX_PUB_INPUT_SIZE = 1024
const MAX_PUB_INPUT_SIZE = 3 * 1024

func VerifyProtocolStateProof(proofBuffer [MAX_PROOF_SIZE]byte, proofLen uint, pubInputBuffer [MAX_PUB_INPUT_SIZE]byte, pubInputLen uint) bool {
proofPtr := (*C.uchar)(unsafe.Pointer(&proofBuffer[0]))
Expand Down
4 changes: 2 additions & 2 deletions operator/mina/mina_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

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

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