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: exposes necessary methods on heap newtype #43

Merged
merged 4 commits into from
Jun 5, 2024
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ u256 = { package = "primitive-types", version = "0.12.1" }
enum_dispatch = "0.3"
arbitrary = { version = "1", features = ["derive"], optional = true }
zk_evm = { git = "https://github.com/matter-labs/era-zk_evm.git", branch = "v1.5.0", optional = true }
anyhow = { optional = true }
anyhow = { version = "1", optional = true }

[dev-dependencies]
divan = "0.1"
Expand Down
24 changes: 24 additions & 0 deletions src/heap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,30 @@ impl HeapId {
#[derive(Debug, Clone, PartialEq)]
pub struct Heap(Vec<u8>);

impl Heap {
pub fn resize(&mut self, new_len: usize, value: u8) {
joonazan marked this conversation as resolved.
Show resolved Hide resolved
self.0.resize(new_len, value);
}

pub fn len(&self) -> usize {
self.0.len()
}
}

impl<Idx: std::slice::SliceIndex<[u8]>> std::ops::Index<Idx> for Heap {
type Output = Idx::Output;

fn index(&self, i: Idx) -> &Self::Output {
self.0.index(i)
}
}

impl<Idx: std::slice::SliceIndex<[u8]>> std::ops::IndexMut<Idx> for Heap {
fn index_mut(&mut self, i: Idx) -> &mut Self::Output {
self.0.index_mut(i)
}
}

impl HeapInterface for Heap {
fn read_u256(&self, start_address: u32) -> U256 {
self.read_u256_partially(start_address..start_address + 32)
Expand Down
Loading