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!: boojum integration #112

Merged
merged 144 commits into from
Nov 6, 2023
Merged
Changes from 11 commits
Commits
Show all changes
144 commits
Select commit Hold shift + click to select a range
b2263ee
boojum integration
StanislavBreadless Sep 29, 2023
1ba1b5e
change verifier
StanislavBreadless Sep 29, 2023
9557e3e
roll back changes
StanislavBreadless Sep 29, 2023
6bfa1bf
fix issues with detecting upgrades
StanislavBreadless Oct 1, 2023
14268ba
fix CI
StanislavBreadless Oct 2, 2023
83ac4cf
Merge pull request #141 from matter-labs/sb-fix-boojum-integration
StanislavBreadless Oct 2, 2023
3930c5d
chore(ci): Fixing CI (#150)
mm-zk Oct 4, 2023
2a5c072
feat(prover): Witness change for snark wrapper, updated keys (#151)
mm-zk Oct 4, 2023
d4f292b
feat(boojum): Adding `zk status prover` command (#128)
mm-zk Oct 4, 2023
1625ec2
fix(boojum): Don't pass aggregation_results as recursive aggregation …
mm-zk Oct 4, 2023
867f2bf
feat(boojum): added flag to control prover selection at genesis (#158)
mm-zk Oct 5, 2023
6040e37
fix(prover): Use SNARK wrapper VK for picking prover jobs (#142)
ly0va Oct 5, 2023
2bc95e9
chore: Bump contracts and system-contracts submodules (#160)
ly0va Oct 5, 2023
7608e5f
chore(boojum): Merge main into boojum-integration (#164)
ly0va Oct 5, 2023
16dc31c
sync with main
StanislavBreadless Oct 5, 2023
ff0c387
updated fee model for new state diff compression
koloz193 Oct 6, 2023
e265187
fixed write size calculation
koloz193 Oct 6, 2023
ecad4b6
allow if statement comparison
koloz193 Oct 6, 2023
481e417
update how size is calculated
koloz193 Oct 6, 2023
1026dd5
only charge for difference in bytes if more than already paid
koloz193 Oct 6, 2023
742ec84
fix(boojum): Fix VK in prover_fri_protocol_versions (#174)
ly0va Oct 9, 2023
ab384c2
Merge remote-tracking branch 'origin/main' into lyova-merge-main-into…
ly0va Oct 9, 2023
d2ca29b
Merge pull request #177 from matter-labs/lyova-merge-main-into-boojum
ly0va Oct 9, 2023
9b2b576
store initial seen value and compare to that for charging users
koloz193 Oct 10, 2023
f943c03
remove unused var
koloz193 Oct 10, 2023
e9b9ae7
merge main into boojum integration
StanislavBreadless Oct 11, 2023
35fef5a
remove accidental prints
StanislavBreadless Oct 11, 2023
70bc440
add logs for debugging
StanislavBreadless Oct 11, 2023
958cbaf
hopefully fix revert test
StanislavBreadless Oct 11, 2023
548689b
remove helper console logs
StanislavBreadless Oct 11, 2023
c7153bf
Merge pull request #197 from matter-labs/sb-merge-main-into-boojum-in…
StanislavBreadless Oct 11, 2023
f56e5ed
Merge branch 'boojum-integration' into zk-fees-pubdata
koloz193 Oct 11, 2023
5a015c1
use 1.4.0 in vm crate
StanislavBreadless Oct 12, 2023
9eefd43
Merge pull request #203 from matter-labs/sb-integrate-1-4-0
StanislavBreadless Oct 12, 2023
018a71b
Remove some RocksDB code diff
perekopskiy Oct 12, 2023
1d6fda4
Run migration till the end when initting
perekopskiy Oct 12, 2023
5e7bc64
Merge pull request #210 from matter-labs/fix-boojum-rocksdb
perekopskiy Oct 12, 2023
3014213
reverted changes to old file
koloz193 Oct 16, 2023
616a526
simplified calculation logic
koloz193 Oct 16, 2023
4716fab
store initial values and check for refund amount based on amount of p…
koloz193 Oct 16, 2023
b30f9f8
use query timestamp
koloz193 Oct 17, 2023
e98780f
sync boojum integration with main
StanislavBreadless Oct 17, 2023
894b323
fix unit tests
StanislavBreadless Oct 18, 2023
341d484
Merge branch 'boojum-integration' into zk-fees-pubdata
koloz193 Oct 18, 2023
6d60703
use full mode in revert test
StanislavBreadless Oct 18, 2023
0ea94d2
remove unneeded print
StanislavBreadless Oct 18, 2023
2a67ab7
fix fee test
StanislavBreadless Oct 18, 2023
4c2d597
support commitments for next version
StanislavBreadless Oct 18, 2023
71ffe99
Merge pull request #253 from matter-labs/sb-merge-main-into-boojum
ly0va Oct 18, 2023
e798ba7
merge boojum
koloz193 Oct 19, 2023
3da317c
updated cargo lock and removed duplicate const
koloz193 Oct 19, 2023
42ab3ae
removed unnecessary calls
koloz193 Oct 20, 2023
b235187
Merge pull request #168 from matter-labs/zk-fees-pubdata
koloz193 Oct 20, 2023
744197a
Merge remote-tracking branch 'origin/main' into boojum-integration
ly0va Oct 25, 2023
83eb614
Remove legacy types and keep only new types
Deniallugo Oct 25, 2023
2530061
feat: contracts submodules linting commands
benceharomi Oct 25, 2023
f802bf3
fmt: json, yaml extensions added to prettier
benceharomi Oct 25, 2023
0967ba0
fmt: json and yaml files formatted
benceharomi Oct 25, 2023
db4ff0f
lint: sol lint rule update + submodule ignore
benceharomi Oct 25, 2023
13a15ca
Revert "fmt: json and yaml files formatted"
benceharomi Oct 25, 2023
2639834
Revert "fmt: json, yaml extensions added to prettier"
benceharomi Oct 25, 2023
574cde7
Fix state_keeper tests
ly0va Oct 25, 2023
f071cff
Fix eth_watch unit tests
ly0va Oct 25, 2023
37fc6bd
Fix empty system logs
ly0va Oct 26, 2023
12ffbf5
updated storage oracle to calculate pubdata bytes correctly
koloz193 Oct 26, 2023
3628d62
Merge branch 'main' into lyova-merge-main-into-boojum-again
koloz193 Oct 26, 2023
f7ac2de
resolved merge conflicts
koloz193 Oct 26, 2023
69c7b9e
Fix some lints
ly0va Oct 27, 2023
af07c50
remove unused variable
koloz193 Oct 27, 2023
fc0fd77
Fix invalid error log
ly0va Oct 27, 2023
5e7cc1c
Fix more lints
ly0va Oct 30, 2023
0cecd94
Merge remote-tracking branch 'origin/main' into lyova-merge-main-into…
ly0va Oct 30, 2023
86655f2
Fix zk compile
ly0va Oct 30, 2023
a99026e
Bump era-contracts
ly0va Oct 30, 2023
830d719
Merge pull request #307 from matter-labs/lyova-merge-main-into-boojum…
ly0va Oct 30, 2023
90d3b63
sync with latest release
StanislavBreadless Nov 1, 2023
1b9feae
update scripts to use the correct facets
StanislavBreadless Nov 1, 2023
222ae96
sync boojum integration with main
StanislavBreadless Nov 2, 2023
2fb9d43
add initial protocol version
StanislavBreadless Nov 2, 2023
293cc9d
upd unit tests
StanislavBreadless Nov 2, 2023
487404c
fix ext node
StanislavBreadless Nov 2, 2023
eb44921
fix compilation
StanislavBreadless Nov 2, 2023
4dd00c9
fix rust unit tests
StanislavBreadless Nov 2, 2023
7dee1e3
Merge pull request #383 from matter-labs/sb-sync-boojum-integration-main
StanislavBreadless Nov 2, 2023
fdf8906
Add the VmBoojumIntegration version
ly0va Nov 2, 2023
c3c5c7d
cherry-pick: Temporarily comment out contract-verification test (#377)
ly0va Nov 2, 2023
27f76f0
Merge branch 'boojum-integration' into bh-evm-294-synchronise-linting…
benceharomi Nov 2, 2023
9c7706d
Fix interaction with core
ly0va Nov 2, 2023
04a0802
sync with updated linting
StanislavBreadless Nov 2, 2023
4787e86
nit for better compilation
StanislavBreadless Nov 2, 2023
27eaf9b
Use zkevm 1.4.0
Deniallugo Nov 2, 2023
041a67d
fix unit tests
StanislavBreadless Nov 2, 2023
92d8235
Merge pull request #393 from matter-labs/deniallugo-use-zkevm-v140
Deniallugo Nov 2, 2023
d5c0299
Merge branch 'boojum-integration' into more-vm-for-the-multivm-god
ly0va Nov 2, 2023
f3532ad
update hardhat package everywhere
StanislavBreadless Nov 2, 2023
f848c44
fix lints
StanislavBreadless Nov 3, 2023
9fb881d
Update compiler.ts
benceharomi Nov 3, 2023
0cff45d
@typescript-eslint/eslint-plugin updated
benceharomi Nov 3, 2023
aa54e7a
fixed eslint errors
benceharomi Nov 3, 2023
517e707
Merge pull request #376 from matter-labs/sb-sync-with-release-contracts
StanislavBreadless Nov 3, 2023
f032c89
basic merge (no compilation)
StanislavBreadless Nov 3, 2023
3337e5e
correct protocol version
StanislavBreadless Nov 3, 2023
0cd8883
Add new bootloaders
ly0va Nov 3, 2023
9d11bfd
Fix unfortunate wildcard match
ly0va Nov 3, 2023
8603a1b
Restore tests
ly0va Nov 3, 2023
5001075
cherry-pick: Make calculation for pubdata a bit more percise (#392)
Deniallugo Nov 2, 2023
063874f
Merge remote-tracking branch 'origin/main' into sb-sync-main-boojum-i…
ly0va Nov 3, 2023
0dd3741
Fix test
ly0va Nov 3, 2023
2288bea
Merge pull request #406 from matter-labs/sb-sync-main-boojum-integration
StanislavBreadless Nov 3, 2023
64eec23
Update old refund tracer
ly0va Nov 3, 2023
e364a4f
Fix lints
ly0va Nov 3, 2023
345b4e6
update boojum contracts
StanislavBreadless Nov 3, 2023
ee82e3e
Merge pull request #391 from matter-labs/more-vm-for-the-multivm-god
ly0va Nov 3, 2023
b3ff655
make the latest contracts work
StanislavBreadless Nov 3, 2023
cd68718
Merge pull request #407 from matter-labs/sb-update-contracts
StanislavBreadless Nov 3, 2023
9bf4468
use contracts from main
StanislavBreadless Nov 5, 2023
b4eaf7d
Merge pull request #411 from matter-labs/sb-use-contracts-from-main
StanislavBreadless Nov 6, 2023
7360070
fix vm nits
StanislavBreadless Nov 6, 2023
155dea7
fix PR comments 2
StanislavBreadless Nov 6, 2023
3ca96fc
different types for system and user logs
StanislavBreadless Nov 6, 2023
c16a222
fix errors
StanislavBreadless Nov 6, 2023
4a77b9c
add unit test for pubdata
StanislavBreadless Nov 6, 2023
8e06c95
do not override old api bootloader
StanislavBreadless Nov 6, 2023
78342c2
use static dispatch
StanislavBreadless Nov 6, 2023
f01187c
fix lint
StanislavBreadless Nov 6, 2023
f14e7b5
panic formatting
StanislavBreadless Nov 6, 2023
d0ebfea
enum for prover at genesis
StanislavBreadless Nov 6, 2023
e7879b0
Some fixes
perekopskiy Nov 6, 2023
a5b5135
more thorough replacement of logs -> user/system logs
StanislavBreadless Nov 6, 2023
af87590
rollback changes in core/lib/types/src/eth_sender.rs
StanislavBreadless Nov 6, 2023
911596e
link todo task
StanislavBreadless Nov 6, 2023
a28ab30
fix
perekopskiy Nov 6, 2023
75f427d
make rust lints pass
StanislavBreadless Nov 6, 2023
e728767
remove unneeded metrics import
StanislavBreadless Nov 6, 2023
ac9c6e2
Merge pull request #415 from matter-labs/sb-fixes-for-pr
StanislavBreadless Nov 6, 2023
df92671
Rename
perekopskiy Nov 6, 2023
c0dba4a
Merge pull request #416 from matter-labs/perekopskiy-fix-boojum-diff-…
perekopskiy Nov 6, 2023
3739b02
use contracts from main
StanislavBreadless Nov 6, 2023
e3f60aa
todo notice
StanislavBreadless Nov 6, 2023
e596008
Merge pull request #420 from matter-labs/sb-use-main-contracts
StanislavBreadless Nov 6, 2023
68be91d
Merge pull request #421 from matter-labs/main
StanislavBreadless Nov 6, 2023
39fb338
fix mps comments
StanislavBreadless Nov 6, 2023
76eb720
resolve linting
StanislavBreadless Nov 6, 2023
e61d9e5
Merge pull request #422 from matter-labs/sb-fix-mp-coments
StanislavBreadless Nov 6, 2023
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
12 changes: 12 additions & 0 deletions core/lib/contracts/src/lib.rs
Original file line number Diff line number Diff line change
@@ -359,6 +359,11 @@ impl BaseSystemContracts {
BaseSystemContracts::load_with_bootloader(bootloader_bytecode)
}

pub fn playground_post_boojum() -> Self {
let bootloader_bytecode = read_zbin_bytecode("etc/multivm_bootloaders/vm_boojum_integration/playground_batch.yul/playground_batch.yul.zbin");
BaseSystemContracts::load_with_bootloader(bootloader_bytecode)
}

/// BaseSystemContracts with playground bootloader - used for handling 'eth_calls'.
pub fn estimate_gas() -> Self {
let bootloader_bytecode = read_bootloader_code("fee_estimate");
@@ -386,6 +391,13 @@ impl BaseSystemContracts {
BaseSystemContracts::load_with_bootloader(bootloader_bytecode)
}

pub fn estimate_gas_post_boojum() -> Self {
let bootloader_bytecode = read_zbin_bytecode(
"etc/multivm_bootloaders/vm_boojum_integration/fee_estimate.yul/fee_estimate.yul.zbin",
);
BaseSystemContracts::load_with_bootloader(bootloader_bytecode)
}

pub fn hashes(&self) -> BaseSystemContractsHashes {
BaseSystemContractsHashes {
bootloader: self.bootloader.hash,
6 changes: 4 additions & 2 deletions core/lib/multivm/src/glue/block_properties.rs
Original file line number Diff line number Diff line change
@@ -33,9 +33,11 @@ impl BlockProperties {
};
Self::Vm1_3_2(inner)
}
VmVersion::VmVirtualBlocks | VmVersion::VmVirtualBlocksRefundsEnhancement => {
VmVersion::VmVirtualBlocks
| VmVersion::VmVirtualBlocksRefundsEnhancement
| VmVersion::VmBoojumIntegration => {
unreachable!(
"From VmVirtualBlocks we have another initialization logic, \
"Starting from VmVirtualBlocks we have another initialization logic, \
so it's not required to have BlockProperties for it"
)
}
24 changes: 21 additions & 3 deletions core/lib/multivm/src/glue/history_mode.rs
Original file line number Diff line number Diff line change
@@ -6,11 +6,13 @@ pub trait HistoryMode:
+ GlueInto<Self::Vm1_3_2Mode>
+ GlueInto<Self::VmVirtualBlocksMode>
+ GlueInto<Self::VmVirtualBlocksRefundsEnhancement>
+ GlueInto<Self::VmBoojumIntegration>
{
type VmM6Mode: crate::vm_m6::HistoryMode;
type Vm1_3_2Mode: crate::vm_1_3_2::HistoryMode;
type VmVirtualBlocksMode: crate::vm_virtual_blocks::HistoryMode;
type VmVirtualBlocksRefundsEnhancement: crate::vm_latest::HistoryMode;
type VmVirtualBlocksRefundsEnhancement: crate::vm_refunds_enhancement::HistoryMode;
type VmBoojumIntegration: crate::vm_latest::HistoryMode;
}

impl GlueFrom<crate::vm_latest::HistoryEnabled> for crate::vm_m6::HistoryEnabled {
@@ -31,6 +33,12 @@ impl GlueFrom<crate::vm_latest::HistoryEnabled> for crate::vm_virtual_blocks::Hi
}
}

impl GlueFrom<crate::vm_latest::HistoryEnabled> for crate::vm_refunds_enhancement::HistoryEnabled {
fn glue_from(_: crate::vm_latest::HistoryEnabled) -> Self {
Self
}
}

impl GlueFrom<crate::vm_latest::HistoryDisabled> for crate::vm_m6::HistoryDisabled {
fn glue_from(_: crate::vm_latest::HistoryDisabled) -> Self {
Self
@@ -49,16 +57,26 @@ impl GlueFrom<crate::vm_latest::HistoryDisabled> for crate::vm_virtual_blocks::H
}
}

impl GlueFrom<crate::vm_latest::HistoryDisabled>
for crate::vm_refunds_enhancement::HistoryDisabled
{
fn glue_from(_: crate::vm_latest::HistoryDisabled) -> Self {
Self
}
}

impl HistoryMode for crate::vm_latest::HistoryEnabled {
type VmM6Mode = crate::vm_m6::HistoryEnabled;
type Vm1_3_2Mode = crate::vm_1_3_2::HistoryEnabled;
type VmVirtualBlocksMode = crate::vm_virtual_blocks::HistoryEnabled;
type VmVirtualBlocksRefundsEnhancement = crate::vm_latest::HistoryEnabled;
type VmVirtualBlocksRefundsEnhancement = crate::vm_refunds_enhancement::HistoryEnabled;
type VmBoojumIntegration = crate::vm_latest::HistoryEnabled;
}

impl HistoryMode for crate::vm_latest::HistoryDisabled {
type VmM6Mode = crate::vm_m6::HistoryDisabled;
type Vm1_3_2Mode = crate::vm_1_3_2::HistoryDisabled;
type VmVirtualBlocksMode = crate::vm_virtual_blocks::HistoryDisabled;
type VmVirtualBlocksRefundsEnhancement = crate::vm_latest::HistoryDisabled;
type VmVirtualBlocksRefundsEnhancement = crate::vm_refunds_enhancement::HistoryDisabled;
type VmBoojumIntegration = crate::vm_latest::HistoryDisabled;
}
16 changes: 15 additions & 1 deletion core/lib/multivm/src/glue/init_vm.rs
Original file line number Diff line number Diff line change
@@ -164,7 +164,7 @@ impl<S: ReadStorage, H: HistoryMode> VmInstance<S, H> {
}
}
VmVersion::VmVirtualBlocksRefundsEnhancement => {
let vm = crate::vm_latest::Vm::new(
let vm = crate::vm_refunds_enhancement::Vm::new(
l1_batch_env.glue_into(),
system_env.clone(),
storage_view.clone(),
@@ -177,6 +177,20 @@ impl<S: ReadStorage, H: HistoryMode> VmInstance<S, H> {
last_tx_compressed_bytecodes: vec![],
}
}
VmVersion::VmBoojumIntegration => {
let vm = crate::vm_latest::Vm::new(
l1_batch_env.glue_into(),
system_env.clone(),
storage_view.clone(),
H::VmBoojumIntegration::default(),
);
let vm = VmInstanceVersion::VmBoojumIntegration(Box::new(vm));
Self {
vm,
system_env,
last_tx_compressed_bytecodes: vec![],
}
}
}
}
}
3 changes: 2 additions & 1 deletion core/lib/multivm/src/glue/oracle_tools.rs
Original file line number Diff line number Diff line change
@@ -31,7 +31,8 @@ where
}
VmVersion::VmVirtualBlocks
| VmVersion::VmVirtualBlocksRefundsEnhancement
| VmVersion::Vm1_3_2 => {
| VmVersion::Vm1_3_2
| VmVersion::VmBoojumIntegration => {
panic!("oracle tools for after VM1.3.2 do not exist")
}
}
21 changes: 12 additions & 9 deletions core/lib/multivm/src/glue/tracer.rs
Original file line number Diff line number Diff line change
@@ -42,7 +42,7 @@ use crate::HistoryMode;
use zksync_state::WriteStorage;

pub trait MultivmTracer<S: WriteStorage, H: HistoryMode>:
IntoLatestTracer<S, H> + IntoVmVirtualBlocksTracer<S, H>
IntoLatestTracer<S, H> + IntoVmVirtualBlocksTracer<S, H> + IntoVmRefundsEnhancementTracer<S, H>
{
fn into_boxed(self) -> Box<dyn MultivmTracer<S, H>>
where
@@ -53,9 +53,7 @@ pub trait MultivmTracer<S: WriteStorage, H: HistoryMode>:
}

pub trait IntoLatestTracer<S: WriteStorage, H: HistoryMode> {
fn latest(
&self,
) -> Box<dyn crate::vm_latest::VmTracer<S, H::VmVirtualBlocksRefundsEnhancement>>;
fn latest(&self) -> Box<dyn crate::vm_latest::VmTracer<S, H::VmBoojumIntegration>>;
}

pub trait IntoVmVirtualBlocksTracer<S: WriteStorage, H: HistoryMode> {
@@ -64,15 +62,19 @@ pub trait IntoVmVirtualBlocksTracer<S: WriteStorage, H: HistoryMode> {
) -> Box<dyn crate::vm_virtual_blocks::VmTracer<S, H::VmVirtualBlocksMode>>;
}

pub trait IntoVmRefundsEnhancementTracer<S: WriteStorage, H: HistoryMode> {
fn vm_refunds_enhancement(
&self,
) -> Box<dyn crate::vm_refunds_enhancement::VmTracer<S, H::VmVirtualBlocksRefundsEnhancement>>;
}

impl<S, T, H> IntoLatestTracer<S, H> for T
where
S: WriteStorage,
H: HistoryMode,
T: crate::vm_latest::VmTracer<S, H::VmVirtualBlocksRefundsEnhancement> + Clone + 'static,
T: crate::vm_latest::VmTracer<S, H::VmBoojumIntegration> + Clone + 'static,
{
fn latest(
&self,
) -> Box<dyn crate::vm_latest::VmTracer<S, H::VmVirtualBlocksRefundsEnhancement>> {
fn latest(&self) -> Box<dyn crate::vm_latest::VmTracer<S, H::VmBoojumIntegration>> {
Box::new(self.clone())
}
}
@@ -81,9 +83,10 @@ impl<S, H, T> MultivmTracer<S, H> for T
where
S: WriteStorage,
H: HistoryMode,
T: crate::vm_latest::VmTracer<S, H::VmVirtualBlocksRefundsEnhancement>
T: crate::vm_latest::VmTracer<S, H::VmBoojumIntegration>
+ IntoLatestTracer<S, H>
+ IntoVmVirtualBlocksTracer<S, H>
+ IntoVmRefundsEnhancementTracer<S, H>
+ Clone
+ 'static,
{
64 changes: 60 additions & 4 deletions core/lib/multivm/src/glue/tracer/implementations.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::glue::tracer::IntoVmVirtualBlocksTracer;
use crate::glue::tracer::{IntoVmRefundsEnhancementTracer, IntoVmVirtualBlocksTracer};
use crate::vm_latest::{CallTracer, StorageInvocations, ValidationTracer};
use zksync_state::WriteStorage;

@@ -16,7 +16,7 @@ where
}
}

impl<S, H> IntoVmVirtualBlocksTracer<S, H> for CallTracer<H::VmVirtualBlocksRefundsEnhancement>
impl<S, H> IntoVmVirtualBlocksTracer<S, H> for CallTracer<H::VmBoojumIntegration>
where
H: crate::HistoryMode + 'static,
S: WriteStorage,
@@ -31,8 +31,7 @@ where
}
}

impl<S, H> IntoVmVirtualBlocksTracer<S, H>
for ValidationTracer<H::VmVirtualBlocksRefundsEnhancement>
impl<S, H> IntoVmVirtualBlocksTracer<S, H> for ValidationTracer<H::VmBoojumIntegration>
where
H: crate::HistoryMode + 'static,
S: WriteStorage,
@@ -54,3 +53,60 @@ where
))
}
}

impl<S, H> IntoVmRefundsEnhancementTracer<S, H> for StorageInvocations
where
H: crate::HistoryMode,
S: WriteStorage,
{
fn vm_refunds_enhancement(
&self,
) -> Box<dyn crate::vm_refunds_enhancement::VmTracer<S, H::VmVirtualBlocksRefundsEnhancement>>
{
Box::new(crate::vm_refunds_enhancement::StorageInvocations::new(
self.limit,
))
}
}

impl<S, H> IntoVmRefundsEnhancementTracer<S, H> for CallTracer<H::VmBoojumIntegration>
where
H: crate::HistoryMode + 'static,
S: WriteStorage,
{
fn vm_refunds_enhancement(
&self,
) -> Box<dyn crate::vm_refunds_enhancement::VmTracer<S, H::VmVirtualBlocksRefundsEnhancement>>
{
Box::new(crate::vm_refunds_enhancement::CallTracer::new(
self.result.clone(),
H::VmVirtualBlocksRefundsEnhancement::default(),
))
}
}

impl<S, H> IntoVmRefundsEnhancementTracer<S, H> for ValidationTracer<H::VmBoojumIntegration>
where
H: crate::HistoryMode + 'static,
S: WriteStorage,
{
fn vm_refunds_enhancement(
&self,
) -> Box<dyn crate::vm_refunds_enhancement::VmTracer<S, H::VmVirtualBlocksRefundsEnhancement>>
{
let params = self.params();
Box::new(
crate::vm_refunds_enhancement::ValidationTracer::new(
crate::vm_refunds_enhancement::ValidationTracerParams {
user_address: params.user_address,
paymaster_address: params.paymaster_address,
trusted_slots: params.trusted_slots,
trusted_addresses: params.trusted_addresses,
trusted_address_slots: params.trusted_address_slots,
computational_gas_limit: params.computational_gas_limit,
},
)
.0,
)
}
}
1 change: 1 addition & 0 deletions core/lib/multivm/src/lib.rs
Original file line number Diff line number Diff line change
@@ -22,4 +22,5 @@ pub use versions::vm_1_3_2;
pub use versions::vm_latest;
pub use versions::vm_m5;
pub use versions::vm_m6;
pub use versions::vm_refunds_enhancement;
pub use versions::vm_virtual_blocks;
1 change: 1 addition & 0 deletions core/lib/multivm/src/versions/mod.rs
Original file line number Diff line number Diff line change
@@ -2,4 +2,5 @@ pub mod vm_1_3_2;
pub mod vm_latest;
pub mod vm_m5;
pub mod vm_m6;
pub mod vm_refunds_enhancement;
pub mod vm_virtual_blocks;
15 changes: 10 additions & 5 deletions core/lib/multivm/src/versions/vm_latest/oracles/storage.rs
Original file line number Diff line number Diff line change
@@ -125,7 +125,7 @@ impl<S: WriteStorage, H: HistoryMode> StorageOracle<S, H> {
query
}

pub fn write_value(&mut self, mut query: LogQuery) -> LogQuery {
pub fn write_value(&mut self, query: LogQuery) -> LogQuery {
let key = triplet_to_storage_key(query.shard_id, query.address, query.key);
let current_value =
self.storage
@@ -138,8 +138,6 @@ impl<S: WriteStorage, H: HistoryMode> StorageOracle<S, H> {
StorageLogQueryType::RepeatedWrite
};

query.read_value = current_value;

self.set_initial_value(&key, current_value, query.timestamp);

let mut storage_log_query = StorageLogQuery {
@@ -320,7 +318,7 @@ impl<S: WriteStorage, H: HistoryMode> VmStorageOracle for StorageOracle<S, H> {
fn execute_partial_query(
&mut self,
_monotonic_cycle_counter: u32,
query: LogQuery,
mut query: LogQuery,
) -> LogQuery {
// tracing::trace!(
// "execute partial query cyc {:?} addr {:?} key {:?}, rw {:?}, wr {:?}, tx {:?}",
@@ -335,6 +333,8 @@ impl<S: WriteStorage, H: HistoryMode> VmStorageOracle for StorageOracle<S, H> {
if query.rw_flag {
// The number of bytes that have been compensated by the user to perform this write
let storage_key = storage_key_of_log(&query);
let read_value = self.storage.read_from_storage(&storage_key);
query.read_value = read_value;

// It is considered that the user has paid for the whole base price for the writes
let to_pay_by_user = self.base_price_for_write_query(&query);
@@ -363,8 +363,13 @@ impl<S: WriteStorage, H: HistoryMode> VmStorageOracle for StorageOracle<S, H> {
_monotonic_cycle_counter: u32,
partial_query: &LogQuery,
) -> RefundType {
let storage_key = storage_key_of_log(partial_query);
let mut partial_query = *partial_query;
let read_value = self.storage.read_from_storage(&storage_key);
partial_query.read_value = read_value;

let price_to_pay = self
.value_update_price(partial_query)
.value_update_price(&partial_query)
.min(INITIAL_STORAGE_WRITE_PUBDATA_BYTES as u32);

let refund = RefundType::RepeatedWrite(RefundedAmounts {
44 changes: 44 additions & 0 deletions core/lib/multivm/src/versions/vm_refunds_enhancement/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# VM Crate

This crate contains code that interacts with the VM (Virtual Machine). The VM itself is in a separate repository
[era-zk_evm][zk_evm_repo_ext].

## VM Dependencies

The VM relies on several subcomponents or traits, such as Memory and Storage. These traits are defined in the `zk_evm`
repository, while their implementations can be found in this crate, such as the storage implementation in
`oracles/storage.rs` and the Memory implementation in `memory.rs`.

Many of these implementations also support easy rollbacks and history, which is useful when creating a block with
multiple transactions and needing to return the VM to a previous state if a transaction doesn't fit.

## Running the VM

To interact with the VM, you must initialize it with `L1BatchEnv`, which represents the initial parameters of the batch,
`SystemEnv`, that represents the system parameters, and a reference to the Storage. To execute a transaction, you have
to push the transaction into the bootloader memory and call the `execute_next_transaction` method.

### Tracers

The VM implementation allows for the addition of `Tracers`, which are activated before and after each instruction. This
provides a more in-depth look into the VM, collecting detailed debugging information and logs. More details can be found
in the `tracer/` directory.

This VM also supports custom tracers. You can call the `inspect_next_transaction` method with a custom tracer and
receive the result of the execution.

### Bootloader

In the context of zkEVM, we usually think about transactions. However, from the VM's perspective, it runs a single
program called the bootloader, which internally processes multiple transactions.

### Rollbacks

The `VMInstance` in `vm.rs` allows for easy rollbacks. You can save the current state at any moment by calling
`make_snapshot()` and return to that state using `rollback_to_the_latest_snapshot()`.

This rollback affects all subcomponents, such as memory, storage, and events, and is mainly used if a transaction
doesn't fit in a block.

[zk_evm_repo]: https://github.com/matter-labs/zk_evm 'internal zk EVM repo'
[zk_evm_repo_ext]: https://github.com/matter-labs/era-zk_evm 'external zk EVM repo'
Loading