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

replace instruction table by lookup argument #171

Merged
merged 10 commits into from
Jan 30, 2023
Merged

Conversation

jan-ferdinand
Copy link
Member

@jan-ferdinand jan-ferdinand commented Jan 27, 2023

Replace the Instruction Table with a Lookup Argument, as described here. This decreases the total number of columns by 5, the total number of constraints by 9, and is expected to decrease the number of rows. The last property depends on the concrete program and its input. However, in the worst case, the number of rows remains unchanged.

@jan-ferdinand jan-ferdinand marked this pull request as ready for review January 29, 2023 17:51
fn default() -> Self {
impl AlgebraicExecutionTrace {
pub fn new(program: Program) -> Self {
let instruction_multiplicities = vec![0_u32; program.len()];
Copy link
Collaborator

Choose a reason for hiding this comment

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

I know I made .len() on Program, but in retrospect, this is ambiguous to me:

A program's length could either be the number of instructions, or the number of b-words.

It is actually the number of b-words here, but perhaps .len() could be more clear.

Copy link
Member Author

@jan-ferdinand jan-ferdinand Jan 30, 2023

Choose a reason for hiding this comment

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

We could have a method

/// The total number of instructions in the program. Double-word instructions are counted as one 
/// instruction. See also `.len()`.
pub fn number_of_instructions(&self) -> usize {
    self.clone().into_iter().count()
}

as addition to .len(). I decided against that since it would not be used anywhere. I tried to clarify the behavior of .len() by introducing the doc-string. Thoughts?

Copy link
Collaborator

Choose a reason for hiding this comment

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

We don't have to have a function that never gets called.

I suppose what I'm suggesting is to rename .len() into something unambiguous, like .len_bwords().

Copy link
Member Author

Choose a reason for hiding this comment

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

That makes sense and is in line with the naming scheme in triton-opcodes. I'll refactor accordingly. 👍

Copy link
Collaborator

Choose a reason for hiding this comment

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

Is there ever a context where we need the number of instructions without counting the arguments?

Copy link
Member Author

Choose a reason for hiding this comment

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

Not that I know of.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I guess I'm a little confused about what ambiguity this renaming is supposed to eliminate. What other thing could program length refer to?

Copy link
Member Author

Choose a reason for hiding this comment

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

Precisely the one you were asking about. Method .len() could return either

  • the number of instructions in the program, or
  • the number of base field elements used to encode the program.

The former interpretation is never used in Triton VM. However, that knowledge is highly domain specific – not even I was certain about that. In fact, I spent a non-negligible amount of time debugging and writing unnecessary code for this current PR because the method .len() did not behave as I had expected it to, given both its name and code.

Copy link
Collaborator

@aszepieniec aszepieniec left a comment

Choose a reason for hiding this comment

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

LGTM

fn default() -> Self {
impl AlgebraicExecutionTrace {
pub fn new(program: Program) -> Self {
let instruction_multiplicities = vec![0_u32; program.len()];
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is there ever a context where we need the number of instructions without counting the arguments?

jan-ferdinand and others added 3 commits January 30, 2023 14:42
A `VMState` records the condition “halting“ explicitly. Initialized as
`false`, only executing instruction `halt` sets it to `true`. This
allows de-duplication of logic in the virtual machine's methods `.run()`
and `.simulate()` and correctly throws an error whenever the instruction
pointer is out of bounds.
@jan-ferdinand jan-ferdinand merged commit 543327a into master Jan 30, 2023
@jan-ferdinand jan-ferdinand deleted the instruction_lookup branch January 30, 2023 17:01
jan-ferdinand added a commit that referenced this pull request Mar 10, 2023
- change instructions `read_mem` and `write_mem` (#179) (022245b)
    - `read_mem` now pushes to stack instead of overwriting
    - `write_mem` now pops the written element from stack
- move to Tip5 hash function (#161) (#182) (d40f0b6)
    - this greatly boosts overall prover performance
- replace Instruction Table by Lookup Argument (#171) (543327a)
- rework U32 Table (#181) (09a4c27)
    - link to processor using Lookup Argument (2719030)
- improve clock jump differences check (#177) (04bb5c4 and 9c2f3c0)
- improve parsing of Triton assembly
    - remove old parser (bbe4aa8)
    - introduce `ParsedInstruction`, simplifying parsing (8602892)
    - fix bug in property test (9e4fcb7)
- improve on constant folding in multicircuits (#183) (c1be5bb)
- update to twenty-first v0.18 (#184) (ff972ff)
- improve specification and documentation
    - explain the various cross-table arguments (567efc0)
    - more and better links (a66b20d and 9386878)
- various simplifications and readability improvements
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.

3 participants