Skip to content

Commit 9c95d6b

Browse files
committed
Merge remote-tracking branch 'origin/next' into merge-train/spartan
2 parents 0d1ffa1 + 6f90118 commit 9c95d6b

260 files changed

Lines changed: 41049 additions & 8977 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

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: 9 additions & 15 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
@@ -18,13 +16,12 @@ pub(crate) const MSM_ASSEMBLY: &str = "
1816
SET d10, 128 u32; Initialize a constant 128
1917
SET d11, 1 u1; Initialize a constant true
2018
SET d12, 0 u1; Initialize a constant false
21-
SET d13, 2 u32; Initialize a constant 2
22-
SET d14, 3 u32; Initialize a constant 3 for computing pointers to the point components
19+
SET d13, 2 u32; Initialize a constant 2 for computing pointers to point and scalar components
2320
; Main loop: iterate over the points/scalars
2421
OUTER_HEAD: LT d6, d2, d15 ; Check if we are done with the outer loop
2522
JUMPI d15, OUTER_BODY
2623
JUMP OUTER_END
27-
OUTER_BODY: MUL d6, d14, d16; Compute the pointer to the point
24+
OUTER_BODY: MUL d6, d13, d16; Compute the pointer to the point
2825
ADD d16, d0, d16;
2926
MUL d6, d13, d17; Compute the pointer to the scalar lo
3027
ADD d17, d1, d17
@@ -51,35 +48,32 @@ FIND_MSB_BODY: JUMPI i19, FIND_MSB_END; Check if the current bit is one
5148
JUMP FIND_MSB_BODY
5249
; Now we have the pointer of the MSB in d19
5350
54-
; Now store the result of the scalar multiplication in d22, d23, d24
51+
; Now store the result of the scalar multiplication in d22, d23
5552
FIND_MSB_END: MOV i16, d22; x
5653
ADD d16, $2, d25; pointer to y
5754
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
55+
; Also store the original point in d25, d26
6156
MOV d22, d25; x
6257
MOV d23, d26; y
63-
MOV d24, d27; is_infinite
6458
6559
; Now we need to do the inner loop, that will do double then add
6660
; We need to iterate from the pointer of the MSB + 1 to the end pointer (d21)
6761
ADD d19, $2, d19; We start from the pointer of the MSB + 1
6862
INNER_HEAD: LT d19, d21, d28; Check if we are done with the loop
6963
JUMPI d28, INNER_BODY
7064
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.
65+
INNER_BODY: ECADD d22, d23, d22, d23, /*not indirect, so the result is stored in d22, d23*/ d22; Double the current result.
7266
EQ i19, d12, d28; Check if the current bit is zero
7367
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
68+
ECADD d25, d26, d22, d23, /*not indirect, so the result is stored in d22, d23*/ d22; Add the original point to the result
7569
INNER_INC: ADD d19, $2, d19; Increment the pointer
7670
JUMP INNER_HEAD
7771
7872
; 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
73+
INNER_END: ECADD i3, i4, d22, d23, i3; Add the result to the msm result
8074
OUTER_INC: ADD d6, $2, d6; Increment the outer loop variable
8175
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
76+
; After the outer loop we have computed the msm. We can return since we wrote the result in i3, i4
8377
OUTER_END: INTERNALRETURN
8478
";
8579

avm-transpiler/src/transpile.rs

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1280,53 +1280,46 @@ 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,
12841283
input2_x: p2_x_offset,
12851284
input2_y: p2_y_offset,
1286-
input2_infinite: p2_infinite_offset,
12871285
result,
12881286
} => avm_instrs.push(AvmInstruction {
12891287
opcode: AvmOpcode::ECADD,
1290-
// The result (SIXTH operand) is indirect (addressing mode).
1288+
// The result (FOURTH operand) is indirect (addressing mode).
12911289
addressing_mode: Some(
12921290
AddressingModeBuilder::default()
12931291
.direct_operand(p1_x_offset)
12941292
.direct_operand(p1_y_offset)
1295-
.direct_operand(p1_infinite_offset)
12961293
.direct_operand(p2_x_offset)
12971294
.direct_operand(p2_y_offset)
1298-
.direct_operand(p2_infinite_offset)
12991295
.indirect_operand(&result.pointer)
13001296
.build(),
13011297
),
13021298
operands: vec![
13031299
AvmOperand::U16 { value: p1_x_offset.to_u32() as u16 },
13041300
AvmOperand::U16 { value: p1_y_offset.to_u32() as u16 },
1305-
AvmOperand::U16 { value: p1_infinite_offset.to_u32() as u16 },
13061301
AvmOperand::U16 { value: p2_x_offset.to_u32() as u16 },
13071302
AvmOperand::U16 { value: p2_y_offset.to_u32() as u16 },
1308-
AvmOperand::U16 { value: p2_infinite_offset.to_u32() as u16 },
13091303
AvmOperand::U16 { value: result.pointer.to_u32() as u16 },
13101304
],
13111305
..Default::default()
13121306
}),
13131307

13141308
BlackBoxOp::MultiScalarMul { points, scalars, outputs } => {
13151309
// The length of the scalars vector is 2x the length of the points vector due to limb
1316-
// decomposition
1317-
// Output array is fixed to 3
1310+
// decomposition. Points are (x, y); the point at infinity is encoded as (0, 0).
13181311
assert_eq!(
13191312
outputs.size,
1320-
SemiFlattenedLength(3),
1321-
"Output array size must be equal to 3"
1313+
SemiFlattenedLength(2),
1314+
"Output array size must be equal to 2"
13221315
);
1323-
assert_eq!(points.size.0 % 3, 0, "Points array size must be divisible by 3");
1316+
assert_eq!(points.size.0 % 2, 0, "Points array size must be divisible by 2");
13241317

13251318
avm_instrs.push(generate_mov_to_procedure(&points.pointer, 0));
13261319
avm_instrs.push(generate_mov_to_procedure(&scalars.pointer, 1));
13271320
avm_instrs.push(generate_set_to_procedure(
13281321
AvmTypeTag::UINT32,
1329-
&FieldElement::from(points.size.0 / 3),
1322+
&FieldElement::from(points.size.0 / 2),
13301323
2,
13311324
));
13321325
avm_instrs.push(generate_mov_to_procedure(&outputs.pointer, 3));
@@ -1634,6 +1627,7 @@ fn handle_get_contract_instance(
16341627
DEPLOYER,
16351628
CLASS_ID,
16361629
INIT_HASH,
1630+
IMMUTABLES_HASH,
16371631
}
16381632

16391633
assert_eq!(inputs.len(), 1);
@@ -1643,6 +1637,7 @@ fn handle_get_contract_instance(
16431637
"aztec_avm_getContractInstanceDeployer" => ContractInstanceMember::DEPLOYER,
16441638
"aztec_avm_getContractInstanceClassId" => ContractInstanceMember::CLASS_ID,
16451639
"aztec_avm_getContractInstanceInitializationHash" => ContractInstanceMember::INIT_HASH,
1640+
"aztec_avm_getContractInstanceImmutablesHash" => ContractInstanceMember::IMMUTABLES_HASH,
16461641
_ => panic!("Transpiler doesn't know how to process function {:?}", function),
16471642
};
16481643

0 commit comments

Comments
 (0)