From d53e0605fab3725e925cdeddad2b4610ac95ac60 Mon Sep 17 00:00:00 2001 From: AurelienFT Date: Thu, 14 Nov 2024 12:03:47 +0100 Subject: [PATCH] Add more boilerplate --- fuel-vm/src/interpreter/crypto.rs | 75 +++++++++++++++++++ .../src/interpreter/executors/instruction.rs | 15 ++-- 2 files changed, 84 insertions(+), 6 deletions(-) diff --git a/fuel-vm/src/interpreter/crypto.rs b/fuel-vm/src/interpreter/crypto.rs index e1ff2cf824..4d133fc278 100644 --- a/fuel-vm/src/interpreter/crypto.rs +++ b/fuel-vm/src/interpreter/crypto.rs @@ -91,6 +91,45 @@ where c, ) } + + pub(crate) fn ec_add(&mut self, a: Word, b: Word, c: Word, d: Word) -> SimpleResult<()> { + let owner = self.ownership_registers(); + ec_add( + self.memory.as_mut(), + owner, + self.registers.pc_mut(), + a, + b, + c, + d, + ) + } + + pub(crate) fn ec_mul(&mut self, a: Word, b: Word, c: Word, d: Word) -> SimpleResult<()> { + let owner = self.ownership_registers(); + ec_mul( + self.memory.as_mut(), + owner, + self.registers.pc_mut(), + a, + b, + c, + d, + ) + } + + pub(crate) fn ec_pairing(&mut self, a: Word, b: Word, c: Word, d: Word) -> SimpleResult<()> { + let owner = self.ownership_registers(); + ec_pairing( + self.memory.as_mut(), + owner, + self.registers.pc_mut(), + a, + b, + c, + d, + ) + } } pub(crate) fn secp256k1_recover( @@ -202,3 +241,39 @@ pub(crate) fn sha256( memory.write_bytes(owner, a, *Hasher::hash(memory.read(b, c)?))?; Ok(inc_pc(pc)?) } + +pub(crate) fn ec_add( + _memory: &mut MemoryInstance, + _owner: OwnershipRegisters, + _pc: RegMut, + _a: Word, + _b: Word, + _c: Word, + _d: Word, +) -> SimpleResult<()> { + todo!() +} + +pub(crate) fn ec_mul( + _memory: &mut MemoryInstance, + _owner: OwnershipRegisters, + _pc: RegMut, + _a: Word, + _b: Word, + _c: Word, + _d: Word, +) -> SimpleResult<()> { + todo!() +} + +pub(crate) fn ec_pairing( + _memory: &mut MemoryInstance, + _owner: OwnershipRegisters, + _pc: RegMut, + _a: Word, + _b: Word, + _c: Word, + _d: Word, +) -> SimpleResult<()> { + todo!() +} \ No newline at end of file diff --git a/fuel-vm/src/interpreter/executors/instruction.rs b/fuel-vm/src/interpreter/executors/instruction.rs index 4f0f867d57..c34dfbc519 100644 --- a/fuel-vm/src/interpreter/executors/instruction.rs +++ b/fuel-vm/src/interpreter/executors/instruction.rs @@ -918,16 +918,19 @@ where self.blob_load_data(r!(a), r!(b), r!(c), r!(d))?; } - Instruction::EADD(_edd) => { - unimplemented!("EADD is not yet implemented") + Instruction::EADD(eadd) => { + let (a, b, c, d) = eadd.unpack(); + self.ec_add(r!(a), r!(b), r!(c), r!(d))?; } - Instruction::EMUL(_emul) => { - unimplemented!("EMUL is not yet implemented") + Instruction::EMUL(emul) => { + let (a, b, c, d) = emul.unpack(); + self.ec_mul(r!(a), r!(b), r!(c), r!(d))?; } - Instruction::EPAR(_epar) => { - unimplemented!("EPAR is not yet implemented") + Instruction::EPAR(epar) => { + let (a, b, c, d) = epar.unpack(); + self.ec_pairing(r!(a), r!(b), r!(c), r!(d))?; } }