Skip to content

feat: enforce semantics for random access memory ram#1962

Open
OlivierBBB wants to merge 2 commits into
mainfrom
1955-feat-enforce-semantics-for-random-access-memory-ram
Open

feat: enforce semantics for random access memory ram#1962
OlivierBBB wants to merge 2 commits into
mainfrom
1955-feat-enforce-semantics-for-random-access-memory-ram

Conversation

@OlivierBBB

Copy link
Copy Markdown
Contributor

No description provided.

Signed-off-by: Olivier Bégassat <olivier.begassat.cours@gmail.com>
… RAM

The RandomAccess struct needs to store values as TimestampedCell's and
so needs a different generic for its StaticArray's data field than for
the geometry field.

We add fields into RandomAccess to track accesses + a timestamp.
Accesses are logged as a list of AccessData which logs timestamps, value
etc ...

Claude also added some GobDecode/GobEncode methods + various access
methods for the RandomAccess / AccessData

Signed-off-by: Olivier Bégassat <olivier.begassat.cours@gmail.com>
Copilot AI review requested due to automatic review settings July 6, 2026 20:54
@OlivierBBB OlivierBBB linked an issue Jul 6, 2026 that may be closed by this pull request

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds stricter “timestamped RAM” semantics to the VM memory layer, likely to support consistent trace/lookup constraints for RAM accesses.

Changes:

  • Introduces a timestamped-cell backing representation for RandomAccess RAM and logs each read/write as AccessData.
  • Generalizes StaticArray to store an arbitrary cell type (C) rather than always storing W.
  • Adds/extends RAM semantics documentation in ram.md.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
ram.md New documentation describing RAM constraints and implementation notes.
pkg/zkc/vm/internal/memory/wom.go Updates WOM to embed the new 2-parameter StaticArray.
pkg/zkc/vm/internal/memory/static_array.go Generalizes StaticArray to store []C and updates signatures accordingly.
pkg/zkc/vm/internal/memory/rom.go Updates ROM to embed and construct the new 2-parameter StaticArray.
pkg/zkc/vm/internal/memory/ram.go Implements timestamped RAM cells plus per-access logging and gob support for timestamped cells.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +87 to +90
timestampWrite := uint64(ram.timestamp)
// Re-stamp the cell with this access's timestamp.
ram.data = expand(ram.data, address+1)
ram.data[address] = TimestampedCell[W]{timestamp: timestampWrite, value: valueWritten}
Comment on lines +35 to +38
// timestamp; increments by 1 with every memory access
timestamp int
// accesses logs memory accesses in chronological order
accesses []AccessData[W]
Comment on lines +60 to +63
if len(newValue) > 1 || (isWrite && len(newValue) != 1) || (!isWrite && len(newValue) != 0) {
var ignored W
return ignored, fmt.Errorf("invalid access call; isWrite = %v, len(newValues) = %d", isWrite, len(newValue))
}
Comment thread ram.md
Comment on lines +160 to +163
What to do in case of empty RAM ? It shouldn't be an issue in our RV-interpreter.
In the "you only initialize / finalize those cells that you touched" approach
you can force an interaction with address `[]0`, for instance
what
Comment thread ram.md
you can force an interaction with address `[]0`, for instance
what

# Claude additions
Comment on lines 30 to 31
// D is the AddressDecoder strategy that encodes the layout of rows within the
// flat slice.
Comment on lines 31 to 33
// The type parameter W is the word type (e.g. a field element or big.Int), and
// D is the AddressDecoder strategy that encodes the layout of rows within the
// flat slice.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: enforce semantics for Random Access Memory (RAM)

2 participants