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: Use l1 real gas #59

Closed
wants to merge 30 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
c944c92
set pubdata constants to 0
toni-calvin Jan 5, 2024
837cf6f
Set to 0
Jan 5, 2024
181d80c
Merge branch 'validium_mode_pubdata_price' into validium_mode_pubdata_0
Jan 5, 2024
cb7edd8
Create contract for writing bytes
jorbush Jan 9, 2024
714bd35
Deploy bytes contract
jorbush Jan 9, 2024
3f91e20
update full node to use rpc providers
toni-calvin Jan 10, 2024
c3373d2
fmt
toni-calvin Jan 10, 2024
ce4de82
add colored prints
toni-calvin Jan 10, 2024
cc32b58
add better debug logs
toni-calvin Jan 10, 2024
f8edfa4
add better logs
toni-calvin Jan 10, 2024
27ab211
Merge branch 'validium_mode_pubdata_0' of github.com:lambdaclass/zksy…
toni-calvin Jan 11, 2024
240c0a8
add erc20 contract and update test
toni-calvin Jan 12, 2024
c683f9a
update logs
toni-calvin Jan 15, 2024
4699ae9
print gas used
toni-calvin Jan 15, 2024
215b9d9
Use `ETH_SENDER_SENDER_VALIDIUM_MODE` to check whether we need to cha…
Oppen Jan 11, 2024
5d3d96c
wip
Oppen Jan 11, 2024
c71ff9c
wip 2: just change runtime behavior
Oppen Jan 15, 2024
183957d
Restore original values
Oppen Jan 15, 2024
cff8bfd
Add validium example readme (#34)
jordibonet-lambdaclass Jan 15, 2024
5bbeb3c
Only keep changes for vm_latest
Oppen Jan 15, 2024
aad41bb
Fix submodule
Oppen Jan 15, 2024
64e639a
Fix integration test license
Oppen Jan 15, 2024
557ec52
change contracts branch
mationorato Jan 15, 2024
b9ceb92
Remove l1 gas data
Jan 15, 2024
3aa9f50
Update submodule branch
Jan 15, 2024
479061d
fix: update output readme (#39)
jordibonet-lambdaclass Jan 16, 2024
ef48b51
feat: remove logs pubdata (#42)
toni-calvin Jan 16, 2024
5c3dfc5
feat: refactor readme example (#44)
jordibonet-lambdaclass Jan 17, 2024
051b983
set real l1 gas
toni-calvin Jan 18, 2024
8cd527f
fmt
toni-calvin Jan 18, 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
5 changes: 5 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
[submodule "contracts"]
path = contracts
url = https://github.com/matter-labs/era-contracts.git

[submodule "era-contracts-lambda"]
path = era-contracts-lambda
url = https://github.com/lambdaclass/era-contracts.git
branch = validium_mode
37 changes: 25 additions & 12 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 Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ members = [
"sdk/zksync-rs",

# Validium Example
"zksync_full_stack",
"validium_mode_example",
]
resolver = "2"

Expand Down
7 changes: 0 additions & 7 deletions core/lib/multivm/src/versions/vm_latest/old_vm/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use zk_evm_1_4_0::{
},
};
use zksync_state::WriteStorage;
use zksync_system_constants::L1_GAS_PER_PUBDATA_BYTE;
use zksync_types::{Address, U256};

use crate::vm_latest::{
Expand Down Expand Up @@ -96,12 +95,6 @@ pub(crate) fn precompile_calls_count_after_timestamp(
sorted_timestamps.len() - sorted_timestamps.partition_point(|t| *t < from_timestamp)
}

pub(crate) fn eth_price_per_pubdata_byte(l1_gas_price: u64) -> u64 {
// This value will typically be a lot less than u64
// unless the gas price on L1 goes beyond tens of millions of gwei
l1_gas_price * (L1_GAS_PER_PUBDATA_BYTE as u64)
}

pub(crate) fn vm_may_have_ended_inner<S: WriteStorage, H: HistoryMode>(
vm: &ZkSyncVmState<S, H>,
) -> Option<VmExecutionResult> {
Expand Down
12 changes: 10 additions & 2 deletions core/lib/multivm/src/versions/vm_latest/oracles/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -456,9 +456,17 @@ fn get_pubdata_price_bytes(initial_value: U256, final_value: U256, is_initial: b
compress_with_best_strategy(initial_value, final_value).len() as u32;

if is_initial {
(BYTES_PER_DERIVED_KEY as u32) + compressed_value_size
println!("is initial");
let pubdata_price_bytes = (BYTES_PER_DERIVED_KEY as u32) + compressed_value_size;
println!("pubdata_price_bytes: {}", pubdata_price_bytes);
pubdata_price_bytes
// (BYTES_PER_DERIVED_KEY as u32) + compressed_value_size
} else {
(BYTES_PER_ENUMERATION_INDEX as u32) + compressed_value_size
println!("is repeated");
let pubdata_price_bytes = (BYTES_PER_ENUMERATION_INDEX as u32) + compressed_value_size;
println!("pubdata_price_bytes: {}", pubdata_price_bytes);
pubdata_price_bytes
// (BYTES_PER_ENUMERATION_INDEX as u32) + compressed_value_size
}
}

Expand Down
6 changes: 2 additions & 4 deletions core/lib/multivm/src/versions/vm_latest/tracers/refunds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,15 @@ use crate::{
vm_latest::{
bootloader_state::BootloaderState,
constants::{BOOTLOADER_HEAP_PAGE, OPERATOR_REFUNDS_OFFSET, TX_GAS_LIMIT_OFFSET},
old_vm::{
events::merge_events, history_recorder::HistoryMode, memory::SimpleMemory,
utils::eth_price_per_pubdata_byte,
},
old_vm::{events::merge_events, history_recorder::HistoryMode, memory::SimpleMemory},
tracers::{
traits::VmTracer,
utils::{
gas_spent_on_bytecodes_and_long_messages_this_opcode, get_vm_hook_params, VmHook,
},
},
types::internals::ZkSyncVmState,
utils::fee::eth_price_per_pubdata_byte,
},
};

Expand Down
10 changes: 8 additions & 2 deletions core/lib/multivm/src/versions/vm_latest/utils/fee.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
//! Utility functions for vm
use zksync_system_constants::MAX_GAS_PER_PUBDATA_BYTE;
use zksync_system_constants::{L1_GAS_PER_PUBDATA_BYTE, MAX_GAS_PER_PUBDATA_BYTE};
use zksync_utils::ceil_div;

use crate::vm_latest::old_vm::utils::eth_price_per_pubdata_byte;
pub(crate) fn eth_price_per_pubdata_byte(l1_gas_price: u64) -> u64 {
// This value will typically be a lot less than u64
// unless the gas price on L1 goes beyond tens of millions of gwei
// TODO: make this check only once
let validium_mode = std::env::var("ETH_SENDER_SENDER_VALIDIUM_MODE") == Ok("true".to_string());
l1_gas_price * (L1_GAS_PER_PUBDATA_BYTE as u64) * (!validium_mode as u64)
}

/// Calculates the amount of gas required to publish one byte of pubdata
pub fn base_fee_to_gas_per_pubdata(l1_gas_price: u64, base_fee: u64) -> u64 {
Expand Down
14 changes: 7 additions & 7 deletions core/lib/types/src/commitment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,14 +224,14 @@ impl L1BatchWithMetadata {
pub fn construct_pubdata(&self, validium_mode: bool) -> Vec<u8> {
let mut res: Vec<u8> = vec![];

// Process and Pack Logs
res.extend((self.header.l2_to_l1_logs.len() as u32).to_be_bytes());
for l2_to_l1_log in &self.header.l2_to_l1_logs {
res.extend(l2_to_l1_log.0.to_bytes());
}

// We do not want to publish L2->L1 msgs, bytecodes, and state diffs in validium mode.
// We do not want to publish L2-L1 logs, L2->L1 msgs, bytecodes, and state diffs in validium mode.
if !validium_mode {
// Process and Pack Logs
res.extend((self.header.l2_to_l1_logs.len() as u32).to_be_bytes());
for l2_to_l1_log in &self.header.l2_to_l1_logs {
res.extend(l2_to_l1_log.0.to_bytes());
}

// Process and Pack Msgs
res.extend((self.header.l2_to_l1_messages.len() as u32).to_be_bytes());
for msg in &self.header.l2_to_l1_messages {
Expand Down
6 changes: 6 additions & 0 deletions core/tests/ts-integration/src/diff_output.txt

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions core/tests/ts-integration/src/diff_validium.txt

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions core/tests/ts-integration/src/rollup_output.txt

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions core/tests/ts-integration/src/validium_output.txt

Large diffs are not rendered by default.

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions era-contracts-lambda
Submodule era-contracts-lambda added at 648773
49 changes: 25 additions & 24 deletions etc/env/base/eth_sender.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,58 +7,59 @@
# operator_commit_eth_addr is defined in the `private.toml`

# Amount of confirmations required to consider L1 transaction committed.
wait_confirmations=1
wait_confirmations = 1
# Amount of blocks we will wait before considering L1 transaction stuck.
expected_wait_time_block=30
expected_wait_time_block = 30
# Node polling period in seconds.
tx_poll_period=1
tx_poll_period = 1
# Aggregate txs polling period in seconds.
aggregate_tx_poll_period=1
aggregate_tx_poll_period = 1
# The maximum amount of simultaneously sent Ethereum transactions.
max_txs_in_flight=30 # Safe in the local environment, do not repeat on prod (right now it will produce way too many extra calls to web3)
proof_sending_mode="SkipEveryProof"
max_txs_in_flight = 30 # Safe in the local environment, do not repeat on prod (right now it will produce way too many extra calls to web3)
proof_sending_mode = "SkipEveryProof"

# Max L2 blocks to commit in one L1 transaction
max_aggregated_blocks_to_commit=10
max_aggregated_blocks_to_commit = 10
# Max L2 blocks to execute in one L1 transaction
max_aggregated_blocks_to_execute=10
max_aggregated_blocks_to_execute = 10

aggregated_block_commit_deadline=1
aggregated_block_prove_deadline=10
aggregated_block_execute_deadline=10
aggregated_block_commit_deadline = 1
aggregated_block_prove_deadline = 10
aggregated_block_execute_deadline = 10

timestamp_criteria_max_allowed_lag=30
timestamp_criteria_max_allowed_lag = 30

# Based on geth implementation max size of transaction is 128kb.
max_eth_tx_data_size=120000
max_eth_tx_data_size = 120000
# Aggregated proof sizes to be generated by server.
aggregated_proof_sizes=[1,4]
aggregated_proof_sizes = [1, 4]

# Max gas that can be used to execute aggregated operation
# for now (should be > 4kk which is max gas for one block commit/verify/execute)
max_aggregated_tx_gas=4000000
max_aggregated_tx_gas = 4000000

# Max gas that can used to include single block in aggregated operation
max_single_tx_gas=6000000
max_single_tx_gas = 6000000

# Max acceptable fee for sending tx to L1
max_acceptable_priority_fee_in_gwei=100000000000
max_acceptable_priority_fee_in_gwei = 100000000000

proof_loading_mode="OldProofFromDb"
proof_loading_mode = "OldProofFromDb"

[eth_sender.gas_adjuster]
# Priority fee to be used by GasAdjuster (in wei).
default_priority_fee_per_gas=1_000_000_000
default_priority_fee_per_gas = 1_000_000_000
# Max number of base fees from previous blocks to be used to correctly price transactions.
max_base_fee_samples=10_000
max_base_fee_samples = 10_000
# These two are parameters of the base_fee_per_gas formula in GasAdjuster.
# The possible formulas are:
# 1. base_fee_median * (A + B * time_in_mempool)
# 2. base_fee_median * A * B ^ time_in_mempool
# Currently the second is used.
# To confirm, see core/bin/zksync_core/src/eth_sender/gas_adjuster/mod.rs
pricing_formula_parameter_a=1.5
pricing_formula_parameter_b=1.0005
internal_l1_pricing_multiplier=0.8
pricing_formula_parameter_a = 1.5
pricing_formula_parameter_b = 1.0005
internal_l1_pricing_multiplier = 0.8
internal_enforced_l1_gas_price = 30955970638
# Node polling period in seconds.
poll_period=5
poll_period = 5
100 changes: 0 additions & 100 deletions validium.md

This file was deleted.

File renamed without changes.
Loading
Loading