Skip to content

Commit

Permalink
Send uncoded commitment
Browse files Browse the repository at this point in the history
  • Loading branch information
gianbelinche committed Sep 26, 2024
1 parent 5021488 commit ee302ec
Show file tree
Hide file tree
Showing 4 changed files with 169 additions and 9 deletions.
5 changes: 4 additions & 1 deletion core/lib/l1_contract_interface/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,11 @@ sha2.workspace = true
sha3.workspace = true
hex.workspace = true
once_cell.workspace = true
rlp.workspace = true
serde.workspace = true
bincode.workspace = true

[dev-dependencies]
serde.workspace = true
serde_json.workspace = true
serde_with = { workspace = true, features = ["base64", "hex"] }

140 changes: 140 additions & 0 deletions core/lib/l1_contract_interface/src/i_executor/structures/blob_info.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
use rlp::Decodable;
use rlp::DecoderError;
use rlp::Rlp;
use serde::{Serialize, Deserialize};

#[derive(Debug,Serialize, Deserialize)]
struct G1Commitment {
pub x: Vec<u8>,
pub y: Vec<u8>,
}

impl Decodable for G1Commitment {
fn decode(rlp: &Rlp) -> Result<Self, DecoderError> {
let x: Vec<u8> = rlp.val_at(0)?; // Decode first element as Vec<u8>
let y: Vec<u8> = rlp.val_at(1)?; // Decode second element as Vec<u8>

Ok(G1Commitment { x, y })
}
}

#[derive(Debug,Serialize, Deserialize)]
struct BlobQuorumParam {
pub quorum_number: u32,
pub adversary_threshold_percentage: u32,
pub confirmation_threshold_percentage: u32,
pub chunk_length: u32
}

impl Decodable for BlobQuorumParam {
fn decode(rlp: &Rlp) -> Result<Self, DecoderError> {
Ok(BlobQuorumParam {
quorum_number: rlp.val_at(0)?,
adversary_threshold_percentage: rlp.val_at(1)?,
confirmation_threshold_percentage: rlp.val_at(2)?,
chunk_length: rlp.val_at(3)?,
})
}
}

#[derive(Debug,Serialize, Deserialize)]
struct BlobHeader {
pub commitment: G1Commitment,
pub data_length: u32,
pub blob_quorum_params: Vec<BlobQuorumParam>
}

impl Decodable for BlobHeader {
fn decode(rlp: &Rlp) -> Result<Self, DecoderError> {
let commitment: G1Commitment = rlp.val_at(0)?;
let data_length: u32 = rlp.val_at(1)?;
let blob_quorum_params: Vec<BlobQuorumParam> = rlp.list_at(2)?;

Ok(BlobHeader {
commitment,
data_length,
blob_quorum_params,
})
}
}

#[derive(Debug,Serialize, Deserialize)]
struct BatchHeader {
pub batch_root: Vec<u8>,
pub quorum_numbers: Vec<u8>,
pub quorum_signed_percentages: Vec<u8>,
pub reference_block_number: u32
}

impl Decodable for BatchHeader {
fn decode(rlp: &Rlp) -> Result<Self, DecoderError> {
Ok(BatchHeader {
batch_root: rlp.val_at(0)?,
quorum_numbers: rlp.val_at(1)?,
quorum_signed_percentages: rlp.val_at(2)?,
reference_block_number: rlp.val_at(3)?,
})
}
}

#[derive(Debug,Serialize, Deserialize)]
struct BatchMetadata {
pub batch_header: BatchHeader,
pub signatory_record_hash: Vec<u8>,
pub fee: Vec<u8>,
pub confirmation_block_number: u32,
pub batch_header_hash: Vec<u8>
}

impl Decodable for BatchMetadata {
fn decode(rlp: &Rlp) -> Result<Self, DecoderError> {
let batch_header: BatchHeader = rlp.val_at(0)?;

Ok(BatchMetadata {
batch_header,
signatory_record_hash: rlp.val_at(1)?,
fee: rlp.val_at(2)?,
confirmation_block_number: rlp.val_at(3)?,
batch_header_hash: rlp.val_at(4)?,
})
}
}

#[derive(Debug,Serialize, Deserialize)]
struct BlobVerificationProof {
pub batch_id: u32,
pub blob_index: u32,
pub batch_medatada: BatchMetadata,
pub inclusion_proof: Vec<u8>,
pub quorum_indexes: Vec<u8>
}

impl Decodable for BlobVerificationProof {
fn decode(rlp: &Rlp) -> Result<Self, DecoderError> {
Ok(BlobVerificationProof {
batch_id: rlp.val_at(0)?,
blob_index: rlp.val_at(1)?,
batch_medatada: rlp.val_at(2)?,
inclusion_proof: rlp.val_at(3)?,
quorum_indexes: rlp.val_at(4)?,
})
}
}

#[derive(Debug,Serialize, Deserialize)]
pub struct BlobInfo {
pub blob_header: BlobHeader,
pub blob_verification_proof: BlobVerificationProof
}

impl Decodable for BlobInfo {
fn decode(rlp: &Rlp) -> Result<Self, DecoderError> {
let blob_header: BlobHeader = rlp.val_at(0)?;
let blob_verification_proof: BlobVerificationProof = rlp.val_at(1)?;

Ok(BlobInfo {
blob_header,
blob_verification_proof,
})
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use rlp::decode;
use zksync_types::{
commitment::{
pre_boojum_serialize_commitments, serialize_commitments, L1BatchCommitmentMode,
Expand All @@ -13,6 +14,8 @@ use crate::{
i_executor::commit::kzg::{KzgInfo, ZK_SYNC_BYTES_PER_BLOB},
Tokenizable,
};
use bincode;
use super::blob_info::BlobInfo;

/// These are used by the L1 Contracts to indicate what DA layer is used for pubdata
const PUBDATA_SOURCE_CALLDATA: u8 = 0;
Expand Down Expand Up @@ -217,14 +220,27 @@ impl Tokenizable for CommitBatchInfo<'_> {
}
(L1BatchCommitmentMode::Validium, PubdataDA::Custom) => {
let mut operator_da_input = vec![PUBDATA_SOURCE_CUSTOM];
operator_da_input.extend(
&self
.l1_batch_with_metadata
.metadata
.da_blob_id
.clone()
.unwrap_or_default()
);

let commitment = &self
.l1_batch_with_metadata
.metadata
.da_blob_id
.clone()
.unwrap_or_default();

let data = &hex::decode(commitment).unwrap()[3..];

let blob_info: BlobInfo = match decode(&data) {
Ok(blob_info) => blob_info,
Err(e) => panic!("Error decoding commitment: {}", e)
};

let bytes = match bincode::serialize(&blob_info) {
Ok(bytes) => bytes,
Err(e) => panic!("Error serializing commitment: {}", e)
};

operator_da_input.extend(bytes);
operator_da_input
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
mod commit_batch_info;
mod stored_batch_info;
mod blob_info;

pub use self::{commit_batch_info::CommitBatchInfo, stored_batch_info::StoredBatchInfo};

0 comments on commit ee302ec

Please sign in to comment.