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

set_refund_for_current_tx #2361

Merged
merged 2 commits into from
Jul 2, 2024
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
1 change: 1 addition & 0 deletions core/lib/multivm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ anyhow.workspace = true
hex.workspace = true
itertools.workspace = true
once_cell.workspace = true
pretty_assertions.workspace = true
serde.workspace = true
thiserror.workspace = true
tracing.workspace = true
Expand Down
16 changes: 5 additions & 11 deletions core/lib/multivm/src/versions/shadow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::{
fmt,
};

use pretty_assertions::assert_eq;
montekki marked this conversation as resolved.
Show resolved Hide resolved
use zksync_state::{ReadStorage, StoragePtr};
use zksync_types::{StorageKey, StorageLogWithPreviousValue, Transaction, U256};
use zksync_utils::bytecode::CompressedBytecodeInfo;
Expand Down Expand Up @@ -147,17 +148,10 @@ where
&main_batch.final_execution_state,
&shadow_batch.final_execution_state,
);

let mut main_bootloader_memory = main_batch.final_bootloader_memory.clone();
if let Some(memory) = &mut main_bootloader_memory {
for (slot, value) in memory {
if *slot == 111 {
// FIXME: this particular memory slot (`OPERATOR_REFUNDS_OFFSET`) differs and is always zero for the new VM
*value = U256::zero();
}
}
}
assert_eq!(main_bootloader_memory, shadow_batch.final_bootloader_memory);
assert_eq!(
main_batch.final_bootloader_memory,
shadow_batch.final_bootloader_memory
);
assert_eq!(main_batch.pubdata_input, shadow_batch.pubdata_input);
assert_eq!(main_batch.state_diffs, shadow_batch.state_diffs);
main_batch
Expand Down
11 changes: 9 additions & 2 deletions core/lib/multivm/src/versions/vm_fast/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ impl<S: ReadStorage> Vm<S> {
operator_suggested_refund: 0,
};
let mut last_tx_result = None;
let mut pubdata_before = self.inner.world_diff.pubdata.0 as u32;

let result = loop {
let hook = match self.inner.resume_from(self.suspended_at, &mut self.world) {
Expand Down Expand Up @@ -152,7 +153,7 @@ impl<S: ReadStorage> Vm<S> {
gas_spent_on_pubdata.as_u64(),
tx_gas_limit,
gas_per_pubdata_byte.low_u32(),
pubdata_published,
pubdata_published - pubdata_before,
self.bootloader_state
.last_l2_block()
.txs
Expand All @@ -161,10 +162,14 @@ impl<S: ReadStorage> Vm<S> {
.hash,
);

pubdata_before = pubdata_published;
let refund_value = refund.operator_suggested_refund;
self.write_to_bootloader_heap([(
OPERATOR_REFUNDS_OFFSET + current_tx_index,
refund.operator_suggested_refund.into(),
refund_value.into(),
)]);
self.bootloader_state
.set_refund_for_current_tx(refund_value);
}
}
NotifyAboutRefund => {
Expand Down Expand Up @@ -310,6 +315,7 @@ impl<S: ReadStorage> Vm<S> {
/// Typically used to read the bootloader heap. We know that we're in the bootloader
/// when a hook occurs, as they are only enabled when preprocessing bootloader code.
pub(crate) fn read_heap_word(&self, word: usize) -> U256 {
// TODO: this should probably address `vm2::FIRST_HEAP` instead.
self.inner.state.heaps[self.inner.state.current_frame.heap].read_u256(word as u32 * 32)
}

Expand All @@ -318,6 +324,7 @@ impl<S: ReadStorage> Vm<S> {
memory: impl IntoIterator<Item = (usize, U256)>,
) {
assert!(self.inner.state.previous_frames.is_empty());
// TODO: this should probably address `vm2::FIRST_HEAP` instead.
let heap = &mut self.inner.state.heaps[self.inner.state.current_frame.heap];
for (slot, value) in memory {
heap.write_u256(slot as u32 * 32, value);
Expand Down
Loading