Skip to content

Commit 0773092

Browse files
committed
feat: first pass, change ECADD opcode sig in transpiler, y-p
1 parent f0f77cb commit 0773092

7 files changed

Lines changed: 110 additions & 238 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()

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)