Skip to content

Commit 814108b

Browse files
authored
feat(avm)!: WIP remove is_infinite flags from ECADD opcode (outside AVM only) (#23031)
This branch includes the changes to remove the `is_infinite` flags from the ECADD opcode fn signature which reside outside `vm2`. This includes the transpiler, ts simulator, and anything required in ACIR. Note that ACIR and noir's black box still use [the flags](https://github.com/AztecProtocol/aztec-packages/blob/b30fe8f401d7af45148071924b22b3f377750eaf/barretenberg/cpp/src/barretenberg/dsl/acir_format/ec_operations.hpp#L34) and represent points by a[ triple of elements.](https://github.com/noir-lang/noir/blob/bc4a37e2994ebc7d44ae98be81e18606b2231c61/acvm-repo/bn254_blackbox_solver/src/embedded_curve_ops.rs#L98) Since this touches both private and public execution, I think it's out of scope of this task to update these. Will partially close [Foundation AVM Issue 19](https://linear.app/aztec-foundation/issue/AVM-19/) (the previous PR with AVM changes will close the initial portion) --- Stack: - #22745 - #22564 - #22921 - #22795 - #22945 - `mw/avm-rem-inf-opcode-ecadd-ext` <-- here
1 parent 908d08b commit 814108b

11 files changed

Lines changed: 119 additions & 246 deletions

File tree

avm-transpiler/src/procedures/compiler.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,10 +233,8 @@ fn compile_opcode(
233233
Mnemonic::ECADD => {
234234
collector.memory_address_operand()?; // p1 x
235235
collector.memory_address_operand()?; // p1 y
236-
collector.memory_address_operand()?; // p1 is_infinite
237236
collector.memory_address_operand()?; // p2 x
238237
collector.memory_address_operand()?; // p2 y
239-
collector.memory_address_operand()?; // p2 is_infinite
240238
collector.memory_address_operand()?; // result
241239
let collection = collector.finish()?;
242240
result.add_instruction(

avm-transpiler/src/procedures/msm.rs

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
pub(crate) const MSM_ASSEMBLY: &str = "
22
; We are passed three pointers and one usize.
3-
; d0 points to the points. Points are represented by (x: Field, y: Field, is_infinite: bool)
3+
; d0 points to the points. Points are represented by (x: Field, y: Field).
44
; d1 points to the scalars. Scalars are represented by (lo: Field, hi: Field) both range checked to 128 bits.
55
; d2 contains the number of points.
66
; d3 points to the result. The result is a point.
77
ADD d3, /*the reserved register 'one_usize'*/ $2, d4; Compute the pointer to the result y.
8-
ADD d4, $2, d5; Compute the pointer to the result is_infinite
98
; Initialize the msm result: point at infinity
109
SET i3, 0 ff
1110
SET i4, 0 ff
12-
SET i5, 1 u1
1311
; Loop globals
1412
SET d6, 0 u32; Initialize the outer loop variable, ranging from 0 to the number of points
1513
SET d8, 0 ff; Initialize a 0 FF
@@ -51,35 +49,32 @@ FIND_MSB_BODY: JUMPI i19, FIND_MSB_END; Check if the current bit is one
5149
JUMP FIND_MSB_BODY
5250
; Now we have the pointer of the MSB in d19
5351
54-
; Now store the result of the scalar multiplication in d22, d23, d24
52+
; Now store the result of the scalar multiplication in d22, d23
5553
FIND_MSB_END: MOV i16, d22; x
5654
ADD d16, $2, d25; pointer to y
5755
MOV i25, d23; y
58-
ADD d25, $2, d25; pointer to is_infinite
59-
MOV i25, d24; is_infinite
60-
; Also store the original point in d25, d26, d27
56+
; Also store the original point in d25, d26
6157
MOV d22, d25; x
6258
MOV d23, d26; y
63-
MOV d24, d27; is_infinite
6459
6560
; Now we need to do the inner loop, that will do double then add
6661
; We need to iterate from the pointer of the MSB + 1 to the end pointer (d21)
6762
ADD d19, $2, d19; We start from the pointer of the MSB + 1
6863
INNER_HEAD: LT d19, d21, d28; Check if we are done with the loop
6964
JUMPI d28, INNER_BODY
7065
JUMP INNER_END
71-
INNER_BODY: ECADD d22, d23, d24, d22, d23, d24, /*not indirect, so the result is stored in d22, d23, d24*/ d22; Double the current result.
66+
INNER_BODY: ECADD d22, d23, d22, d23, /*not indirect, so the result is stored in d22, d23*/ d22; Double the current result.
7267
EQ i19, d12, d28; Check if the current bit is zero
7368
JUMPI d28, INNER_INC; If the current bit is zero, continue
74-
ECADD d25, d26, d27, d22, d23, d24, /*not indirect, so the result is stored in d22, d23, d24*/ d22; Add the original point to the result
69+
ECADD d25, d26, d22, d23, /*not indirect, so the result is stored in d22, d23*/ d22; Add the original point to the result
7570
INNER_INC: ADD d19, $2, d19; Increment the pointer
7671
JUMP INNER_HEAD
7772
7873
; After the inner loop we have computed the scalar multiplication. Add it to the msm result
79-
INNER_END: ECADD i3, i4, i5, d22, d23, d24, i3; Add the result to the msm result
74+
INNER_END: ECADD i3, i4, d22, d23, i3; Add the result to the msm result
8075
OUTER_INC: ADD d6, $2, d6; Increment the outer loop variable
8176
JUMP OUTER_HEAD
82-
; After the outer loop we have computed the msm. We can return since we wrote the result in i3, i4, i5
77+
; After the outer loop we have computed the msm. We can return since we wrote the result in i3, i4
8378
OUTER_END: INTERNALRETURN
8479
";
8580

avm-transpiler/src/transpile.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1280,32 +1280,28 @@ fn handle_black_box_function(
12801280
BlackBoxOp::EmbeddedCurveAdd {
12811281
input1_x: p1_x_offset,
12821282
input1_y: p1_y_offset,
1283-
input1_infinite: p1_infinite_offset,
1283+
input1_infinite: _,
12841284
input2_x: p2_x_offset,
12851285
input2_y: p2_y_offset,
1286-
input2_infinite: p2_infinite_offset,
1286+
input2_infinite: _,
12871287
result,
12881288
} => avm_instrs.push(AvmInstruction {
12891289
opcode: AvmOpcode::ECADD,
1290-
// The result (SIXTH operand) is indirect (addressing mode).
1290+
// The result (FOURTH operand) is indirect (addressing mode).
12911291
addressing_mode: Some(
12921292
AddressingModeBuilder::default()
12931293
.direct_operand(p1_x_offset)
12941294
.direct_operand(p1_y_offset)
1295-
.direct_operand(p1_infinite_offset)
12961295
.direct_operand(p2_x_offset)
12971296
.direct_operand(p2_y_offset)
1298-
.direct_operand(p2_infinite_offset)
12991297
.indirect_operand(&result.pointer)
13001298
.build(),
13011299
),
13021300
operands: vec![
13031301
AvmOperand::U16 { value: p1_x_offset.to_u32() as u16 },
13041302
AvmOperand::U16 { value: p1_y_offset.to_u32() as u16 },
1305-
AvmOperand::U16 { value: p1_infinite_offset.to_u32() as u16 },
13061303
AvmOperand::U16 { value: p2_x_offset.to_u32() as u16 },
13071304
AvmOperand::U16 { value: p2_y_offset.to_u32() as u16 },
1308-
AvmOperand::U16 { value: p2_infinite_offset.to_u32() as u16 },
13091305
AvmOperand::U16 { value: result.pointer.to_u32() as u16 },
13101306
],
13111307
..Default::default()

barretenberg/cpp/src/barretenberg/aztec/aztec_constants.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@
233233
#define AVM_POSEIDON2_BASE_L2_GAS 360
234234
#define AVM_SHA256COMPRESSION_BASE_L2_GAS 12288
235235
#define AVM_KECCAKF1600_BASE_L2_GAS 58176
236-
#define AVM_ECADD_BASE_L2_GAS 270
236+
#define AVM_ECADD_BASE_L2_GAS 180
237237
#define AVM_TORADIXBE_BASE_L2_GAS 24
238238
#define AVM_CALLDATACOPY_DYN_L2_GAS 3
239239
#define AVM_RETURNDATACOPY_DYN_L2_GAS 3

barretenberg/cpp/src/barretenberg/vm2/constraining/avm_fixed_vk.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class AvmHardCodedVKAndHash {
1717
using FF = bb::curve::BN254::ScalarField;
1818

1919
// Precomputed VK hash (hash of all commitments below).
20-
static FF vk_hash() { return FF(uint256_t("0x0f0714f53e7fcf7ffb15cfb22b7a1614c65f01742706b0ca20eb80454eaf1e48")); }
20+
static FF vk_hash() { return FF(uint256_t("0x00b6d67db723a570d7686fbcb5f3c4c39945378222f37e86fa9f511af4c036b5")); }
2121

2222
static constexpr std::array<Commitment, NUM_PRECOMPUTED_ENTITIES> get_all()
2323
{
@@ -71,9 +71,9 @@ class AvmHardCodedVKAndHash {
7171
uint256_t(
7272
"0x090dda25e7d64ab5cabe09fd80fbb731af2a98de7a608157dc10394b4fc022a4")), // precomputed_exec_opcode_dynamic_l2_gas
7373
Commitment(
74-
uint256_t("0x26086b5fb31a24f236f0441d5b922b94ca141e861b9cc640184681c518cd68d3"),
74+
uint256_t("0x1fbccee2ff656d845414c1a520adde56aa3625e29b6fff377044986493023e6d"),
7575
uint256_t(
76-
"0x0bab134bb4e25ff33584c1094847e762ce6573054bae27715d0e4eb2b7278d80")), // precomputed_exec_opcode_opcode_gas
76+
"0x05c88802d3174f1c7b3c9aa1abf4754ebdaf6409d1aaf1dfa3f551da1c10fa93")), // precomputed_exec_opcode_opcode_gas
7777
Commitment(
7878
uint256_t("0x296def9415d1c96b4d8ab91df5f59ad8522a726f98461b1ab5c4d4c5b22471a4"),
7979
uint256_t(

noir-projects/noir-protocol-circuits/crates/types/src/constants.nr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1220,7 +1220,7 @@ pub global AVM_DEBUGLOG_BASE_L2_GAS: u32 = 9;
12201220
pub global AVM_POSEIDON2_BASE_L2_GAS: u32 = 24 * 15; // SLOW_SIM_MUL = 15
12211221
pub global AVM_SHA256COMPRESSION_BASE_L2_GAS: u32 = 12288;
12221222
pub global AVM_KECCAKF1600_BASE_L2_GAS: u32 = 58176;
1223-
pub global AVM_ECADD_BASE_L2_GAS: u32 = 27 * 10; // SLOW_SIM_MUL = 10
1223+
pub global AVM_ECADD_BASE_L2_GAS: u32 = 18 * 10; // SLOW_SIM_MUL = 10
12241224
pub global AVM_TORADIXBE_BASE_L2_GAS: u32 = 24;
12251225

12261226
// Dynamic L2 GAS

yarn-project/constants/src/constants.gen.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ export const AVM_DEBUGLOG_BASE_L2_GAS = 9;
451451
export const AVM_POSEIDON2_BASE_L2_GAS = 360;
452452
export const AVM_SHA256COMPRESSION_BASE_L2_GAS = 12288;
453453
export const AVM_KECCAKF1600_BASE_L2_GAS = 58176;
454-
export const AVM_ECADD_BASE_L2_GAS = 270;
454+
export const AVM_ECADD_BASE_L2_GAS = 180;
455455
export const AVM_TORADIXBE_BASE_L2_GAS = 24;
456456
export const AVM_CALLDATACOPY_DYN_L2_GAS = 3;
457457
export const AVM_RETURNDATACOPY_DYN_L2_GAS = 3;
@@ -497,6 +497,7 @@ export const GRUMPKIN_ONE_Y = 17631683881184975370165255887551781615748388533673
497497
export const DEFAULT_MAX_DEBUG_LOG_MEMORY_READS = 125000;
498498
export enum DomainSeparator {
499499
NOTE_HASH = 116501019,
500+
PARTIAL_NOTE_COMMITMENT = 568912195,
500501
SILOED_NOTE_HASH = 3361878420,
501502
UNIQUE_NOTE_HASH = 226850429,
502503
NOTE_HASH_NONCE = 1721808740,

yarn-project/simulator/docs/avm/avm-isa-quick-reference.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -250,9 +250,9 @@ Click on an opcode name to view its detailed documentation.
250250
* **[🔗ECADD](opcodes/ecadd.md)**: Grumpkin elliptic curve addition
251251
* Opcode `0x42`
252252
```javascript
253-
M[dstOffset:dstOffset+3] = grumpkinAdd(
254-
/*point1=*/{x: M[p1XOffset], y: M[p1YOffset], isInfinite: M[p1IsInfiniteOffset]},
255-
/*point2=*/{x: M[p2XOffset], y: M[p2YOffset], isInfinite: M[p2IsInfiniteOffset]}
253+
M[dstOffset:dstOffset+1] = grumpkinAdd(
254+
/*point1=*/{x: M[p1XOffset], y: M[p1YOffset]},
255+
/*point2=*/{x: M[p2XOffset], y: M[p2YOffset]}
256256
)
257257
```
258258
* **[🔗TORADIXBE](opcodes/toradixbe.md)**: Convert to radix (big-endian)

0 commit comments

Comments
 (0)