Encodes a TEE proof into the 130-byte format expected by `AggregateVerifier.initializeWithInitData()`. Format: `proofType(1) + l1OriginHash(32) + l1OriginNumber(32) + signature(65)` The v-value in the ECDSA signature is adjusted from 0/1 to 27/28 if needed. # Errors Returns an error if the signature is not exactly 65 bytes or has an invalid v-value.
(
signature: &[u8],
l1_origin_hash: B256,
l1_origin_number: u64,
)
| 59 | /// |
| 60 | /// Returns an error if the signature is not exactly 65 bytes or has an invalid v-value. |
| 61 | pub fn encode_proof_bytes( |
| 62 | signature: &[u8], |
| 63 | l1_origin_hash: B256, |
| 64 | l1_origin_number: u64, |
| 65 | ) -> Result<Bytes, CryptoError> { |
| 66 | if signature.len() != ECDSA_SIGNATURE_LENGTH { |
| 67 | return Err(CryptoError::InvalidSignatureLength(signature.len())); |
| 68 | } |
| 69 | |
| 70 | let mut proof_data = vec![0u8; 1 + 32 + 32 + ECDSA_SIGNATURE_LENGTH]; |
| 71 | |
| 72 | // Byte 0: proof type (TEE = 0) |
| 73 | proof_data[0] = PROOF_TYPE_TEE; |
| 74 | |
| 75 | // Bytes 1-32: L1 origin hash |
| 76 | proof_data[1..33].copy_from_slice(l1_origin_hash.as_slice()); |
| 77 | |
| 78 | // Bytes 33-64: L1 origin number as 32-byte big-endian uint256 |
| 79 | proof_data[33..65].copy_from_slice(&U256::from(l1_origin_number).to_be_bytes::<32>()); |
| 80 | |
| 81 | // Bytes 65-129: ECDSA signature with v-value adjusted from 0/1 to 27/28 |
| 82 | proof_data[65..130].copy_from_slice(&signature[..ECDSA_SIGNATURE_LENGTH]); |
| 83 | proof_data[129] = Self::normalize_v(proof_data[129])?; |
| 84 | |
| 85 | Ok(Bytes::from(proof_data)) |
| 86 | } |
| 87 | |
| 88 | /// Encodes a TEE proof into the compact 66-byte format expected by |
| 89 | /// `AggregateVerifier.nullify()`, `challenge()`, and `verifyProposalProof()`. |