Skip to content

Commit

Permalink
Add new ZK opcodes (#870)
Browse files Browse the repository at this point in the history
* Add boilerplate new opcodes

* Format

* Update changelog

* Add more boilerplate

* Add code for ec add and ec mul

* Update reserved_registers

* Add source code pairing

* use alloc vec

* Add gas costs charge

* Add tests for new zk opcodes

* remove forget dbg

* Add more test case for zk opcodes

* Remove old todo

* Fix clippy in tests

* Change elliptic curve point error variant

* Change gas costs to v5 because v4 is already released

* format

* Update ec pairing to ouput directly in the register and fix the test

* Update comments on opcodes

* Update zk opcode to match the new spec

* Update EPAR prototype

* update gas costs functions

* Update default gas ecop based on benches

* Add tests with instructions

* Change gas epar

* Fomat

* Update fuel-vm/src/interpreter/crypto.rs

Co-authored-by: Hannes Karppila <2204863+Dentosal@users.noreply.github.com>

* cleanup for add zk opcodes PR (#874)

* Simplify error types

* Use MemoryOverflow instead of ArithmeticOverflow

* Fix inversion letter

---------

Co-authored-by: AurelienFT <aurelien.foucault@epitech.eu>

* Add some doc about the usage of operation symbols + and *

* Add memory overflow tests

* fix clippy

---------

Co-authored-by: Hannes Karppila <2204863+Dentosal@users.noreply.github.com>
  • Loading branch information
AurelienFT and Dentosal authored Nov 29, 2024
1 parent 486d06f commit e7d5d6f
Show file tree
Hide file tree
Showing 12 changed files with 1,622 additions and 9 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]

### Added
- [870](https://github.com/FuelLabs/fuel-vm/pull/870): Add 3 new ZK-related opcodes: eadd (ecAdd on EVM), emul (ecMul on EVM), epar (ecPairing on EVM)

### Fixed
- [860](https://github.com/FuelLabs/fuel-vm/pull/860): Fixed missing fuzzing coverage report in CI.

Expand Down
9 changes: 6 additions & 3 deletions fuel-asm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,10 @@ impl_instructions! {
0xba BSIZ bsiz [dst: RegId blob_id_ptr: RegId]
"Load blob as data"
0xbb BLDD bldd [dst_ptr: RegId blob_id_ptr: RegId offset: RegId len: RegId]
"Given some curve, performs an operation on points"
0xbc ECOP ecop [dst: RegId curve_id: RegId operation_type: RegId points_ptr: RegId]
"Given some curve, performs a pairing on groups of points"
0xbe EPAR epar [success: RegId curve_id: RegId number_elements: RegId points_ptr: RegId]
}

impl Instruction {
Expand Down Expand Up @@ -701,9 +705,8 @@ impl Opcode {
| K256 | S256 | NOOP | FLAG | ADDI | ANDI | DIVI | EXPI | MODI | MULI
| MLDV | ORI | SLLI | SRLI | SUBI | XORI | JNEI | LB | LW | SB | SW
| MCPI | MCLI | GM | MOVI | JNZI | JI | JMP | JNE | JMPF | JMPB | JNZF
| JNZB | JNEF | JNEB | CFEI | CFSI | CFE | CFS | GTF | LDC | BSIZ | BLDD => {
true
}
| JNZB | JNEF | JNEB | CFEI | CFSI | CFE | CFS | GTF | LDC | BSIZ | BLDD
| ECOP | EPAR => true,
_ => false,
}
}
Expand Down
7 changes: 7 additions & 0 deletions fuel-asm/src/panic_reason.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,13 @@ enum_from! {
BlobIdAlreadyUploaded = 0x37,
/// Active gas costs do not define the cost for this instruction.
GasCostNotDefined = 0x38,
/// The curve id is not supported.
UnsupportedCurveId = 0x39,
/// The operation type is not supported.
UnsupportedOperationType = 0x3a,
/// Read alt_bn_128 curve point is invalid.
InvalidEllipticCurvePoint = 0x3b,

}
}

Expand Down
Loading

0 comments on commit e7d5d6f

Please sign in to comment.