Skip to content

Commit

Permalink
Merge pull request #132 from near/zkasm_fibo
Browse files Browse the repository at this point in the history
Implement Fibonacci in ZK ASM
  • Loading branch information
aborg-dev authored Dec 1, 2023
2 parents a9e13fc + b17fd6d commit 43148fa
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
start:
10000 => A
:CALL(fib)
fibEnd:
15574651946073070043n :ASSERT
finalizeExecution:
${beforeLast()} :JMPN(finalizeExecution)
:JMP(start)

; Computes the fibonacci number for N stored in register A.
; Stores the result in register A.
; Uses registers: C, D.
fib:
A :JMPZ(fibReturn)
; Here A >= 1.

A => D
0 => A
1 => B
fibLoop:
$ => C :ADD
B => A
C => B
D - 1 => D
D: JMPNZ(fibLoop)

fibReturn:
:RETURN
1 change: 1 addition & 0 deletions cranelift/zkasm_data/benchmarks/fibonacci/state.csv
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
Test,Status,Cycles
from_rust,pass,42024
handwritten,pass,50008
handwritten_wat,pass,190024
2 changes: 1 addition & 1 deletion docs/zkasm/test_summary.csv
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Suite path,Passing count,Total count,Total cycles
cranelift/zkasm_data,25,26,1023
cranelift/zkasm_data/benchmarks/fibonacci,2,2,232048
cranelift/zkasm_data/benchmarks/fibonacci,3,3,282056
cranelift/zkasm_data/benchmarks/sha256,0,1,0
cranelift/zkasm_data/spectest/conversions,3,24,45
cranelift/zkasm_data/spectest/i32,203,364,6938
Expand Down

0 comments on commit 43148fa

Please sign in to comment.