Skip to content

Commit

Permalink
feat: don't charge for pubdata in Validium mode (#32)
Browse files Browse the repository at this point in the history
* set pubdata constants to 0

* Set  to 0

* Create contract for writing bytes

* Deploy bytes contract

* update full node to use rpc providers

* fmt

* add colored prints

* add better debug logs

* add better logs

* add erc20 contract and update test

* update logs

* print gas used

* Use `ETH_SENDER_SENDER_VALIDIUM_MODE` to check whether we need to charge the pubdata

* wip

* wip 2: just change runtime behavior

* Restore original values

* Add validium example readme (#34)

* Add validium example readme

* update validium.md and change test name

* fmt

---------

Co-authored-by: toni-calvin <[email protected]>

* Only keep changes for vm_latest

* Fix submodule

* Fix integration test license

* change contracts branch

* Remove l1 gas data

* Update submodule branch

* fix: update output readme (#39)

* Update output readme

* Add a note for transactions

* Fix note

* feat: remove logs pubdata (#42)

* remove logs from pubdata

* update comment

* feat: refactor readme example (#44)

* Refactor readme example

* Fix some comments

* Remove validium.md

* Remove debug prints

* Remove debug files

* zk fmt

---------

Co-authored-by: toni-calvin <[email protected]>
Co-authored-by: Ivan Litteri <[email protected]>
Co-authored-by: Jordi <[email protected]>
Co-authored-by: Jordi <[email protected]>
Co-authored-by: Matías Onorato <[email protected]>
Co-authored-by: Antonio Calvín García <[email protected]>
  • Loading branch information
7 people authored Jan 19, 2024
1 parent c5fe842 commit d3f703e
Show file tree
Hide file tree
Showing 26 changed files with 1,384 additions and 250 deletions.
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
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
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

0 comments on commit d3f703e

Please sign in to comment.