Repository: nexus-xyz/nexus-zkvm
File: vm/src/memory/unified.rs (Rust)

Code before:
            }
            Some(Modes::RO) => {
                if idx < self.fro_store.len() {
                    Ok(self.fro_store[idx].segment_bytes(start, end))
                } else {
                    Err(MemoryError::UndefinedMemoryRegion)
                }
            }
            Some(Modes::WO) => {
                if idx < self.fwo_store.len() {
                    Ok(self.fwo_store[idx].segment_bytes(start, end))
                } else {
                    Err(MemoryError::UndefinedMemoryRegion)
                }
            }
            Some(Modes::NA) => {
                if idx < self.fna_store.len() {
                    Ok(self.fna_store[idx].segment_bytes(start, end))
                } else {
                    Err(MemoryError::UndefinedMemoryRegion)
                }
            }
            _ => Err(MemoryError::UndefinedMemoryRegion),
        }
    }

    /// Returns a cloned FixedMemory<RO> for the given index in the RW store.
    pub fn fixed_memory_as_ro(&self, idx: usize) -> Result<FixedMemory<RO>, MemoryError> {
        if idx < self.frw_store.len() {
            Ok(self.frw_store[idx].clone().into())
        } else {
            Err(MemoryError::UndefinedMemoryRegion)
        }
    }
    /// Returns a cloned FixedMemory<RO> for the given index in the RO store.
    pub fn fixed_memory_ro(&self, idx: usize) -> Result<FixedMemory<RO>, MemoryError> {
        if idx < self.fro_store.len() {
            Ok(self.fro_store[idx].clone())
        } else {
            Err(MemoryError::UndefinedMemoryRegion)
        }
    }
    /// Returns a cloned FixedMemory<NA> for the given index in the WO store.
    pub fn fixed_memory_as_na_from_wo(&self, idx: usize) -> Result<FixedMemory<NA>, MemoryError> {
        if idx < self.fwo_store.len() {
            Ok(self.fwo_store[idx].clone().into())
        } else {
            Err(MemoryError::UndefinedMemoryRegion)
        }
    }
    /// Returns a cloned FixedMemory<NA> for the given index in the NA store.

Review comment (suggestion):
Are these functions being used anywhere anymore? It seems like no. Either they should be used (rather than making the stores themselves `pub` in the underlying struct), or they should be removed.

Code after:
            }
            Some(Modes::RO) => {
                if idx < self.fro_store.len() {
                    Ok(self.fro_store[idx].segment_bytes(start, end))
                } else {
                    Err(MemoryError::UndefinedMemoryRegion)
                }
            }
            Some(Modes::WO) => {
                if idx < self.fwo_store.len() {
                    Ok(self.fwo_store[idx].segment_bytes(start, end))
                } else {
                    Err(MemoryError::UndefinedMemoryRegion)
                }
            }
            Some(Modes::NA) => {
                if idx < self.fna_store.len() {
                    Ok(self.fna_store[idx].segment_bytes(start, end))
                } else {
                    Err(MemoryError::UndefinedMemoryRegion)
                }
            }
            _ => Err(MemoryError::UndefinedMemoryRegion),
        }
    }
}

impl MemoryProcessor for UnifiedMemory {
    /// Writes data to memory.
    ///
    /// # Arguments
    ///
    /// * `address` - The memory address to write to.
    /// * `size` - The size of the write operation.
    /// * `value` - The value to write.
    ///
    /// # Returns
    ///
    /// The value written to memory, or an error if the operation failed.
    fn write(
        &mut self,
        address: u32,
        size: MemAccessSize,
        value: u32,
    ) -> Result<StoreOp, MemoryError> {
        if let Some(meta) = self.meta.get(&address) {
            // Safety: that address is in meta means unwraps and indexing are safe
            match meta {
                Modes::RW => {
                    self.frw_store[*self.frw.get(&address).unwrap()].write(address, size, value)
                }