Skip to content

Commit e847fa2

Browse files
committed
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 0546d6d commit e847fa2

10 files changed

Lines changed: 111 additions & 228 deletions

File tree

avm-transpiler/src/procedures/msm.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
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). The point at infinity is (0, 0).
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-
; Initialize the msm result: point at infinity (0, 0)
8+
; Initialize the msm result: point at infinity
99
SET i3, 0 ff
1010
SET i4, 0 ff
1111
; Loop globals

avm-transpiler/src/transpile.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1285,7 +1285,7 @@ fn handle_black_box_function(
12851285
result,
12861286
} => avm_instrs.push(AvmInstruction {
12871287
opcode: AvmOpcode::ECADD,
1288-
// The result (SIXTH operand) is indirect (addressing mode).
1288+
// The result (FOURTH operand) is indirect (addressing mode).
12891289
addressing_mode: Some(
12901290
AddressingModeBuilder::default()
12911291
.direct_operand(p1_x_offset)

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
@@ -1240,7 +1240,7 @@ pub global AVM_DEBUGLOG_BASE_L2_GAS: u32 = 9;
12401240
pub global AVM_POSEIDON2_BASE_L2_GAS: u32 = 24 * 15; // SLOW_SIM_MUL = 15
12411241
pub global AVM_SHA256COMPRESSION_BASE_L2_GAS: u32 = 12288;
12421242
pub global AVM_KECCAKF1600_BASE_L2_GAS: u32 = 58176;
1243-
pub global AVM_ECADD_BASE_L2_GAS: u32 = 27 * 10; // SLOW_SIM_MUL = 10
1243+
pub global AVM_ECADD_BASE_L2_GAS: u32 = 18 * 10; // SLOW_SIM_MUL = 10
12441244
pub global AVM_TORADIXBE_BASE_L2_GAS: u32 = 24;
12451245

12461246
// Dynamic L2 GAS

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ export const AVM_DEBUGLOG_BASE_L2_GAS = 9;
460460
export const AVM_POSEIDON2_BASE_L2_GAS = 360;
461461
export const AVM_SHA256COMPRESSION_BASE_L2_GAS = 12288;
462462
export const AVM_KECCAKF1600_BASE_L2_GAS = 58176;
463-
export const AVM_ECADD_BASE_L2_GAS = 270;
463+
export const AVM_ECADD_BASE_L2_GAS = 180;
464464
export const AVM_TORADIXBE_BASE_L2_GAS = 24;
465465
export const AVM_CALLDATACOPY_DYN_L2_GAS = 3;
466466
export const AVM_RETURNDATACOPY_DYN_L2_GAS = 3;

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)