diff --git a/Makefile b/Makefile index fb2a89150b..ae82402543 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/batcher/aligned-batcher/src/mina/mod.rs b/batcher/aligned-batcher/src/mina/mod.rs index 9bffad6b7d..382b09cbab 100644 --- a/batcher/aligned-batcher/src/mina/mod.rs +++ b/batcher/aligned-batcher/src/mina/mod.rs @@ -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, )); } } diff --git a/operator/mina/mina.go b/operator/mina/mina.go index ee25b3e458..0fa124d0e9 100644 --- a/operator/mina/mina.go +++ b/operator/mina/mina.go @@ -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])) diff --git a/operator/mina/mina_test.go b/operator/mina/mina_test.go index b09d5dde08..697f7c005b 100644 --- a/operator/mina/mina_test.go +++ b/operator/mina/mina_test.go @@ -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") } @@ -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") }