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: preparation for new precompiles #3535

Merged
merged 1 commit into from
Feb 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
10 changes: 7 additions & 3 deletions core/lib/constants/src/contracts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,27 +100,31 @@ pub const SHA256_PRECOMPILE_ADDRESS: Address = H160([
0x00, 0x00, 0x00, 0x02,
]);

pub const SECP256R1_VERIFY_PRECOMPILE_ADDRESS: Address = H160([
/// The `modexp` system contract address.
pub const MODEXP_PRECOMPILE_ADDRESS: Address = H160([
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x01, 0x00,
0x00, 0x00, 0x00, 0x05,
]);

/// The `ecadd` system contract address.
pub const EC_ADD_PRECOMPILE_ADDRESS: Address = H160([
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x06,
]);

/// The `ecmul` system contract address.
pub const EC_MUL_PRECOMPILE_ADDRESS: Address = H160([
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x07,
]);

/// The `ecpairing` system contract address.
pub const EC_PAIRING_PRECOMPILE_ADDRESS: Address = H160([
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x08,
]);

pub const P256VERIFY_PRECOMPILE_ADDRESS: Address = H160([
pub const SECP256R1_VERIFY_PRECOMPILE_ADDRESS: Address = H160([
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x01, 0x00,
]);
Expand Down
4 changes: 4 additions & 0 deletions core/lib/multivm/src/utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -578,4 +578,8 @@ pub(crate) struct CircuitCycleStatistic {
pub sha256_cycles: u32,
pub secp256k1_verify_cycles: u32,
pub transient_storage_checker_cycles: u32,
pub modexp_cycles: u32,
pub ecadd_cycles: u32,
pub ecmul_cycles: u32,
pub ecpairing_cycles: u32,
}
4 changes: 2 additions & 2 deletions core/lib/multivm/src/versions/testonly/secp256r1.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use zk_evm_1_5_0::zkevm_opcode_defs::p256;
use zksync_system_constants::P256VERIFY_PRECOMPILE_ADDRESS;
use zksync_system_constants::SECP256R1_VERIFY_PRECOMPILE_ADDRESS;
use zksync_types::{h256_to_u256, web3::keccak256, Execute, H256, U256};

use super::{tester::VmTesterBuilder, TestedVm};
Expand Down Expand Up @@ -44,7 +44,7 @@ pub(crate) fn test_secp256r1<VM: TestedVm>() {

let tx = account.get_l2_tx_for_execute(
Execute {
contract_address: Some(P256VERIFY_PRECOMPILE_ADDRESS),
contract_address: Some(SECP256R1_VERIFY_PRECOMPILE_ADDRESS),
calldata: [digest, encoded_r, encoded_s, x, y].concat(),
value: U256::zero(),
factory_deps: vec![],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,6 @@ pub(crate) fn circuit_statistic_from_cycles(cycles: CircuitCycleStatistic) -> Ci
sha256: cycles.sha256_cycles as f32 / GEOMETRY_CONFIG.cycles_per_sha256_circuit as f32,
secp256k1_verify: 0.0,
transient_storage_checker: 0.0,
..Default::default()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,6 @@ pub(crate) fn circuit_statistic_from_cycles(cycles: CircuitCycleStatistic) -> Ci
sha256: cycles.sha256_cycles as f32 / GEOMETRY_CONFIG.cycles_per_sha256_circuit as f32,
secp256k1_verify: 0.0,
transient_storage_checker: 0.0,
..Default::default()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,6 @@ pub(crate) fn circuit_statistic_from_cycles(cycles: CircuitCycleStatistic) -> Ci
sha256: cycles.sha256_cycles as f32 / GEOMETRY_CONFIG.cycles_per_sha256_circuit as f32,
secp256k1_verify: 0.0,
transient_storage_checker: 0.0,
..Default::default()
}
}
1 change: 1 addition & 0 deletions core/lib/multivm/src/versions/vm_fast/tracers/circuits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ impl CircuitsTracer {
/ GEOMETRY_CONFIG.cycles_per_secp256r1_verify_circuit as f32,
transient_storage_checker: self.transient_storage_checker_cycles as f32
/ GEOMETRY_CONFIG.cycles_per_transient_storage_sorter as f32,
..Default::default()
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,5 +80,6 @@ pub(crate) fn circuit_statistic_from_cycles(cycles: CircuitCycleStatistic) -> Ci
/ GEOMETRY_CONFIG.cycles_per_secp256r1_verify_circuit as f32,
transient_storage_checker: cycles.transient_storage_checker_cycles as f32
/ GEOMETRY_CONFIG.cycles_per_transient_storage_sorter as f32,
..Default::default()
}
}
6 changes: 3 additions & 3 deletions core/lib/types/src/system_contracts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ use zksync_system_constants::{
BOOTLOADER_UTILITIES_ADDRESS, CODE_ORACLE_ADDRESS, COMPRESSOR_ADDRESS, CREATE2_FACTORY_ADDRESS,
EVENT_WRITER_ADDRESS, EVM_GAS_MANAGER_ADDRESS, L2_ASSET_ROUTER_ADDRESS, L2_BRIDGEHUB_ADDRESS,
L2_GENESIS_UPGRADE_ADDRESS, L2_MESSAGE_ROOT_ADDRESS, L2_NATIVE_TOKEN_VAULT_ADDRESS,
L2_WRAPPED_BASE_TOKEN_IMPL, P256VERIFY_PRECOMPILE_ADDRESS, PUBDATA_CHUNK_PUBLISHER_ADDRESS,
SLOAD_CONTRACT_ADDRESS,
L2_WRAPPED_BASE_TOKEN_IMPL, PUBDATA_CHUNK_PUBLISHER_ADDRESS,
SECP256R1_VERIFY_PRECOMPILE_ADDRESS, SLOAD_CONTRACT_ADDRESS,
};

use crate::{
Expand Down Expand Up @@ -115,7 +115,7 @@ static SYSTEM_CONTRACT_LIST: [(&str, &str, Address, ContractLanguage); 33] = [
(
"precompiles/",
"P256Verify",
P256VERIFY_PRECOMPILE_ADDRESS,
SECP256R1_VERIFY_PRECOMPILE_ADDRESS,
ContractLanguage::Yul,
),
(
Expand Down
20 changes: 20 additions & 0 deletions core/lib/vm_interface/src/types/outputs/statistic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ pub struct CircuitStatistic {
pub secp256k1_verify: f32,
#[serde(default)]
pub transient_storage_checker: f32,
#[serde(default)]
pub modexp: f32,
#[serde(default)]
pub ecadd: f32,
#[serde(default)]
pub ecmul: f32,
#[serde(default)]
pub ecpairing: f32,
}

impl CircuitStatistic {
Expand All @@ -47,6 +55,10 @@ impl CircuitStatistic {
+ self.sha256.ceil() as usize
+ self.secp256k1_verify.ceil() as usize
+ self.transient_storage_checker.ceil() as usize
+ self.modexp as usize
+ self.ecadd as usize
+ self.ecmul as usize
+ self.ecpairing as usize
}

/// Adds numbers.
Expand All @@ -64,6 +76,10 @@ impl CircuitStatistic {
+ self.sha256
+ self.secp256k1_verify
+ self.transient_storage_checker
+ self.modexp
+ self.ecadd
+ self.ecmul
+ self.ecpairing
}
}

Expand All @@ -86,6 +102,10 @@ impl ops::Add for CircuitStatistic {
secp256k1_verify: self.secp256k1_verify + other.secp256k1_verify,
transient_storage_checker: self.transient_storage_checker
+ other.transient_storage_checker,
modexp: self.modexp + other.modexp,
ecadd: self.ecadd + other.ecadd,
ecmul: self.ecmul + other.ecmul,
ecpairing: self.ecpairing + other.ecpairing,
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,20 +176,22 @@ impl JobManager for RecursionTip {
queue_set[index] = take_sponge_like_queue_state_from_simulator(recursion_queue);
}

const EXPECTED_RECURSION_TIP_LEAVES: usize = 16;

let leaf_vk_commits = get_leaf_vk_params(&keystore).context("get_leaf_vk_params()")?;
assert_eq!(
leaf_vk_commits.len(),
16,
EXPECTED_RECURSION_TIP_LEAVES,
"expected 16 leaf vk commits, which corresponds to the numebr of circuits, got {}",
leaf_vk_commits.len()
);
let leaf_layer_parameters: [RecursionLeafParametersWitness<GoldilocksField>; 16] =
leaf_vk_commits
.iter()
.map(|el| el.1.clone())
.collect::<Vec<_>>()
.try_into()
.unwrap();
let leaf_layer_parameters: [RecursionLeafParametersWitness<GoldilocksField>;
EXPECTED_RECURSION_TIP_LEAVES] = leaf_vk_commits
.iter()
.map(|el| el.1.clone())
.collect::<Vec<_>>()
.try_into()
.unwrap();

let input = RecursionTipInputWitness {
leaf_layer_parameters,
Expand Down
Loading