Skip to content

Commit

Permalink
refactor!: make instruction names more consistent
Browse files Browse the repository at this point in the history
In particular:
- `xxadd` becomes `xx_add`
- `xxmul` becomes `xx_mul`
- `xbmul` becomes `xb_mul`
- `xinvert` becomes `x_invert`
- `xxdotstep` becomes `xx_dot_step`
- `xbdotstep` becomes `xb_dot_step`

No behavior changes.
  • Loading branch information
jan-ferdinand committed May 5, 2024
1 parent 9b4fd73 commit 96c92ea
Show file tree
Hide file tree
Showing 10 changed files with 138 additions and 138 deletions.
62 changes: 31 additions & 31 deletions specification/src/instruction-groups.md

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions specification/src/instruction-specific-transition-constraints.md
Original file line number Diff line number Diff line change
Expand Up @@ -807,7 +807,7 @@ In addition to its [instruction groups](instruction-groups.md), this instruction
This instruction is fully constrained by its [instruction groups](instruction-groups.md)
Beyond that, correct transition is guaranteed by the [U32 Table](u32-table.md).

## Instruction `xxadd`
## Instruction `xx_add`

In addition to its [instruction groups](instruction-groups.md), this instruction has the following constraints.

Expand Down Expand Up @@ -849,7 +849,7 @@ In addition to its [instruction groups](instruction-groups.md), this instruction
`·(🪤 - 🍋·clk - 🍊 - 🍉·(op_stack_pointer' + 1) - 🫒·st14')`<br/>
`·(🪤 - 🍋·clk - 🍊 - 🍉·(op_stack_pointer' + 2) - 🫒·st13')`

## Instruction `xxmul`
## Instruction `xx_mul`

In addition to its [instruction groups](instruction-groups.md), this instruction has the following constraints.

Expand Down Expand Up @@ -891,7 +891,7 @@ In addition to its [instruction groups](instruction-groups.md), this instruction
`·(🪤 - 🍋·clk - 🍊 - 🍉·(op_stack_pointer' + 1) - 🫒·st14')`<br/>
`·(🪤 - 🍋·clk - 🍊 - 🍉·(op_stack_pointer' + 2) - 🫒·st13')`

## Instruction `xinvert`
## Instruction `x_invert`

In addition to its [instruction groups](instruction-groups.md), this instruction has the following constraints.

Expand All @@ -907,7 +907,7 @@ In addition to its [instruction groups](instruction-groups.md), this instruction
1. `st1·st0' + st0·st1' - st2·st2' + st2·st1' + st1·st2'`
1. `st2·st0' + st1·st1' + st0·st2' + st2·st2'`

## Instruction `xbmul`
## Instruction `xb_mul`

In addition to its [instruction groups](instruction-groups.md), this instruction has the following constraints.

Expand Down Expand Up @@ -991,7 +991,7 @@ In addition to its [instruction groups](instruction-groups.md), this instruction
`+ ind_4(hv3, hv2, hv1, hv0)·(RunningEvaluationStandardOutput' - 🧯·(🧯·(🧯·(🧯·RunningEvaluationStandardOutput - st0) - st1) - st2) - st3)`<br />
`+ ind_5(hv3, hv2, hv1, hv0)·(RunningEvaluationStandardOutput' - 🧯·(🧯·(🧯·(🧯·(🧯·RunningEvaluationStandardOutput - st0) - st1) - st2) - st3) - st4)`

## Instruction `xxdotstep`
## Instruction `xx_dot_step`

In addition to its [instruction groups](instruction-groups.md), this instruction has the following constraints.

Expand All @@ -1002,7 +1002,7 @@ In addition to its [instruction groups](instruction-groups.md), this instruction
1. Add `(hv0 + hv1·x + hv2·x²) · (hv3 + hv4·x + hv5·x²)` into `(st2, st3, st4)`
1. Increase the pointers: `st0` and `st1` by 3 each.

## Instruction `xbdotstep`
## Instruction `xb_dot_step`

In addition to its [instruction groups](instruction-groups.md), this instruction has the following constraints.

Expand All @@ -1011,4 +1011,4 @@ In addition to its [instruction groups](instruction-groups.md), this instruction
1. Store `RAM[st0]` in `hv0`.
1. Store `(RAM[st1], RAM[st1+1], RAM[st1+2])` in `(hv1, hv2, hv3)`.
1. Add `hv0 · (hv1 + hv2·x + hv3·x²)` into `(st1, st2, st3)`
1. Increase the pointers: `st0` and `st1` by 1 and 3, respectively.
1. Increase the pointers: `st0` and `st1` by 1 and 3, respectively.
16 changes: 8 additions & 8 deletions specification/src/instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,10 @@ Triton VM cannot know the number of elements that will be absorbed.

| Instruction | Opcode | old op stack | new op stack | Description |
|:------------|-------:|:----------------|:-------------|:---------------------------------------------------------------------------------------------------------------------------------------------------|
| `xxadd` | 66 | `_ z y x b c a` | `_ w v u` | Adds the two extension field elements encoded by field elements `z y x` and `b c a`. |
| `xxmul` | 74 | `_ z y x b c a` | `_ w v u` | Multiplies the two extension field elements encoded by field elements `z y x` and `b c a`. |
| `xinvert` | 64 | `_ z y x` | `_ w v u` | Inverts the extension field element encoded by field elements `z y x` in-place. Crashes the VM if the extension field element is 0. |
| `xbmul` | 82 | `_ z y x a` | `_ w v u` | Scalar multiplication of the extension field element encoded by field elements `z y x` with field element `a`. Overwrites `z y x` with the result. |
| `xx_add` | 66 | `_ z y x b c a` | `_ w v u` | Adds the two extension field elements encoded by field elements `z y x` and `b c a`. |
| `xx_mul` | 74 | `_ z y x b c a` | `_ w v u` | Multiplies the two extension field elements encoded by field elements `z y x` and `b c a`. |
| `x_invert` | 64 | `_ z y x` | `_ w v u` | Inverts the extension field element encoded by field elements `z y x` in-place. Crashes the VM if the extension field element is 0. |
| `xb_mul` | 82 | `_ z y x a` | `_ w v u` | Scalar multiplication of the extension field element encoded by field elements `z y x` with field element `a`. Overwrites `z y x` with the result. |

## Input/Output

Expand All @@ -149,7 +149,7 @@ Triton VM cannot know the number of elements that will be absorbed.

## Many-In-One

| Instruction | Opcode | old op stack | new op stack | Description |
|:------------|--------|:----------------|:-----------------------------|-------------|
| `xxdotstep` | 72 | `_ z y x *b *a` | `_ z+p2 y+p1 x+p0 *b+3 *a+3` | Reads two extension field elements from RAM located at the addresses corresponding to the two top stack elements, multiplies the extension field elements, and adds the product `(p0, p1, p2)` to an accumulator located on stack immediately below the two pointers. Also, increase the pointers by the number of words read. |
| `xxdotstep` | 80 | `_ z y x *b *a` | `_ z+p2 y+p1 x+p0 *b+3 *a+1` | Reads one base field element from RAM located at the addresses corresponding to the top of the stack, one extension field element from RAM located at the address of the second stack element, multiplies the field elements, and adds the product `(p0, p1, p2)` to an accumulator located on stack immediately below the two pointers. Also, increase the pointers by the number of words read. |
| Instruction | Opcode | old op stack | new op stack | Description |
|:--------------|:-------|:----------------|:-----------------------------|:--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `xx_dot_step` | 72 | `_ z y x *b *a` | `_ z+p2 y+p1 x+p0 *b+3 *a+3` | Reads two extension field elements from RAM located at the addresses corresponding to the two top stack elements, multiplies the extension field elements, and adds the product `(p0, p1, p2)` to an accumulator located on stack immediately below the two pointers. Also, increase the pointers by the number of words read. |
| `xx_dot_step` | 80 | `_ z y x *b *a` | `_ z+p2 y+p1 x+p0 *b+3 *a+1` | Reads one base field element from RAM located at the addresses corresponding to the top of the stack, one extension field element from RAM located at the address of the second stack element, multiplies the field elements, and adds the product `(p0, p1, p2)` to an accumulator located on stack immediately below the two pointers. Also, increase the pointers by the number of words read. |
4 changes: 2 additions & 2 deletions specification/src/registers.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,6 @@ For instruction group [`decompose_arg`](instruction-groups.md#group-decompose_ar
[`divine_sibling`](instruction-specific-transition-constraints.md#helper-variable-definitions-for-divine_sibling),
[`split`](instruction-specific-transition-constraints.md#helper-variable-definitions-for-split),
[`eq`](instruction-specific-transition-constraints.md#helper-variable-definitions-for-eq),
[`xxdotstep`](instruction-specific-transition-constraints.md#instruction-xxdotstep), and
[`xbdotstep`](instruction-specific-transition-constraints.md#instruction-xbdotstep),
[`xx_dot_step`](instruction-specific-transition-constraints.md#instruction-xx_dot_step), and
[`xb_dot_step`](instruction-specific-transition-constraints.md#instruction-xb_dot_step),
the behavior is defined in the respective sections.
2 changes: 1 addition & 1 deletion triton-vm/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ mod tests {

#[test]
fn xfe_inverse_of_zero() {
let program = triton_program!(push 0 push 0 push 0 xinvert halt);
let program = triton_program!(push 0 push 0 push 0 x_invert halt);
let_assert!(Err(err) = program.run([].into(), [].into()));
let_assert!(InstructionError::InverseOfZero = err.source);
}
Expand Down
12 changes: 6 additions & 6 deletions triton-vm/src/instruction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,14 +296,14 @@ impl<Dest: PartialEq + Default> AnInstruction<Dest> {
Pow => "pow",
DivMod => "div_mod",
PopCount => "pop_count",
XxAdd => "xxadd",
XxMul => "xxmul",
XInvert => "xinvert",
XbMul => "xbmul",
XxAdd => "xx_add",
XxMul => "xx_mul",
XInvert => "x_invert",
XbMul => "xb_mul",
ReadIo(_) => "read_io",
WriteIo(_) => "write_io",
XxDotStep => "xxdotstep",
XbDotStep => "xbdotstep",
XxDotStep => "xx_dot_step",
XbDotStep => "xb_dot_step",
}
}

Expand Down
16 changes: 8 additions & 8 deletions triton-vm/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,15 +264,15 @@ fn an_instruction(s: &str) -> ParseResult<AnInstruction<String>> {
let pow = instruction("pow", Pow);
let div_mod = instruction("div_mod", DivMod);
let pop_count = instruction("pop_count", PopCount);
let xxadd = instruction("xxadd", XxAdd);
let xxmul = instruction("xxmul", XxMul);
let xinvert = instruction("xinvert", XInvert);
let xbmul = instruction("xbmul", XbMul);
let xx_add = instruction("xx_add", XxAdd);
let xx_mul = instruction("xx_mul", XxMul);
let x_invert = instruction("x_invert", XInvert);
let xb_mul = instruction("xb_mul", XbMul);

let base_field_arithmetic_on_stack = alt((add, mul, invert, eq));
let bitwise_arithmetic_on_stack =
alt((split, lt, and, xor, log_2_floor, pow, div_mod, pop_count));
let extension_field_arithmetic_on_stack = alt((xxadd, xxmul, xinvert, xbmul));
let extension_field_arithmetic_on_stack = alt((xx_add, xx_mul, x_invert, xb_mul));
let arithmetic_on_stack = alt((
base_field_arithmetic_on_stack,
bitwise_arithmetic_on_stack,
Expand All @@ -286,10 +286,10 @@ fn an_instruction(s: &str) -> ParseResult<AnInstruction<String>> {
let read_write = alt((read_io, write_io));

// Many-in-One
let xxdotstep = instruction("xxdotstep", XxDotStep);
let xbdotstep = instruction("xbdotstep", XbDotStep);
let xx_dot_step = instruction("xx_dot_step", XxDotStep);
let xb_dot_step = instruction("xb_dot_step", XbDotStep);

let many_to_one = alt((xxdotstep, xbdotstep));
let many_to_one = alt((xx_dot_step, xb_dot_step));

// Because of common prefixes, the following parsers are sensitive to order:
//
Expand Down
42 changes: 21 additions & 21 deletions triton-vm/src/stark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1518,23 +1518,23 @@ pub(crate) mod tests {
}

#[test]
fn check_grand_cross_table_argument_for_test_program_for_xxadd() {
check_grand_cross_table_argument(test_program_for_xxadd())
fn check_grand_cross_table_argument_for_test_program_for_xx_add() {
check_grand_cross_table_argument(test_program_for_xx_add())
}

#[test]
fn check_grand_cross_table_argument_for_test_program_for_xxmul() {
check_grand_cross_table_argument(test_program_for_xxmul())
fn check_grand_cross_table_argument_for_test_program_for_xx_mul() {
check_grand_cross_table_argument(test_program_for_xx_mul())
}

#[test]
fn check_grand_cross_table_argument_for_test_program_for_xinvert() {
check_grand_cross_table_argument(test_program_for_xinvert())
fn check_grand_cross_table_argument_for_test_program_for_x_invert() {
check_grand_cross_table_argument(test_program_for_x_invert())
}

#[test]
fn check_grand_cross_table_argument_for_test_program_for_xbmul() {
check_grand_cross_table_argument(test_program_for_xbmul())
fn check_grand_cross_table_argument_for_test_program_for_xb_mul() {
check_grand_cross_table_argument(test_program_for_xb_mul())
}

#[test]
Expand Down Expand Up @@ -1959,23 +1959,23 @@ pub(crate) mod tests {
}

#[test]
fn constraints_evaluate_to_zero_on_program_for_xxadd() {
triton_constraints_evaluate_to_zero(test_program_for_xxadd())
fn constraints_evaluate_to_zero_on_program_for_xx_add() {
triton_constraints_evaluate_to_zero(test_program_for_xx_add())
}

#[test]
fn constraints_evaluate_to_zero_on_program_for_xxmul() {
triton_constraints_evaluate_to_zero(test_program_for_xxmul())
fn constraints_evaluate_to_zero_on_program_for_xx_mul() {
triton_constraints_evaluate_to_zero(test_program_for_xx_mul())
}

#[test]
fn constraints_evaluate_to_zero_on_program_for_xinvert() {
triton_constraints_evaluate_to_zero(test_program_for_xinvert())
fn constraints_evaluate_to_zero_on_program_for_x_invert() {
triton_constraints_evaluate_to_zero(test_program_for_x_invert())
}

#[test]
fn constraints_evaluate_to_zero_on_program_for_xbmul() {
triton_constraints_evaluate_to_zero(test_program_for_xbmul())
fn constraints_evaluate_to_zero_on_program_for_xb_mul() {
triton_constraints_evaluate_to_zero(test_program_for_xb_mul())
}

#[test]
Expand Down Expand Up @@ -2054,13 +2054,13 @@ pub(crate) mod tests {
}

#[test]
fn constraints_evaluate_to_zero_on_property_based_test_program_for_xxdotstep() {
triton_constraints_evaluate_to_zero(property_based_test_program_for_xxdotstep());
fn constraints_evaluate_to_zero_on_property_based_test_program_for_xx_dot_step() {
triton_constraints_evaluate_to_zero(property_based_test_program_for_xx_dot_step());
}

#[test]
fn constraints_evaluate_to_zero_on_property_based_test_program_for_xbdotstep() {
triton_constraints_evaluate_to_zero(property_based_test_program_for_xbdotstep());
fn constraints_evaluate_to_zero_on_property_based_test_program_for_xb_dot_step() {
triton_constraints_evaluate_to_zero(property_based_test_program_for_xb_dot_step());
}

#[test]
Expand All @@ -2071,7 +2071,7 @@ pub(crate) mod tests {
let program = triton_program! {
dup 0
push {i} add
xxdotstep
xx_dot_step
halt
};
let result = program.run(PublicInput::default(), NonDeterminism::default());
Expand Down
Loading

0 comments on commit 96c92ea

Please sign in to comment.