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: don't charge for pubdata in Validium mode #32

Merged
merged 31 commits into from
Jan 19, 2024
Merged
Show file tree
Hide file tree
Changes from 28 commits
Commits
Show all changes
31 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
55d04f3
Remove debug prints
Jan 19, 2024
48a90a0
Remove debug files
Jan 19, 2024
5e98b84
zk fmt
Jan 19, 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
Oppen marked this conversation as resolved.
Show resolved Hide resolved
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
ilitteri marked this conversation as resolved.
Show resolved Hide resolved
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");
Copy link

Choose a reason for hiding this comment

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

Debugging statements obviously should not be present in the code that is to be merged.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Of course, there will be a clean PR to your repo when finished

Copy link
Collaborator

Choose a reason for hiding this comment

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

Btw, we'll remove this rn cause is not useful anymore

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());
Copy link

Choose a reason for hiding this comment

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

VM should have no assumptions regarding available environment variables.
In general, the only source of environment variables right now is the zksync_env_config crate.
In the future, we'll have different configuration schemas not based on the env variables (think JSON configs), so you should present configuration in an explicit and serialization-agnostic form.

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
ilitteri marked this conversation as resolved.
Show resolved Hide resolved

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions core/tests/ts-integration/src/diff_validium.txt
ilitteri marked this conversation as resolved.
Show resolved Hide resolved

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions core/tests/ts-integration/src/rollup_output.txt
ilitteri marked this conversation as resolved.
Show resolved Hide resolved

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions core/tests/ts-integration/src/validium_output.txt
ilitteri marked this conversation as resolved.
Show resolved Hide resolved

Large diffs are not rendered by default.

ilitteri marked this conversation as resolved.
Show resolved Hide resolved

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions era-contracts-lambda
Submodule era-contracts-lambda added at 648773
100 changes: 0 additions & 100 deletions validium.md

This file was deleted.

File renamed without changes.
39 changes: 39 additions & 0 deletions validium_mode_example/BytesWriter.abi
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
[
{
"inputs": [
{
"internalType": "bytes",
"name": "_message",
"type": "bytes"
}
],
"stateMutability": "nonpayable",
"type": "constructor"
},
{
"inputs": [],
"name": "readBytes",
"outputs": [
{
"internalType": "bytes",
"name": "",
"type": "bytes"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "bytes",
"name": "_message",
"type": "bytes"
}
],
"name": "writeBytes",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
}
]
Loading
Loading