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(state-keeper): circuits seal criterion #729

Merged
merged 32 commits into from
Jan 5, 2024
Merged
Show file tree
Hide file tree
Changes from 30 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
00513b2
Add circuits seal criterion
perekopskiy Dec 14, 2023
d19806e
Merge branch 'main' into circuits-seal-criterion
perekopskiy Dec 19, 2023
6dfd883
Proper calculation of used circuits
perekopskiy Dec 21, 2023
eef8c1d
fmt
perekopskiy Dec 21, 2023
740221d
Merge branch 'main' into circuits-seal-criterion
perekopskiy Dec 21, 2023
8de4cc3
Clean up geometry criteria interface
perekopskiy Dec 21, 2023
6c9185d
Add comment
perekopskiy Dec 21, 2023
fcaec4d
revert
perekopskiy Dec 21, 2023
5bd13d3
Revert
perekopskiy Dec 21, 2023
a128c01
Fix
perekopskiy Dec 21, 2023
3d9d349
Fix
perekopskiy Dec 21, 2023
0844bd9
try f32
perekopskiy Dec 21, 2023
812f211
Clean up
perekopskiy Dec 21, 2023
569a493
Track hot write and reads
perekopskiy Dec 21, 2023
df9b7df
Add comment
perekopskiy Dec 22, 2023
fae2f1f
Apply some review suggestions
perekopskiy Jan 2, 2024
8a487a2
Use updated zk_evm_abstractions
perekopskiy Jan 2, 2024
428618f
Add comments
perekopskiy Jan 3, 2024
8bda047
Change approach to tracing precompiles
perekopskiy Jan 3, 2024
8cc77fd
Merge branch 'main' into circuits-seal-criterion
perekopskiy Jan 3, 2024
7a80f06
Tests
perekopskiy Jan 3, 2024
987e5fc
Switch to main branches back
perekopskiy Jan 3, 2024
a3413e6
Update prover lock file
perekopskiy Jan 3, 2024
2e6ad23
Add comment
perekopskiy Jan 4, 2024
cc8f1cf
new db column
perekopskiy Jan 4, 2024
e37e910
new db column
perekopskiy Jan 4, 2024
51fb475
Merge branch 'main' into circuits-seal-criterion
perekopskiy Jan 4, 2024
a14c189
Add changes to vm_boojum_integration
perekopskiy Jan 5, 2024
bc30894
Add sanity panic
perekopskiy Jan 5, 2024
31c9499
Fix
perekopskiy Jan 5, 2024
066a635
Merge branch 'main' into circuits-seal-criterion
perekopskiy Jan 5, 2024
a3916dc
Fix test
perekopskiy Jan 5, 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
6 changes: 4 additions & 2 deletions 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 core/bin/snapshots_creator/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ async fn create_l1_batch(
);
header.is_finished = true;
conn.blocks_dal()
.insert_l1_batch(&header, &[], BlockGasCount::default(), &[], &[])
.insert_l1_batch(&header, &[], BlockGasCount::default(), &[], &[], 0)
.await
.unwrap();
conn.blocks_dal()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ALTER TABLE l1_batches
DROP COLUMN IF EXISTS predicted_circuits;
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ALTER TABLE l1_batches
ADD COLUMN IF NOT EXISTS predicted_circuits INT;
71 changes: 36 additions & 35 deletions core/lib/dal/sqlx-data.json
Original file line number Diff line number Diff line change
Expand Up @@ -5788,6 +5788,42 @@
},
"query": "\n SELECT\n number,\n hash\n FROM\n miniblocks\n WHERE\n number >= $1\n ORDER BY\n number ASC\n LIMIT\n $2\n "
},
"70979db81f473950b2fae7816dbad7fe3464f2619cee2d583accaa829aa12b94": {
"describe": {
"columns": [],
"nullable": [],
"parameters": {
"Left": [
"Int8",
"Int4",
"Int4",
"Int8",
"Bool",
"Bytea",
"ByteaArray",
"ByteaArray",
"Bytea",
"ByteaArray",
"Int8",
"Int8",
"Int8",
"Jsonb",
"Jsonb",
"Numeric",
"Int8",
"Int8",
"Bytea",
"Bytea",
"Int4",
"ByteaArray",
"Int8Array",
"Bytea",
"Int4"
]
}
},
"query": "\n INSERT INTO\n l1_batches (\n number,\n l1_tx_count,\n l2_tx_count,\n timestamp,\n is_finished,\n fee_account_address,\n l2_to_l1_logs,\n l2_to_l1_messages,\n bloom,\n priority_ops_onchain_data,\n predicted_commit_gas_cost,\n predicted_prove_gas_cost,\n predicted_execute_gas_cost,\n initial_bootloader_heap_content,\n used_contract_hashes,\n base_fee_per_gas,\n l1_gas_price,\n l2_fair_gas_price,\n bootloader_code_hash,\n default_aa_code_hash,\n protocol_version,\n system_logs,\n storage_refunds,\n pubdata_input,\n predicted_circuits,\n created_at,\n updated_at\n )\n VALUES\n (\n $1,\n $2,\n $3,\n $4,\n $5,\n $6,\n $7,\n $8,\n $9,\n $10,\n $11,\n $12,\n $13,\n $14,\n $15,\n $16,\n $17,\n $18,\n $19,\n $20,\n $21,\n $22,\n $23,\n $24,\n $25,\n NOW(),\n NOW()\n )\n "
},
"72a4f50355324cce85ebaef9fa32826095e9290f0c1157094bd0c44e06012e42": {
"describe": {
"columns": [
Expand Down Expand Up @@ -8002,41 +8038,6 @@
},
"query": "\n SELECT\n upgrade_tx_hash\n FROM\n protocol_versions\n WHERE\n id = $1\n "
},
"aa8e569cf406cd0975a6ffaeeafa92f632186181ba8b93518e549e0643f58da8": {
"describe": {
"columns": [],
"nullable": [],
"parameters": {
"Left": [
"Int8",
"Int4",
"Int4",
"Int8",
"Bool",
"Bytea",
"ByteaArray",
"ByteaArray",
"Bytea",
"ByteaArray",
"Int8",
"Int8",
"Int8",
"Jsonb",
"Jsonb",
"Numeric",
"Int8",
"Int8",
"Bytea",
"Bytea",
"Int4",
"ByteaArray",
"Int8Array",
"Bytea"
]
}
},
"query": "\n INSERT INTO\n l1_batches (\n number,\n l1_tx_count,\n l2_tx_count,\n timestamp,\n is_finished,\n fee_account_address,\n l2_to_l1_logs,\n l2_to_l1_messages,\n bloom,\n priority_ops_onchain_data,\n predicted_commit_gas_cost,\n predicted_prove_gas_cost,\n predicted_execute_gas_cost,\n initial_bootloader_heap_content,\n used_contract_hashes,\n base_fee_per_gas,\n l1_gas_price,\n l2_fair_gas_price,\n bootloader_code_hash,\n default_aa_code_hash,\n protocol_version,\n system_logs,\n storage_refunds,\n pubdata_input,\n created_at,\n updated_at\n )\n VALUES\n (\n $1,\n $2,\n $3,\n $4,\n $5,\n $6,\n $7,\n $8,\n $9,\n $10,\n $11,\n $12,\n $13,\n $14,\n $15,\n $16,\n $17,\n $18,\n $19,\n $20,\n $21,\n $22,\n $23,\n $24,\n NOW(),\n NOW()\n )\n "
},
"aa91697157517322b0dbb53dca99f41220c51f58a03c61d6b7789eab0504e320": {
"describe": {
"columns": [
Expand Down
10 changes: 7 additions & 3 deletions core/lib/dal/src/blocks_dal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,7 @@ impl BlocksDal<'_, '_> {
predicted_block_gas: BlockGasCount,
events_queue: &[LogQuery],
storage_refunds: &[u32],
predicted_circuits: u32,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where is a good place to add the description on what 'predicted_circuits' mean?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think adding a comment to this method declaration will work best, will add it with the next PR I open

) -> anyhow::Result<()> {
let priority_onchain_data: Vec<Vec<u8>> = header
.priority_ops_onchain_data
Expand Down Expand Up @@ -509,6 +510,7 @@ impl BlocksDal<'_, '_> {
system_logs,
storage_refunds,
pubdata_input,
predicted_circuits,
created_at,
updated_at
)
Expand Down Expand Up @@ -538,6 +540,7 @@ impl BlocksDal<'_, '_> {
$22,
$23,
$24,
$25,
NOW(),
NOW()
)
Expand Down Expand Up @@ -566,6 +569,7 @@ impl BlocksDal<'_, '_> {
&system_logs,
&storage_refunds,
pubdata_input,
predicted_circuits as i32,
)
.execute(transaction.conn())
.await?;
Expand Down Expand Up @@ -2341,7 +2345,7 @@ mod tests {
header.l2_to_l1_messages.push(vec![33; 33]);

conn.blocks_dal()
.insert_l1_batch(&header, &[], BlockGasCount::default(), &[], &[])
.insert_l1_batch(&header, &[], BlockGasCount::default(), &[], &[], 0)
.await
.unwrap();

Expand Down Expand Up @@ -2390,15 +2394,15 @@ mod tests {
execute: 10,
};
conn.blocks_dal()
.insert_l1_batch(&header, &[], predicted_gas, &[], &[])
.insert_l1_batch(&header, &[], predicted_gas, &[], &[], 0)
.await
.unwrap();

header.number = L1BatchNumber(2);
header.timestamp += 100;
predicted_gas += predicted_gas;
conn.blocks_dal()
.insert_l1_batch(&header, &[], predicted_gas, &[], &[])
.insert_l1_batch(&header, &[], predicted_gas, &[], &[], 0)
.await
.unwrap();

Expand Down
2 changes: 1 addition & 1 deletion core/lib/dal/src/storage_logs_dal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -733,7 +733,7 @@ mod tests {
);
header.is_finished = true;
conn.blocks_dal()
.insert_l1_batch(&header, &[], BlockGasCount::default(), &[], &[])
.insert_l1_batch(&header, &[], BlockGasCount::default(), &[], &[], 0)
.await
.unwrap();
conn.blocks_dal()
Expand Down
4 changes: 2 additions & 2 deletions core/lib/dal/src/sync_dal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ mod tests {
ProtocolVersionId::latest(),
);
conn.blocks_dal()
.insert_l1_batch(&l1_batch_header, &[], BlockGasCount::default(), &[], &[])
.insert_l1_batch(&l1_batch_header, &[], BlockGasCount::default(), &[], &[], 0)
.await
.unwrap();
conn.blocks_dal()
Expand Down Expand Up @@ -205,7 +205,7 @@ mod tests {
l1_batch_header.number = L1BatchNumber(1);
l1_batch_header.timestamp = 1;
conn.blocks_dal()
.insert_l1_batch(&l1_batch_header, &[], BlockGasCount::default(), &[], &[])
.insert_l1_batch(&l1_batch_header, &[], BlockGasCount::default(), &[], &[], 0)
.await
.unwrap();
conn.blocks_dal()
Expand Down
3 changes: 2 additions & 1 deletion core/lib/multivm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ zk_evm_1_4_0 = { package = "zk_evm", git = "https://github.com/matter-labs/era-z
zk_evm_1_3_3 = { package = "zk_evm", git = "https://github.com/matter-labs/era-zk_evm.git", tag= "v1.3.3-rc2" }
zk_evm_1_3_1 = { package = "zk_evm", git = "https://github.com/matter-labs/era-zk_evm.git", tag= "v1.3.1-rc2" }

zkevm_test_harness_1_4_0 = { git = "https://github.com/matter-labs/era-zkevm_test_harness.git", branch = "v1.4.0", package = "zkevm_test_harness" }

zksync_types = { path = "../types" }
zksync_state = { path = "../state" }
zksync_contracts = { path = "../contracts" }
Expand All @@ -29,7 +31,6 @@ thiserror = "1.0"
tracing = "0.1"
vise = { git = "https://github.com/matter-labs/vise.git", version = "0.1.0", rev = "1c9cc500e92cf9ea052b230e114a6f9cce4fb2c1" }


[dev-dependencies]
tokio = { version = "1", features = ["time"] }
zksync_test_account = { path = "../test_account" }
Expand Down
6 changes: 6 additions & 0 deletions core/lib/multivm/src/glue/types/vm/vm_block_result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ impl GlueFrom<crate::vm_m5::vm_instance::VmBlockResult> for crate::interface::Fi
computational_gas_used: value.full_result.gas_used,
gas_used: value.full_result.gas_used,
pubdata_published: 0,
estimated_circuits_used: 0.0,
},
refunds: Refunds::default(),
},
Expand Down Expand Up @@ -64,6 +65,7 @@ impl GlueFrom<crate::vm_m6::vm_instance::VmBlockResult> for crate::interface::Fi
computational_gas_used: value.full_result.computational_gas_used,
gas_used: value.full_result.gas_used,
pubdata_published: 0,
estimated_circuits_used: 0.0,
},
refunds: Refunds::default(),
},
Expand Down Expand Up @@ -108,6 +110,7 @@ impl GlueFrom<crate::vm_1_3_2::vm_instance::VmBlockResult> for crate::interface:
computational_gas_used: value.full_result.computational_gas_used,
gas_used: value.full_result.gas_used,
pubdata_published: 0,
estimated_circuits_used: 0.0,
},
refunds: Refunds::default(),
},
Expand Down Expand Up @@ -168,6 +171,7 @@ impl GlueFrom<crate::vm_1_3_2::vm_instance::VmBlockResult>
computational_gas_used: value.full_result.computational_gas_used,
gas_used: value.full_result.gas_used,
pubdata_published: 0,
estimated_circuits_used: 0.0,
},
refunds: Refunds::default(),
}
Expand Down Expand Up @@ -198,6 +202,7 @@ impl GlueFrom<crate::vm_m5::vm_instance::VmBlockResult>
computational_gas_used: 0,
gas_used: value.full_result.gas_used,
pubdata_published: 0,
estimated_circuits_used: 0.0,
},
refunds: Refunds::default(),
}
Expand Down Expand Up @@ -239,6 +244,7 @@ impl GlueFrom<crate::vm_m6::vm_instance::VmBlockResult>
computational_gas_used: value.full_result.computational_gas_used,
gas_used: value.full_result.gas_used,
pubdata_published: 0,
estimated_circuits_used: 0.0,
},
refunds: Refunds::default(),
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ impl GlueFrom<crate::vm_m5::vm_instance::VmPartialExecutionResult>
// There are no such fields in m5
computational_gas_used: 0,
pubdata_published: 0,
estimated_circuits_used: 0.0,
},
refunds: crate::interface::Refunds {
gas_refunded: 0,
Expand All @@ -39,6 +40,7 @@ impl GlueFrom<crate::vm_m6::vm_instance::VmPartialExecutionResult>
computational_gas_used: value.computational_gas_used,
total_log_queries: value.logs.total_log_queries_count,
pubdata_published: 0,
estimated_circuits_used: 0.0,
},
refunds: crate::interface::Refunds {
gas_refunded: 0,
Expand All @@ -62,6 +64,7 @@ impl GlueFrom<crate::vm_1_3_2::vm_instance::VmPartialExecutionResult>
computational_gas_used: value.computational_gas_used,
total_log_queries: value.logs.total_log_queries_count,
pubdata_published: 0,
estimated_circuits_used: 0.0,
},
refunds: crate::interface::Refunds {
gas_refunded: 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ impl VmExecutionResultAndLogs {
cycles_used: self.statistics.cycles_used,
computational_gas_used: self.statistics.computational_gas_used,
pubdata_published: self.statistics.pubdata_published,
estimated_circuits_used: self.statistics.estimated_circuits_used,
}
}
}
1 change: 1 addition & 0 deletions core/lib/multivm/src/interface/types/outputs/statistic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ pub struct VmExecutionStatistics {
/// Number of log queries produced by the VM during the tx execution.
pub total_log_queries: usize,
pub pubdata_published: u32,
pub estimated_circuits_used: f32,
}

/// Oracle metrics of the VM.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ impl<S: WriteStorage, H: HistoryMode> Vm<S, H> {
spent_pubdata_counter_before,
pubdata_published,
logs.total_log_queries_count,
tx_tracer.circuits_tracer.estimated_circuits_used,
);
let result = tx_tracer.result_tracer.into_result();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ impl<S: WriteStorage, H: HistoryMode> Vm<S, H> {
spent_pubdata_counter_before: u32,
pubdata_published: u32,
total_log_queries_count: usize,
estimated_circuits_used: f32,
) -> VmExecutionStatistics {
let computational_gas_used = self.calculate_computational_gas_used(
tracer,
Expand All @@ -40,6 +41,7 @@ impl<S: WriteStorage, H: HistoryMode> Vm<S, H> {
computational_gas_used,
total_log_queries: total_log_queries_count,
pubdata_published,
estimated_circuits_used,
}
}

Expand Down
Loading