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

fix!: Revise VM storage interface #73

Merged
merged 4 commits into from
Sep 30, 2024
Merged
Changes from 1 commit
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
Prev Previous commit
Constrain changes some more
slowli committed Sep 26, 2024
commit 1340e55e5016e9b680ffc8afe65d50488d065ce9
3 changes: 2 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -49,7 +49,7 @@ jobs:
run: |
# Check the main library with non-test features (needs to be tested in isolation since the fuzzing crate enables test features)
cargo clippy -p zksync_vm2 --all-targets -- -D warnings
# The benches in `vm2` don't compile with fuzzing enabled
# The benches in `vm2` don't compile with fuzzing enabled
cargo clippy --workspace --all-features --lib --bins --tests -- -D warnings

- name: Check formatting
@@ -58,6 +58,7 @@ jobs:

- name: Run tests
run: |
PROPTEST_CASES=10000 \
cargo test -p zksync_vm2_interface -p zksync_vm2 --all-targets

- name: Run doc tests
82 changes: 38 additions & 44 deletions crates/vm2/src/world_diff.rs
Original file line number Diff line number Diff line change
@@ -375,7 +375,7 @@ const COLD_WRITE_AFTER_WARM_READ_REFUND: u32 = STORAGE_ACCESS_COLD_READ_COST;

#[cfg(test)]
mod tests {
use proptest::prelude::*;
use proptest::{bits, collection::btree_map, prelude::*};

use super::*;
use crate::StorageSlot;
@@ -507,59 +507,53 @@ mod tests {
}
}

/// Max items in generated initial storage / changes.
const MAX_ITEMS: usize = 5;
/// Bit mask for bytes in constrained `U256` / `H160` values.
const BIT_MASK: u8 = 0b_1111;

fn arbitrary_initial_storage() -> impl Strategy<Value = BTreeMap<(H160, U256), StorageSlot>> {
any::<Vec<([u8; 20], [u8; 32], [u8; 32], bool)>>().prop_map(|vec| {
vec.into_iter()
.map(|(contract, key, value, is_write_initial)| {
(
(H160::from(contract), U256::from(key)),
StorageSlot {
value: U256::from(value),
is_write_initial,
},
)
})
.collect()
})
btree_map(
any::<([u8; 20], [u8; 32])>()
.prop_map(|(contract, key)| (H160::from(contract), U256::from(key))),
any::<([u8; 32], bool)>().prop_map(|(value, is_write_initial)| StorageSlot {
value: U256::from(value),
is_write_initial,
}),
0..=MAX_ITEMS,
)
}

fn constrained_initial_storage() -> impl Strategy<Value = BTreeMap<(H160, U256), StorageSlot>> {
slowli marked this conversation as resolved.
Show resolved Hide resolved
any::<Vec<(u8, u8, u8, bool)>>().prop_map(|vec| {
vec.into_iter()
.map(|(contract, key, value, is_write_initial)| {
(
(H160::repeat_byte(contract), U256::from(key)),
StorageSlot {
value: U256::from(value),
is_write_initial,
},
)
})
.collect()
})
btree_map(
(bits::u8::masked(BIT_MASK), bits::u8::masked(BIT_MASK))
.prop_map(|(contract, key)| (H160::repeat_byte(contract), U256::from(key))),
(bits::u8::masked(BIT_MASK), any::<bool>()).prop_map(|(value, is_write_initial)| {
StorageSlot {
value: U256::from(value),
is_write_initial,
}
}),
0..=MAX_ITEMS,
)
}

fn arbitrary_storage_changes() -> impl Strategy<Value = BTreeMap<(H160, U256), U256>> {
any::<Vec<([u8; 20], [u8; 32], [u8; 32])>>().prop_map(|vec| {
vec.into_iter()
.map(|(contract, key, value)| {
((H160::from(contract), U256::from(key)), U256::from(value))
})
.collect()
})
btree_map(
any::<([u8; 20], [u8; 32])>()
.prop_map(|(contract, key)| (H160::from(contract), U256::from(key))),
any::<[u8; 32]>().prop_map(U256::from),
0..=MAX_ITEMS,
)
}

fn constrained_storage_changes() -> impl Strategy<Value = BTreeMap<(H160, U256), U256>> {
any::<Vec<(u8, u8, u8)>>().prop_map(|vec| {
vec.into_iter()
.map(|(contract, key, value)| {
(
(H160::repeat_byte(contract), U256::from(key)),
U256::from(value),
)
})
.collect()
})
btree_map(
(bits::u8::masked(BIT_MASK), bits::u8::masked(BIT_MASK))
.prop_map(|(contract, key)| (H160::repeat_byte(contract), U256::from(key))),
bits::u8::masked(BIT_MASK).prop_map(U256::from),
0..=MAX_ITEMS,
)
}

struct NoWorld;