Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: verification of L1Batch witness (BFT-471) #2019

Merged
merged 65 commits into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
2c97eac
snapshot
pompon0 May 20, 2024
677f265
root_hash proof obtained
pompon0 May 20, 2024
8469d4a
snapshot
pompon0 May 21, 2024
4282d8d
wip
pompon0 May 22, 2024
754b613
removed secret
pompon0 May 23, 2024
3d3c38e
block hash extracted
pompon0 May 23, 2024
dd793ef
block hashes do not match
pompon0 May 23, 2024
93bb857
all hashes match
pompon0 May 24, 2024
10f7237
found eth client for tests
pompon0 May 27, 2024
a0bd284
stub of the batch verification/generation
pompon0 May 27, 2024
3417f7f
snapshot
pompon0 May 28, 2024
f1a3698
snapshot
pompon0 May 29, 2024
65924d9
Merge remote-tracking branch 'origin/main' into gprusak-batch-proof
pompon0 May 30, 2024
ab6529d
cargo check passes
pompon0 May 30, 2024
3097a09
L1Tx <-> NewPriorityRequest isomorphism
pompon0 May 30, 2024
06cecd8
zk fmt
pompon0 May 31, 2024
f23d5c3
Merge remote-tracking branch 'origin/main' into gprusak-batch-proof
pompon0 May 31, 2024
76b91c2
zk lint
pompon0 May 31, 2024
d6eed6d
adjusted ProtocolUpgradeTx
pompon0 May 31, 2024
3363574
cleanup
pompon0 May 31, 2024
1c3275f
fixed unit test
pompon0 May 31, 2024
6c24b8c
Merge remote-tracking branch 'origin/main' into gprusak-batch-proof
pompon0 May 31, 2024
71ba819
abi
pompon0 Jun 1, 2024
4a23fb4
zk fmt
pompon0 Jun 1, 2024
4f93213
fixed token count
pompon0 Jun 3, 2024
da439e5
fixed conditional computation
pompon0 Jun 3, 2024
f59c78f
snapshot
pompon0 Jun 3, 2024
b226d85
snapshot
pompon0 Jun 3, 2024
6dd1d17
fixed ethwatch tests
pompon0 Jun 3, 2024
da0baf3
zk lint
pompon0 Jun 4, 2024
d055f3d
storage WIP
pompon0 Jun 4, 2024
1917cf9
L1BatchProof::load
pompon0 Jun 4, 2024
404818f
Merge remote-tracking branch 'origin/main' into gprusak-batch-proof
pompon0 Jun 4, 2024
7bfaddb
snapshot
pompon0 Jun 4, 2024
ad34839
test works, although no transactions are present
pompon0 Jun 4, 2024
5786b0f
Merge remote-tracking branch 'origin/main' into gprusak-batch-proof
pompon0 Jun 5, 2024
cad6cd8
Merge remote-tracking branch 'origin/main' into gprusak-batch-proof
pompon0 Jun 6, 2024
faec021
removed debugs from commitment_generator
pompon0 Jun 6, 2024
6c72917
snapshot
pompon0 Jun 6, 2024
1db4d4b
exposed test utilities to reuse
pompon0 Jun 6, 2024
7a39332
WIP the VM crashes
pompon0 Jun 6, 2024
986282d
wip: fixing fake L2 transactions
pompon0 Jun 8, 2024
b2e0844
test passes
pompon0 Jun 8, 2024
e07716e
removed the tool
pompon0 Jun 8, 2024
d9a3fe5
prover Cargo.toml
pompon0 Jun 8, 2024
15756fb
removed serde from TransansactionRequest
pompon0 Jun 8, 2024
8a98f7d
zk fmt
pompon0 Jun 10, 2024
f3f2202
zk lint
pompon0 Jun 10, 2024
2409c96
spellcheck
pompon0 Jun 10, 2024
1b528b1
Merge remote-tracking branch 'origin/main' into gprusak-batch-proof
pompon0 Jun 10, 2024
624c703
fixing tests
pompon0 Jun 10, 2024
efe0ba8
typo
pompon0 Jun 10, 2024
a88cf51
Merge branch 'main' into gprusak-batch-proof
pompon0 Jun 11, 2024
d4b5254
zk lint
pompon0 Jun 11, 2024
8fac670
Merge remote-tracking branch 'origin/main' into gprusak-batch-proof
pompon0 Jun 11, 2024
2f3ee80
Merge branch 'gprusak-batch-proof' of https://github.com/matter-labs/…
pompon0 Jun 11, 2024
4d38a01
prover Cargo.lock
pompon0 Jun 11, 2024
960d1d5
random bullshit
pompon0 Jun 11, 2024
51b8540
change type of factory_deps
pompon0 Jun 11, 2024
a666d7e
forgoten logs
pompon0 Jun 11, 2024
9eb9255
Merge remote-tracking branch 'origin/main' into gprusak-batch-proof
pompon0 Jun 12, 2024
949745a
applied comments
pompon0 Jun 12, 2024
1f19a6c
spellcheck doesn't know english
pompon0 Jun 12, 2024
f5b85ae
Merge branch 'main' into gprusak-batch-proof
pompon0 Jun 12, 2024
90a4f0e
Merge branch 'main' into gprusak-batch-proof
pompon0 Jun 13, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions Cargo.lock

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

6 changes: 3 additions & 3 deletions core/bin/system-constants-generator/src/intrinsic_costs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ pub(crate) fn l2_gas_constants() -> IntrinsicSystemGasConstants {
0,
Some(U256::zero()),
None,
None,
vec![],
)
.into(),
],
Expand All @@ -99,7 +99,7 @@ pub(crate) fn l2_gas_constants() -> IntrinsicSystemGasConstants {
0,
Some(U256::zero()),
Some(vec![0u8; DELTA_IN_TX_SIZE]),
None,
vec![],
)
.into()],
true,
Expand All @@ -117,7 +117,7 @@ pub(crate) fn l2_gas_constants() -> IntrinsicSystemGasConstants {
0,
Some(U256::zero()),
None,
Some(vec![vec![0u8; 32]]),
vec![vec![0u8; 32]],
)
.into()],
true,
Expand Down
8 changes: 4 additions & 4 deletions core/bin/system-constants-generator/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ pub(super) fn get_l2_tx(
U256::from(0),
L2ChainId::from(270),
signer,
None,
vec![],
Default::default(),
)
.unwrap()
Expand Down Expand Up @@ -128,7 +128,7 @@ pub(super) fn get_l1_tx(
pubdata_price: u32,
custom_gas_limit: Option<U256>,
custom_calldata: Option<Vec<u8>>,
factory_deps: Option<Vec<Vec<u8>>>,
factory_deps: Vec<Vec<u8>>,
) -> L1Tx {
L1Tx {
execute: Execute {
Expand Down Expand Up @@ -157,10 +157,10 @@ pub(super) fn get_l1_txs(number_of_txs: usize) -> (Vec<Transaction>, Vec<Transac
let contract_address = Address::random();

txs_without_pubdata_price
.push(get_l1_tx(id as u64, sender, contract_address, 0, None, None, None).into());
.push(get_l1_tx(id as u64, sender, contract_address, 0, None, None, vec![]).into());

txs_with_pubdata_price
.push(get_l1_tx(id as u64, sender, contract_address, 1, None, None, None).into());
.push(get_l1_tx(id as u64, sender, contract_address, 1, None, None, vec![]).into());
}

(txs_with_pubdata_price, txs_without_pubdata_price)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ impl<TypedStructure: EIP712TypedStructure> StructMember for TypedStructure {
}

/// Interface for defining the structure for the EIP712 signature.
pub trait EIP712TypedStructure: Serialize {
pub trait EIP712TypedStructure {
const TYPE_NAME: &'static str;

fn build_structure<BUILDER: StructBuilder>(&self, builder: &mut BUILDER);
Expand Down
2 changes: 1 addition & 1 deletion core/lib/crypto_primitives/src/eip712_signature/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::eip712_signature::typed_structure::{EIP712TypedStructure, Eip712Domai

/// Formats the data that needs to be signed in json according to the standard eip-712.
/// Compatible with `eth_signTypedData` RPC call.
pub fn get_eip712_json<T: EIP712TypedStructure>(
pub fn get_eip712_json<T: EIP712TypedStructure + serde::Serialize>(
eip712_domain: &Eip712Domain,
typed_struct: &T,
) -> Value {
Expand Down

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

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

10 changes: 2 additions & 8 deletions core/lib/dal/src/consensus/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,10 +277,7 @@ impl ProtoRepr for proto::Transaction {
.and_then(|x| parse_h256(x))
.map(h256_to_u256)
.context("execute.value")?,
factory_deps: match execute.factory_deps.is_empty() {
true => None,
false => Some(execute.factory_deps.clone()),
},
factory_deps: execute.factory_deps.clone(),
},
received_timestamp_ms: 0, // This timestamp is local to the node
raw_bytes: self.raw_bytes.as_ref().map(|x| x.clone().into()),
Expand Down Expand Up @@ -361,10 +358,7 @@ impl ProtoRepr for proto::Transaction {
contract_address: Some(this.execute.contract_address.as_bytes().into()),
calldata: Some(this.execute.calldata.clone()),
value: Some(u256_to_h256(this.execute.value).as_bytes().into()),
factory_deps: match &this.execute.factory_deps {
Some(inner) => inner.clone(),
None => vec![],
},
factory_deps: this.execute.factory_deps.clone(),
};
Self {
common_data: Some(common_data),
Expand Down
4 changes: 3 additions & 1 deletion core/lib/dal/src/consensus/proto/mod.proto
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ message Payload {
}

message Transaction {
reserved 5;
reserved "received_timestamp_ms";
oneof common_data {
L1TxCommonData l1 = 1;
L2TxCommonData l2 = 2;
Expand Down Expand Up @@ -80,7 +82,7 @@ message Execute {
optional bytes contract_address = 1; // required; H160
optional bytes calldata = 2; // required
optional bytes value = 3; // required; U256
repeated bytes factory_deps = 4; // optional
repeated bytes factory_deps = 4;
}

message InputData {
Expand Down
61 changes: 41 additions & 20 deletions core/lib/dal/src/consensus_dal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -279,33 +279,54 @@ impl ConsensusDal<'_, '_> {
.await
}

/// Converts the L2 block `block_number` into consensus payload. `Payload` is an
/// opaque format for the L2 block that consensus understands and generates a
/// certificate for it.
pub async fn block_payload(
/// Fetches a range of L2 blocks from storage and converts them to `Payload`s.
pub async fn block_payloads(
&mut self,
block_number: validator::BlockNumber,
) -> DalResult<Option<Payload>> {
let instrumentation =
Instrumented::new("block_payload").with_arg("block_number", &block_number);
let block_number = u32::try_from(block_number.0)
.map_err(|err| instrumentation.arg_error("block_number", err))?;
let block_number = L2BlockNumber(block_number);
numbers: std::ops::Range<validator::BlockNumber>,
) -> DalResult<Vec<Payload>> {
let numbers = (|| {
anyhow::Ok(std::ops::Range {
start: L2BlockNumber(numbers.start.0.try_into().context("start")?),
end: L2BlockNumber(numbers.end.0.try_into().context("end")?),
})
})()
.map_err(|err| {
Instrumented::new("block_payloads")
.with_arg("numbers", &numbers)
.arg_error("numbers", err)
})?;

let Some(block) = self
let blocks = self
.storage
.sync_dal()
.sync_block_inner(block_number)
.await?
else {
return Ok(None);
};
let transactions = self
.sync_blocks_inner(numbers.clone())
.await?;
let mut transactions = self
.storage
.transactions_web3_dal()
.get_raw_l2_block_transactions(block_number)
.get_raw_l2_blocks_transactions(numbers)
.await?;
Ok(Some(block.into_payload(transactions)))
Ok(blocks
.into_iter()
.map(|b| {
let txs = transactions.remove(&b.number).unwrap_or_default();
b.into_payload(txs)
})
.collect())
}

/// Fetches an L2 block from storage and converts it to `Payload`. `Payload` is an
/// opaque format for the L2 block that consensus understands and generates a
/// certificate for it.
pub async fn block_payload(
&mut self,
number: validator::BlockNumber,
) -> DalResult<Option<Payload>> {
Ok(self
.block_payloads(number..number + 1)
.await?
.into_iter()
.next())
}

/// Inserts a certificate for the L2 block `cert.header().number`. It verifies that
Expand Down
2 changes: 1 addition & 1 deletion core/lib/dal/src/models/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ fn default_execute() -> Execute {
8cdfd0000000000000000000000000000000000000000000000000000000157d600d0",
)
.unwrap(),
factory_deps: None,
factory_deps: vec![],
}
}

Expand Down
43 changes: 28 additions & 15 deletions core/lib/dal/src/sync_dal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,15 @@ pub struct SyncDal<'a, 'c> {
}

impl SyncDal<'_, '_> {
pub(super) async fn sync_block_inner(
pub(super) async fn sync_blocks_inner(
&mut self,
block_number: L2BlockNumber,
) -> DalResult<Option<SyncBlock>> {
let block = sqlx::query_as!(
numbers: std::ops::Range<L2BlockNumber>,
) -> DalResult<Vec<SyncBlock>> {
// Check if range is non-empty, because BETWEEN in SQL in `unordered`.
if numbers.is_empty() {
return Ok(vec![]);
}
let blocks = sqlx::query_as!(
StorageSyncBlock,
r#"
SELECT
Expand Down Expand Up @@ -53,35 +57,44 @@ impl SyncDal<'_, '_> {
FROM
miniblocks
WHERE
miniblocks.number = $1
miniblocks.number BETWEEN $1 AND $2
"#,
i64::from(block_number.0)
i64::from(numbers.start.0),
i64::from(numbers.end.0 - 1),
pompon0 marked this conversation as resolved.
Show resolved Hide resolved
)
.try_map(SyncBlock::try_from)
.instrument("sync_dal_sync_block.block")
.with_arg("block_number", &block_number)
.fetch_optional(self.storage)
.instrument("sync_dal_sync_blocks.block")
.with_arg("numbers", &numbers)
.fetch_all(self.storage)
.await?;

Ok(block)
Ok(blocks)
}

pub async fn sync_block(
&mut self,
block_number: L2BlockNumber,
number: L2BlockNumber,
include_transactions: bool,
) -> DalResult<Option<en::SyncBlock>> {
let _latency = MethodLatency::new("sync_dal_sync_block");
let Some(block) = self.sync_block_inner(block_number).await? else {
let numbers = number..number + 1;
let Some(block) = self
.sync_blocks_inner(numbers.clone())
.await?
.into_iter()
.next()
else {
return Ok(None);
};
let transactions = if include_transactions {
let transactions = self
let mut transactions = self
.storage
.transactions_web3_dal()
.get_raw_l2_block_transactions(block_number)
.get_raw_l2_blocks_transactions(numbers)
.await?;
Some(transactions)
// If there are no transactions in the block,
// return `Some(vec![])`.
Some(transactions.remove(&number).unwrap_or_default())
} else {
None
};
Expand Down
6 changes: 3 additions & 3 deletions core/lib/dal/src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ pub(crate) fn mock_l2_transaction() -> L2Tx {
Default::default(),
L2ChainId::from(270),
&K256PrivateKey::random(),
None,
vec![],
Default::default(),
)
.unwrap();
Expand Down Expand Up @@ -98,7 +98,7 @@ pub(crate) fn mock_l1_execute() -> L1Tx {
contract_address: H160::random(),
value: Default::default(),
calldata: vec![],
factory_deps: None,
factory_deps: vec![],
};

L1Tx {
Expand Down Expand Up @@ -126,7 +126,7 @@ pub(crate) fn mock_protocol_upgrade_transaction() -> ProtocolUpgradeTx {
contract_address: H160::random(),
value: Default::default(),
calldata: vec![],
factory_deps: None,
factory_deps: vec![],
};

ProtocolUpgradeTx {
Expand Down
Loading
Loading