Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new ZK opcodes #870

Merged
merged 31 commits into from
Nov 29, 2024
Merged
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
56e31f5
Add boilerplate new opcodes
AurelienFT Nov 14, 2024
87dd242
Format
AurelienFT Nov 14, 2024
9705f6d
Update changelog
AurelienFT Nov 14, 2024
d53e060
Add more boilerplate
AurelienFT Nov 14, 2024
273ffda
Add code for ec add and ec mul
AurelienFT Nov 14, 2024
deac347
Update reserved_registers
AurelienFT Nov 14, 2024
59aae8e
Add source code pairing
AurelienFT Nov 15, 2024
d455d86
use alloc vec
AurelienFT Nov 15, 2024
cc22760
Add gas costs charge
AurelienFT Nov 15, 2024
bd193f2
Add tests for new zk opcodes
AurelienFT Nov 15, 2024
09f62c8
remove forget dbg
AurelienFT Nov 15, 2024
6615559
Add more test case for zk opcodes
AurelienFT Nov 15, 2024
0d41300
Remove old todo
AurelienFT Nov 15, 2024
c8b88ee
Fix clippy in tests
AurelienFT Nov 15, 2024
d59b18d
Change elliptic curve point error variant
AurelienFT Nov 18, 2024
c0a14ff
Change gas costs to v5 because v4 is already released
AurelienFT Nov 19, 2024
4cf15da
format
AurelienFT Nov 19, 2024
c8bc192
Update ec pairing to ouput directly in the register and fix the test
AurelienFT Nov 19, 2024
519e8f3
Update comments on opcodes
AurelienFT Nov 19, 2024
b25ef51
Update zk opcode to match the new spec
AurelienFT Nov 20, 2024
edc190f
Update EPAR prototype
AurelienFT Nov 22, 2024
d12b6fb
update gas costs functions
AurelienFT Nov 23, 2024
c83a7a1
Update default gas ecop based on benches
AurelienFT Nov 23, 2024
00ffd60
Add tests with instructions
AurelienFT Nov 25, 2024
04b8d30
Change gas epar
AurelienFT Nov 25, 2024
4493b33
Fomat
AurelienFT Nov 25, 2024
1741110
Update fuel-vm/src/interpreter/crypto.rs
AurelienFT Nov 28, 2024
ff0bbf7
cleanup for add zk opcodes PR (#874)
Dentosal Nov 28, 2024
498395c
Add some doc about the usage of operation symbols + and *
AurelienFT Nov 28, 2024
5f8b8e8
Add memory overflow tests
AurelienFT Nov 28, 2024
003ade7
fix clippy
AurelienFT Nov 28, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add gas costs charge
AurelienFT committed Nov 15, 2024
commit cc2276034693f0839be4a86244832c2366349dd3
27 changes: 27 additions & 0 deletions fuel-tx/src/transaction/consensus_parameters/gas.rs
Original file line number Diff line number Diff line change
@@ -858,6 +858,24 @@ impl GasCostsValues {
}
}

pub fn eadd(&self) -> Result<Word, GasCostNotDefined> {
match self {
GasCostsValues::V1(_) => Err(GasCostNotDefined),
GasCostsValues::V2(_) => Err(GasCostNotDefined),
GasCostsValues::V3(_) => Err(GasCostNotDefined),
GasCostsValues::V4(v4) => Ok(v4.eadd),
}
}

pub fn emul(&self) -> Result<Word, GasCostNotDefined> {
match self {
GasCostsValues::V1(_) => Err(GasCostNotDefined),
GasCostsValues::V2(_) => Err(GasCostNotDefined),
GasCostsValues::V3(_) => Err(GasCostNotDefined),
GasCostsValues::V4(v4) => Ok(v4.emul),
}
}

pub fn aloc(&self) -> DependentCost {
match self {
GasCostsValues::V1(v1) => DependentCost::HeavyOperation {
@@ -1098,6 +1116,15 @@ impl GasCostsValues {
}
}

pub fn epar(&self) -> Result<DependentCost, GasCostNotDefined> {
match self {
GasCostsValues::V1(_v1) => Err(GasCostNotDefined),
GasCostsValues::V2(_v2) => Err(GasCostNotDefined),
GasCostsValues::V3(_v3) => Err(GasCostNotDefined),
GasCostsValues::V4(v4) => Ok(v4.epar),
}
}

pub fn contract_root(&self) -> DependentCost {
match self {
GasCostsValues::V1(v1) => v1.contract_root,
9 changes: 8 additions & 1 deletion fuel-vm/src/interpreter/executors/instruction.rs
Original file line number Diff line number Diff line change
@@ -919,18 +919,25 @@ where
}

Instruction::EADD(eadd) => {
self.gas_charge(self.gas_costs().eadd().map_err(PanicReason::from)?)?;
let (a, b, c, d) = eadd.unpack();
self.ec_add(r!(a), r!(b), r!(c), r!(d))?;
}

Instruction::EMUL(emul) => {
self.gas_charge(self.gas_costs().emul().map_err(PanicReason::from)?)?;
let (a, b, c, d) = emul.unpack();
self.ec_mul(r!(a), r!(b), r!(c), r!(d))?;
}

Instruction::EPAR(epar) => {
let (a, b, c, d) = epar.unpack();
self.ec_pairing(r!(a), r!(b), r!(c), r!(d))?;
let len = r!(c);
self.dependent_gas_charge(
self.gas_costs().epar().map_err(PanicReason::from)?,
len,
)?;
self.ec_pairing(r!(a), r!(b), len, r!(d))?;
}
}