diff --git a/forc-plugins/forc-client/src/util/account.rs b/forc-plugins/forc-client/src/util/account.rs index c94735b0b41..b129ce95b2d 100644 --- a/forc-plugins/forc-client/src/util/account.rs +++ b/forc-plugins/forc-client/src/util/account.rs @@ -22,7 +22,6 @@ pub enum ForcClientAccount { KmsSigner(AwsSigner), } -#[async_trait] impl Account for ForcClientAccount { fn add_witnesses(&self, tb: &mut Tb) -> Result<()> { tb.add_signer(self.clone())?; diff --git a/sway-ast/src/expr/op_code.rs b/sway-ast/src/expr/op_code.rs index 83c6d319743..bfd13f1ed81 100644 --- a/sway-ast/src/expr/op_code.rs +++ b/sway-ast/src/expr/op_code.rs @@ -337,6 +337,8 @@ define_op_codes!( (Ed19, Ed19Opcode, "ed19", (addr: reg, sig: reg, hash: reg, len: reg)), (K256, K256Opcode, "k256", (addr: reg, data: reg, size: reg)), (S256, S256Opcode, "s256", (addr: reg, data: reg, size: reg)), + (ECOP, ECOPOpcode, "ecop", (dst_addr: reg, curve: reg, operation: reg, src_addr: reg)), + (EPAR, EPAROpcode, "epar", (ret: reg, curve: reg, groups_of_points: reg, addr: reg)), /* Other Instructions */ (Flag, FlagOpcode, "flag", (value: reg)), (Gm, GmOpcode, "gm", (ret: reg, op: imm)), diff --git a/sway-core/src/asm_lang/allocated_ops.rs b/sway-core/src/asm_lang/allocated_ops.rs index 730706e29de..bbf00a4067b 100644 --- a/sway-core/src/asm_lang/allocated_ops.rs +++ b/sway-core/src/asm_lang/allocated_ops.rs @@ -267,6 +267,18 @@ pub(crate) enum AllocatedOpcode { ), K256(AllocatedRegister, AllocatedRegister, AllocatedRegister), S256(AllocatedRegister, AllocatedRegister, AllocatedRegister), + ECOP( + AllocatedRegister, + AllocatedRegister, + AllocatedRegister, + AllocatedRegister, + ), + EPAR( + AllocatedRegister, + AllocatedRegister, + AllocatedRegister, + AllocatedRegister, + ), /* Other Instructions */ FLAG(AllocatedRegister), @@ -392,6 +404,8 @@ impl AllocatedOpcode { ED19(_r1, _r2, _r3, _r4) => vec![], K256(_r1, _r2, _r3) => vec![], S256(_r1, _r2, _r3) => vec![], + ECOP(_r1, _r2, _r3, _r4) => vec![], + EPAR(r1, _r2, _r3, _r4) => vec![r1], /* Other Instructions */ FLAG(_r1) => vec![], @@ -521,6 +535,8 @@ impl fmt::Display for AllocatedOpcode { ED19(a, b, c, d) => write!(fmtr, "ed19 {a} {b} {c} {d}"), K256(a, b, c) => write!(fmtr, "k256 {a} {b} {c}"), S256(a, b, c) => write!(fmtr, "s256 {a} {b} {c}"), + ECOP(a, b, c, d) => write!(fmtr, "ecop {a} {b} {c} {d}"), + EPAR(a, b, c, d) => write!(fmtr, "epar {a} {b} {c} {d}"), /* Other Instructions */ FLAG(a) => write!(fmtr, "flag {a}"), @@ -751,6 +767,12 @@ impl AllocatedOp { } K256(a, b, c) => op::K256::new(a.to_reg_id(), b.to_reg_id(), c.to_reg_id()).into(), S256(a, b, c) => op::S256::new(a.to_reg_id(), b.to_reg_id(), c.to_reg_id()).into(), + ECOP(a, b, c, d) => { + op::ECOP::new(a.to_reg_id(), b.to_reg_id(), c.to_reg_id(), d.to_reg_id()).into() + } + EPAR(a, b, c, d) => { + op::EPAR::new(a.to_reg_id(), b.to_reg_id(), c.to_reg_id(), d.to_reg_id()).into() + } /* Other Instructions */ FLAG(a) => op::FLAG::new(a.to_reg_id()).into(), diff --git a/sway-core/src/asm_lang/mod.rs b/sway-core/src/asm_lang/mod.rs index 1506a5c3bd8..029c59f048e 100644 --- a/sway-core/src/asm_lang/mod.rs +++ b/sway-core/src/asm_lang/mod.rs @@ -674,6 +674,14 @@ impl Op { let (r1, r2, r3) = three_regs(handler, args, immediate, whole_op_span)?; VirtualOp::S256(r1, r2, r3) } + "ecop" => { + let (r1, r2, r3, r4) = four_regs(handler, args, immediate, whole_op_span)?; + VirtualOp::ECOP(r1, r2, r3, r4) + } + "epar" => { + let (r1, r2, r3, r4) = four_regs(handler, args, immediate, whole_op_span)?; + VirtualOp::EPAR(r1, r2, r3, r4) + } /* Other Instructions */ "flag" => { @@ -1228,6 +1236,8 @@ impl fmt::Display for VirtualOp { ED19(a, b, c, d) => write!(fmtr, "ed19 {a} {b} {c} {d}"), K256(a, b, c) => write!(fmtr, "k256 {a} {b} {c}"), S256(a, b, c) => write!(fmtr, "s256 {a} {b} {c}"), + ECOP(a, b, c, d) => write!(fmtr, "ecop {a} {b} {c} {d}"), + EPAR(a, b, c, d) => write!(fmtr, "epar {a} {b} {c} {d}"), /* Other Instructions */ FLAG(a) => write!(fmtr, "flag {a}"), diff --git a/sway-core/src/asm_lang/virtual_ops.rs b/sway-core/src/asm_lang/virtual_ops.rs index 449577ccf58..1845303ebd6 100644 --- a/sway-core/src/asm_lang/virtual_ops.rs +++ b/sway-core/src/asm_lang/virtual_ops.rs @@ -218,6 +218,18 @@ pub(crate) enum VirtualOp { ), K256(VirtualRegister, VirtualRegister, VirtualRegister), S256(VirtualRegister, VirtualRegister, VirtualRegister), + ECOP( + VirtualRegister, + VirtualRegister, + VirtualRegister, + VirtualRegister, + ), + EPAR( + VirtualRegister, + VirtualRegister, + VirtualRegister, + VirtualRegister, + ), /* Other Instructions */ FLAG(VirtualRegister), @@ -339,6 +351,8 @@ impl VirtualOp { ED19(r1, r2, r3, r4) => vec![r1, r2, r3, r4], K256(r1, r2, r3) => vec![r1, r2, r3], S256(r1, r2, r3) => vec![r1, r2, r3], + ECOP(r1, r2, r3, r4) => vec![r1, r2, r3, r4], + EPAR(r1, r2, r3, r4) => vec![r1, r2, r3, r4], /* Other Instructions */ FLAG(r1) => vec![r1], @@ -407,6 +421,7 @@ impl VirtualOp { | TIME(_, _) | GM(_, _) | GTF(_, _, _) + | EPAR(_, _, _, _) // Virtual OPs | LoadDataId(_, _) | AddrDataId(_, _) @@ -463,6 +478,7 @@ impl VirtualOp { | ED19(_, _, _, _) | K256(_, _, _) | S256(_, _, _) + | ECOP(_, _, _, _) | FLAG(_) // Virtual OPs | BLOB(_) @@ -570,6 +586,8 @@ impl VirtualOp { | TRO(_, _, _, _) | K256(_, _, _) | S256(_, _, _) + | ECOP(_, _, _, _) + | EPAR(_, _, _, _) | GM(_, _) | GTF(_, _, _) | BLOB(_) @@ -687,6 +705,8 @@ impl VirtualOp { ED19(r1, r2, r3, r4) => vec![r1, r2, r3, r4], K256(r1, r2, r3) => vec![r1, r2, r3], S256(r1, r2, r3) => vec![r1, r2, r3], + ECOP(r1, r2, r3, r4) => vec![r1, r2, r3, r4], + EPAR(_r1, r2, r3, r4) => vec![r2, r3, r4], /* Other Instructions */ FLAG(r1) => vec![r1], @@ -809,6 +829,8 @@ impl VirtualOp { ED19(_r1, _r2, _r3, _r4) => vec![], K256(_r1, _r2, _r3) => vec![], S256(_r1, _r2, _r3) => vec![], + ECOP(_r1, _r2, _r3, _r4) => vec![], + EPAR(r1, _r2, _r3, _r4) => vec![r1], /* Other Instructions */ FLAG(_r1) => vec![], @@ -1256,6 +1278,18 @@ impl VirtualOp { update_reg(reg_to_reg_map, r2), update_reg(reg_to_reg_map, r3), ), + ECOP(r1, r2, r3, r4) => Self::ECOP( + update_reg(reg_to_reg_map, r1), + update_reg(reg_to_reg_map, r2), + update_reg(reg_to_reg_map, r3), + update_reg(reg_to_reg_map, r4), + ), + EPAR(r1, r2, r3, r4) => Self::EPAR( + update_reg(reg_to_reg_map, r1), + update_reg(reg_to_reg_map, r2), + update_reg(reg_to_reg_map, r3), + update_reg(reg_to_reg_map, r4), + ), /* Other Instructions */ FLAG(r1) => Self::FLAG(update_reg(reg_to_reg_map, r1)), @@ -1737,6 +1771,18 @@ impl VirtualOp { map_reg(&mapping, reg2), map_reg(&mapping, reg3), ), + ECOP(reg1, reg2, reg3, reg4) => AllocatedOpcode::ECOP( + map_reg(&mapping, reg1), + map_reg(&mapping, reg2), + map_reg(&mapping, reg3), + map_reg(&mapping, reg4), + ), + EPAR(reg1, reg2, reg3, reg4) => AllocatedOpcode::EPAR( + map_reg(&mapping, reg1), + map_reg(&mapping, reg2), + map_reg(&mapping, reg3), + map_reg(&mapping, reg4), + ), /* Other Instructions */ FLAG(reg) => AllocatedOpcode::FLAG(map_reg(&mapping, reg)), diff --git a/sway-parse/src/expr/op_code.rs b/sway-parse/src/expr/op_code.rs index 1281ca4bae3..29ad8918111 100644 --- a/sway-parse/src/expr/op_code.rs +++ b/sway-parse/src/expr/op_code.rs @@ -124,6 +124,18 @@ define_op_codes!( (Ed19, Ed19Opcode, "ed19", (addr, sig, hash, len)), (K256, K256Opcode, "k256", (addr, data, size)), (S256, S256Opcode, "s256", (addr, data, size)), + ( + ECOP, + ECOPOpcode, + "ecop", + (dst_addr, curve, operation, src_addr) + ), + ( + EPAR, + EPAROpcode, + "epar", + (ret, curve, groups_of_points, addr) + ), /* Other Instructions */ (Flag, FlagOpcode, "flag", (value)), (Gm, GmOpcode, "gm", (ret, op)), diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/zk_opcodes/Forc.lock b/test/src/e2e_vm_tests/test_programs/should_pass/language/zk_opcodes/Forc.lock new file mode 100644 index 00000000000..249dfc40045 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/zk_opcodes/Forc.lock @@ -0,0 +1,13 @@ +[[package]] +name = "core" +source = "path+from-root-11C3CFAE4942D9B7" + +[[package]] +name = "std" +source = "path+from-root-11C3CFAE4942D9B7" +dependencies = ["core"] + +[[package]] +name = "zk_opcodes" +source = "member" +dependencies = ["std"] diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/zk_opcodes/Forc.toml b/test/src/e2e_vm_tests/test_programs/should_pass/language/zk_opcodes/Forc.toml new file mode 100644 index 00000000000..398b5b6b1a5 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/zk_opcodes/Forc.toml @@ -0,0 +1,8 @@ +[project] +authors = ["Fuel Labs "] +entry = "main.sw" +license = "Apache-2.0" +name = "zk_opcodes" + +[dependencies] +std = { path = "../../../../reduced_std_libs/sway-lib-std-assert" } diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/zk_opcodes/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/zk_opcodes/src/main.sw new file mode 100644 index 00000000000..db00a0f0090 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/zk_opcodes/src/main.sw @@ -0,0 +1,14 @@ +script; + +fn main() -> bool { + let src_addr: [u64; 32] = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; + let dst_addr: [u64; 32] = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; + asm(dst_addr: dst_addr, curve: 0, op: 0, src_addr: src_addr) { + ecop dst_addr curve op src_addr; + } + + asm(res, curve: 0, group_of_points: 1, addr: dst_addr) { + epar res curve group_of_points addr; + res: bool + } +} diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/zk_opcodes/test.toml b/test/src/e2e_vm_tests/test_programs/should_pass/language/zk_opcodes/test.toml new file mode 100644 index 00000000000..e816041d3f8 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/zk_opcodes/test.toml @@ -0,0 +1 @@ +category = "compile"