Skip to content

Commit

Permalink
Fix operator for new Mina proof
Browse files Browse the repository at this point in the history
  • Loading branch information
xqft committed Aug 29, 2024
1 parent 893bb71 commit dbcb0d0
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 69 deletions.
80 changes: 40 additions & 40 deletions operator/mina/lib/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion operator/mina/lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
8 changes: 4 additions & 4 deletions operator/mina/lib/mina_verifier.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include <stdbool.h>

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);
28 changes: 10 additions & 18 deletions operator/mina/lib/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand All @@ -25,21 +25,21 @@ 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);
return false;
}
};
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);
Expand Down Expand Up @@ -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);
}

Expand All @@ -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);
}

Expand Down
6 changes: 3 additions & 3 deletions operator/mina/mina.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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)))
}
2 changes: 1 addition & 1 deletion operator/mina/mina_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}
4 changes: 2 additions & 2 deletions operator/pkg/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand Down

0 comments on commit dbcb0d0

Please sign in to comment.