From dbcb0d0ea0f5330593aa75404f58f07e01ce5b70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Est=C3=A9fano=20Bargas?= Date: Thu, 29 Aug 2024 17:17:36 -0300 Subject: [PATCH] Fix operator for new Mina proof --- operator/mina/lib/Cargo.lock | 80 +++++++++++++++---------------- operator/mina/lib/Cargo.toml | 2 +- operator/mina/lib/mina_verifier.h | 8 ++-- operator/mina/lib/src/lib.rs | 28 ++++------- operator/mina/mina.go | 6 +-- operator/mina/mina_test.go | 2 +- operator/pkg/operator.go | 4 +- 7 files changed, 61 insertions(+), 69 deletions(-) diff --git a/operator/mina/lib/Cargo.lock b/operator/mina/lib/Cargo.lock index 9cf878d3a..1d34207fa 100644 --- a/operator/mina/lib/Cargo.lock +++ b/operator/mina/lib/Cargo.lock @@ -1510,45 +1510,6 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6245d59a3e82a7fc217c5828a6692dbc6dfb63a0c8c90495621f7b9d79704a0e" -[[package]] -name = "core" -version = "0.1.0" -source = "git+https://github.com/lambdaclass/mina_bridge?branch=relative_finalization#fc75962e88fc23988ce3eb09d84f32db6d937b4f" -dependencies = [ - "aligned-sdk", - "alloy", - "ark-ec", - "ark-ff 0.3.0", - "ark-poly", - "ark-serialize 0.3.0", - "base64 0.22.1", - "bincode", - "clap", - "dotenv", - "env_logger", - "ethers", - "futures", - "graphql_client", - "hex", - "kimchi", - "log", - "mina-curves", - "mina-p2p-messages", - "mina-signer", - "mina-tree", - "num-bigint", - "o1-utils 0.1.0 (git+https://github.com/lambdaclass/proof-systems?branch=add-verifier-serializations)", - "poly-commitment", - "reqwest 0.11.27", - "rmp-serde", - "rpassword", - "serde", - "serde_json", - "serde_with 1.14.0", - "sha3", - "tokio", -] - [[package]] name = "core-foundation" version = "0.9.4" @@ -3556,13 +3517,13 @@ dependencies = [ "bincode", "blake2", "bs58 0.5.1", - "core", "hex", "kimchi", "lazy_static", "mina-curves", "mina-p2p-messages", "mina-tree", + "mina_bridge_core", "o1-utils 0.1.0 (git+https://github.com/lambdaclass/proof-systems?branch=add-verifier-serializations)", "once_cell", "poly-commitment", @@ -3622,6 +3583,45 @@ dependencies = [ "wasm_thread", ] +[[package]] +name = "mina_bridge_core" +version = "0.1.0" +source = "git+https://github.com/lambdaclass/mina_bridge?branch=relative_finalization#fd359911b8da3039972276c7872e457d45e26646" +dependencies = [ + "aligned-sdk", + "alloy", + "ark-ec", + "ark-ff 0.3.0", + "ark-poly", + "ark-serialize 0.3.0", + "base64 0.22.1", + "bincode", + "clap", + "dotenv", + "env_logger", + "ethers", + "futures", + "graphql_client", + "hex", + "kimchi", + "log", + "mina-curves", + "mina-p2p-messages", + "mina-signer", + "mina-tree", + "num-bigint", + "o1-utils 0.1.0 (git+https://github.com/lambdaclass/proof-systems?branch=add-verifier-serializations)", + "poly-commitment", + "reqwest 0.11.27", + "rmp-serde", + "rpassword", + "serde", + "serde_json", + "serde_with 1.14.0", + "sha3", + "tokio", +] + [[package]] name = "miniz_oxide" version = "0.7.4" diff --git a/operator/mina/lib/Cargo.toml b/operator/mina/lib/Cargo.toml index e4d02628e..fc916dc53 100644 --- a/operator/mina/lib/Cargo.toml +++ b/operator/mina/lib/Cargo.toml @@ -26,7 +26,7 @@ bs58 = "0.5.1" lazy_static = "1.5.0" blake2 = "0.10.6" once_cell = "1.19.0" -core = { git = "https://github.com/lambdaclass/mina_bridge", branch = "relative_finalization" } +mina_bridge_core = { git = "https://github.com/lambdaclass/mina_bridge", branch = "relative_finalization" } bincode = "1.3.3" [patch.crates-io] diff --git a/operator/mina/lib/mina_verifier.h b/operator/mina/lib/mina_verifier.h index ce007ae49..3806aae2f 100644 --- a/operator/mina/lib/mina_verifier.h +++ b/operator/mina/lib/mina_verifier.h @@ -1,6 +1,6 @@ #include -bool verify_protocol_state_proof_ffi(unsigned char *proof_buffer, - unsigned int proof_len, - unsigned char *public_input_buffer, - unsigned int public_input_len); +bool verify_mina_state_ffi(unsigned char *proof_buffer, + unsigned int proof_len, + unsigned char *pub_input_buffer, + unsigned int pub_input_len); diff --git a/operator/mina/lib/src/lib.rs b/operator/mina/lib/src/lib.rs index 04199f2ec..52220242a 100644 --- a/operator/mina/lib/src/lib.rs +++ b/operator/mina/lib/src/lib.rs @@ -1,6 +1,6 @@ mod consensus_state; -use core::proof::state_proof::{MinaStateProof, MinaStatePubInputs}; +use mina_bridge_core::proof::state_proof::{MinaStateProof, MinaStatePubInputs}; use ark_ec::short_weierstrass_jacobian::GroupAffine; use consensus_state::{select_longer_chain, LongerChainResult}; @@ -25,13 +25,13 @@ const MAX_PROOF_SIZE: usize = 48 * 1024; const MAX_PUB_INPUT_SIZE: usize = 6 * 1024; #[no_mangle] -pub extern "C" fn verify_protocol_state_proof_ffi( - proof_bytes: &[u8; MAX_PROOF_SIZE], +pub extern "C" fn verify_mina_state_ffi( + proof_buffer: &[u8; MAX_PROOF_SIZE], proof_len: usize, - pub_input_bytes: &[u8; MAX_PUB_INPUT_SIZE], + pub_input_buffer: &[u8; MAX_PUB_INPUT_SIZE], pub_input_len: usize, ) -> bool { - let proof: MinaStateProof = match bincode::deserialize(&proof_bytes[..proof_len]) { + let proof: MinaStateProof = match bincode::deserialize(&proof_buffer[..proof_len]) { Ok(proof) => proof, Err(err) => { eprintln!("Failed to deserialize state proof: {}", err); @@ -39,7 +39,7 @@ pub extern "C" fn verify_protocol_state_proof_ffi( } }; let pub_inputs: MinaStatePubInputs = - match bincode::deserialize(&pub_input_bytes[..pub_input_len]) { + match bincode::deserialize(&pub_input_buffer[..pub_input_len]) { Ok(pub_inputs) => pub_inputs, Err(err) => { eprintln!("Failed to deserialize state pub inputs: {}", err); @@ -208,12 +208,8 @@ mod test { assert!(pub_input_size <= pub_input_buffer.len()); pub_input_buffer[..pub_input_size].clone_from_slice(PUB_INPUT_BYTES); - let result = verify_protocol_state_proof_ffi( - &proof_buffer, - proof_size, - &pub_input_buffer, - pub_input_size, - ); + let result = + verify_mina_state_ffi(&proof_buffer, proof_size, &pub_input_buffer, pub_input_size); assert!(result); } @@ -229,12 +225,8 @@ mod test { assert!(pub_input_size <= pub_input_buffer.len()); pub_input_buffer[..pub_input_size].clone_from_slice(PROTOCOL_STATE_BAD_HASH_PUB_BYTES); - let result = verify_protocol_state_proof_ffi( - &proof_buffer, - proof_size, - &pub_input_buffer, - pub_input_size, - ); + let result = + verify_mina_state_ffi(&proof_buffer, proof_size, &pub_input_buffer, pub_input_size); assert!(!result); } diff --git a/operator/mina/mina.go b/operator/mina/mina.go index fe00fb24e..772124a28 100644 --- a/operator/mina/mina.go +++ b/operator/mina/mina.go @@ -14,7 +14,7 @@ import ( ) // TODO(xqft): check proof size -const MAX_PROOF_SIZE = 16 * 1024 +const MAX_PROOF_SIZE = 48 * 1024 const MAX_PUB_INPUT_SIZE = 6 * 1024 func timer() func() { @@ -24,9 +24,9 @@ func timer() func() { } } -func VerifyProtocolStateProof(proofBuffer [MAX_PROOF_SIZE]byte, proofLen uint, pubInputBuffer [MAX_PUB_INPUT_SIZE]byte, pubInputLen uint) bool { +func VerifyMinaState(proofBuffer [MAX_PROOF_SIZE]byte, proofLen uint, pubInputBuffer [MAX_PUB_INPUT_SIZE]byte, pubInputLen uint) bool { defer timer()() proofPtr := (*C.uchar)(unsafe.Pointer(&proofBuffer[0])) pubInputPtr := (*C.uchar)(unsafe.Pointer(&pubInputBuffer[0])) - return (bool)(C.verify_protocol_state_proof_ffi(proofPtr, (C.uint)(proofLen), pubInputPtr, (C.uint)(pubInputLen))) + return (bool)(C.verify_mina_state_ffi(proofPtr, (C.uint)(proofLen), pubInputPtr, (C.uint)(pubInputLen))) } diff --git a/operator/mina/mina_test.go b/operator/mina/mina_test.go index 697f7c005..89317a34a 100644 --- a/operator/mina/mina_test.go +++ b/operator/mina/mina_test.go @@ -31,7 +31,7 @@ func TestMinaStateProofVerifies(t *testing.T) { t.Errorf("could not read bytes from mina state hash") } - if !mina.VerifyProtocolStateProof(([mina.MAX_PROOF_SIZE]byte)(proofBuffer), uint(proofLen), ([mina.MAX_PUB_INPUT_SIZE]byte)(pubInputBuffer), uint(pubInputLen)) { + if !mina.VerifyMinaState(([mina.MAX_PROOF_SIZE]byte)(proofBuffer), uint(proofLen), ([mina.MAX_PUB_INPUT_SIZE]byte)(pubInputBuffer), uint(pubInputLen)) { t.Errorf("proof did not verify") } } diff --git a/operator/pkg/operator.go b/operator/pkg/operator.go index d494bc2ba..d6ead4828 100644 --- a/operator/pkg/operator.go +++ b/operator/pkg/operator.go @@ -365,7 +365,7 @@ func (o *Operator) verify(verificationData VerificationData, results chan bool) pubInputBuffer := make([]byte, mina.MAX_PUB_INPUT_SIZE) copy(pubInputBuffer, verificationData.PubInput) - verificationResult := mina.VerifyProtocolStateProof(([mina.MAX_PROOF_SIZE]byte)(proofBuffer), proofLen, ([mina.MAX_PUB_INPUT_SIZE]byte)(pubInputBuffer), (uint)(pubInputLen)) + verificationResult := mina.VerifyMinaState(([mina.MAX_PROOF_SIZE]byte)(proofBuffer), proofLen, ([mina.MAX_PUB_INPUT_SIZE]byte)(pubInputBuffer), (uint)(pubInputLen)) o.Logger.Infof("Mina state proof verification result: %t", verificationResult) results <- verificationResult case common.MinaAccount: @@ -376,7 +376,7 @@ func (o *Operator) verify(verificationData VerificationData, results chan bool) pubInputBuffer := make([]byte, mina.MAX_PUB_INPUT_SIZE) copy(pubInputBuffer, verificationData.PubInput) - verificationResult := mina_account.VerifyAccountInclusion(([mina.MAX_PROOF_SIZE]byte)(proofBuffer), proofLen, ([mina.MAX_PUB_INPUT_SIZE]byte)(pubInputBuffer), (uint)(pubInputLen)) + verificationResult := mina_account.VerifyAccountInclusion(([mina_account.MAX_PROOF_SIZE]byte)(proofBuffer), proofLen, ([mina_account.MAX_PUB_INPUT_SIZE]byte)(pubInputBuffer), (uint)(pubInputLen)) o.Logger.Infof("Mina account inclusion proof verification result: %t", verificationResult) results <- verificationResult default: