taikoxyz / raiko

Multi-proofs for Taiko. SNARKS, STARKS and Trusted Execution Enclave. Our previous ZK-EVM circuits are deprecated.
Apache License 2.0
96 stars 75 forks source link

Tracking Sp1 cycles optimization and benchmarks #280

Open CeciliaZ030 opened 3 weeks ago

CeciliaZ030 commented 3 weeks ago

The ongoing effort of optimizing sp1 cycles: https://github.com/CeciliaZ030/block-cycles/tree/master

Latest results

Before Txs

2024-06-04T10:42:40.092527Z DEBUG execute: ┌╴initialize_database    
stdout: initialize_db Account touch 496
stdout: initialize_db Storage touch 1564
2024-06-04T10:42:48.471586Z  INFO execute: └╴312,728,708 cycles    
2024-06-04T10:42:48.471737Z DEBUG execute: ┌╴prepare_header    
2024-06-04T10:42:48.472237Z  INFO execute: └╴16,184 cycles   

Typical Transfer: https://etherscan.io/tx/0x61d554e035af9bcf615818c14c725c7d0b424b806e9c7b2220380b5cf7a51b5b

2024-06-04T10:43:06.677300Z DEBUG execute: │ ┌╴Eip1559    
2024-06-04T10:43:06.677317Z DEBUG execute: │ │ ┌╴signature_hash    
2024-06-04T10:43:06.677428Z  INFO execute: │ │ └╴3,606 cycles    
2024-06-04T10:43:06.677445Z DEBUG execute: │ │ ┌╴recover_address_from_prehash    
2024-06-04T10:43:06.977910Z  INFO execute: │ │ └╴218,247 cycles    
2024-06-04T10:43:06.977942Z  INFO execute: │ └╴223,150 cycles    
2024-06-04T10:43:06.977974Z DEBUG execute: │ ┌╴evm.transact()    
2024-06-04T10:43:06.979178Z  INFO execute: │ └╴43,155 cycles  

Swap Router https://etherscan.io/tx/0x85522ad7366e195340be6c97a036d2660e0c8b87794fc7e80176ebfa37ba63b9

2024-06-04T10:42:49.303667Z DEBUG execute: │ ┌╴Eip1559    
2024-06-04T10:42:49.303684Z DEBUG execute: │ │ ┌╴signature_hash    
2024-06-04T10:42:49.303875Z  INFO execute: │ │ └╴6,166 cycles    
2024-06-04T10:42:49.303892Z DEBUG execute: │ │ ┌╴recover_address_from_prehash    
2024-06-04T10:42:49.603095Z  INFO execute: │ │ └╴218,247 cycles    
2024-06-04T10:42:49.603124Z  INFO execute: │ └╴225,710 cycles    
2024-06-04T10:42:49.603156Z DEBUG execute: │ ┌╴evm.transact()    
2024-06-04T10:42:49.643565Z  INFO execute: │ └╴1,529,795 cycles    

Bridge Approval https://etherscan.io/tx/0x0cc57a28fb31e03a2d12b07ada3efe5bfe91aaf7dc4b4f7ffa15e51c386a7428

2024-06-04T10:42:50.671066Z DEBUG execute: │ ┌╴Eip1559    
2024-06-04T10:42:50.671083Z DEBUG execute: │ │ ┌╴signature_hash    
2024-06-04T10:42:50.671510Z  INFO execute: │ │ └╴14,551 cycles    
2024-06-04T10:42:50.671528Z DEBUG execute: │ │ ┌╴recover_address_from_prehash    
2024-06-04T10:42:50.970735Z  INFO execute: │ │ └╴218,247 cycles    
2024-06-04T10:42:50.970762Z  INFO execute: │ └╴234,095 cycles    
2024-06-04T10:42:50.970797Z DEBUG execute: │ ┌╴evm.transact()    
2024-06-04T10:42:51.068495Z  INFO execute: │ └╴3,744,954 cycles 

Dependency Changes

ecdsa = { git = "https://github.com/taikoxyz/signatures.git", branch = "0.16.9", package = "ecdsa", default-features = false, features = ["der"] }

Unconstraint the recover_address_from_prehash results in 218,247 cycles

Spam policy

CeciliaZ030 commented 1 week ago

rust-kzg compiled with modification in this crate: https://github.com/CeciliaZ030/rust-kzg

performance not looking great

2024-06-12T20:25:45.908283Z DEBUG execute: ┌╴load kzg_setting    
2024-06-12T20:25:46.496903Z  INFO execute: └╴7,783,656 cycles    
2024-06-12T20:25:46.496969Z DEBUG execute: ┌╴read blob    
2024-06-12T20:25:46.557434Z  INFO execute: └╴815,690 cycles    
2024-06-12T20:25:46.557497Z DEBUG execute: ┌╴blob_to_kzg_commitment_rust    
2024-06-12T20:25:46.689752Z  INFO execute: clk = 10000000 pc = 0x2060ac    
2024-06-12T20:25:47.353332Z  INFO execute: clk = 20000000 pc = 0x218b3c    
2024-06-12T20:25:48.019065Z  INFO execute: clk = 30000000 pc = 0x20ae70    
......
024-06-12T20:34:17.819632Z  INFO execute: clk = 7700000000 pc = 0x20d8cc    
2024-06-12T20:34:17.902761Z  INFO execute: └╴7,692,653,487 cycles    
CeciliaZ030 commented 1 week ago

compiled scep256k1 to replace k256 https://github.com/CeciliaZ030/rust-secp256k1

performance

2024-06-11T17:27:46.877028Z  INFO execute: loading memory image
2024-06-11T17:27:46.899079Z  INFO execute: starting execution
2024-06-11T17:27:46.899124Z  INFO execute: clk = 0 pc = 0x202508    
2024-06-11T17:27:46.899215Z DEBUG execute: ┌╴sign_recover    
2024-06-11T17:27:46.926345Z DEBUG execute: │ ┌╴sign    
2024-06-11T17:27:47.066870Z  INFO execute: │ └╴1,101,016 cycles    
2024-06-11T17:27:47.066959Z DEBUG execute: │ ┌╴recover    
2024-06-11T17:27:47.372553Z  INFO execute: │ └╴379,598 cycles    
2024-06-11T17:27:47.372628Z  INFO execute: └╴1,691,304 cycles    
2024-06-11T17:27:47.373276Z  INFO execute: finished execution clk = 1696694 pc = 0x0

recovering takes less than a million which is good :)