taikoxyz / raiko

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

Tracking Sp1 cycles optimization and benchmarks #280

Open CeciliaZ030 opened 5 months ago

CeciliaZ030 commented 5 months 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 5 months 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 5 months 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 :)

CeciliaZ030 commented 4 months ago

A whole block at #229

2024-08-01T03:45:49.183779Z DEBUG setup:setup machine: close time.busy=2.71s time.idle=1.46µs
2024-08-01T03:45:49.204515Z DEBUG setup: close time.busy=2.89s time.idle=2.29µs
2024-08-01T03:45:49.212830Z DEBUG Proving locally with recursion mode: Core
2024-08-01T03:45:49.371724Z DEBUG execute: loading memory image
2024-08-01T03:45:49.480999Z  INFO execute: clk = 0 pc = 0x218de0    
2024-08-01T03:45:49.481296Z DEBUG execute: ┌╴input    
stdout: WARNING: Using insecure random number generator.
2024-08-01T03:45:53.228409Z  INFO execute: clk = 10000000 pc = 0x218d04    
2024-08-01T03:45:54.620323Z  INFO execute: └╴18,777,833 cycles    
2024-08-01T03:45:54.620539Z DEBUG execute: ┌╴calculate_block_header    
2024-08-01T03:45:54.620723Z DEBUG execute: │ ┌╴initialize_database    
2024-08-01T03:45:54.894901Z  INFO execute: clk = 20000000 pc = 0x26e04c    
2024-08-01T03:45:56.731529Z  INFO execute: clk = 30000000 pc = 0x485e50    
2024-08-01T03:45:58.135479Z  INFO execute: clk = 40000000 pc = 0x2e8848    
2024-08-01T03:45:59.595193Z  INFO execute: clk = 50000000 pc = 0x2e8ecc    
2024-08-01T03:46:01.052408Z  INFO execute: clk = 60000000 pc = 0x2e8b10    
2024-08-01T03:46:02.511321Z  INFO execute: clk = 70000000 pc = 0x2e8b68    
2024-08-01T03:46:03.969533Z  INFO execute: clk = 80000000 pc = 0x2e87dc    
2024-08-01T03:46:05.407976Z  INFO execute: clk = 90000000 pc = 0x2d0e20    
2024-08-01T03:46:06.846776Z  INFO execute: clk = 100000000 pc = 0x486e78    
2024-08-01T03:46:08.180640Z  INFO execute: clk = 110000000 pc = 0x486e84    
2024-08-01T03:46:08.575438Z  INFO execute: │ └╴93,800,227 cycles    
2024-08-01T03:46:09.927232Z DEBUG execute: │ ┌╴execute_transactions    
2024-08-01T03:46:10.172938Z  INFO execute: clk = 120000000 pc = 0x44d074    
2024-08-01T03:46:11.440334Z  INFO execute: clk = 130000000 pc = 0x44c458    
2024-08-01T03:46:12.593718Z  INFO execute: clk = 140000000 pc = 0x44c490    
2024-08-01T03:46:13.862057Z  INFO execute: clk = 150000000 pc = 0x218b10    
2024-08-01T03:46:15.124407Z  INFO execute: clk = 160000000 pc = 0x4ac330    
2024-08-01T03:46:16.273326Z  INFO execute: clk = 170000000 pc = 0x44cf2c    
2024-08-01T03:46:17.539776Z  INFO execute: clk = 180000000 pc = 0x218af4    
2024-08-01T03:46:18.798185Z  INFO execute: clk = 190000000 pc = 0x44cfdc    
2024-08-01T03:46:19.953814Z  INFO execute: clk = 200000000 pc = 0x44c468    
2024-08-01T03:46:21.223376Z  INFO execute: clk = 210000000 pc = 0x44c460    
2024-08-01T03:46:22.487072Z  INFO execute: clk = 220000000 pc = 0x44d104    
2024-08-01T03:46:23.637079Z  INFO execute: clk = 230000000 pc = 0x44d074    
2024-08-01T03:46:24.904518Z  INFO execute: clk = 240000000 pc = 0x218b24    
2024-08-01T03:46:26.157875Z  INFO execute: clk = 250000000 pc = 0x44cfac    
2024-08-01T03:46:29.200567Z  INFO execute: clk = 260000000 pc = 0x3edf38    
2024-08-01T03:46:37.260079Z  INFO execute: clk = 270000000 pc = 0x3edf34    
2024-08-01T03:46:45.312655Z  INFO execute: clk = 280000000 pc = 0x3e870c    
2024-08-01T03:46:53.628745Z  INFO execute: clk = 290000000 pc = 0x3edf3c    
2024-08-01T03:47:01.652572Z  INFO execute: clk = 300000000 pc = 0x3ed9a8    
2024-08-01T03:47:09.693853Z  INFO execute: clk = 310000000 pc = 0x3edea0    
2024-08-01T03:47:17.787726Z  INFO execute: clk = 320000000 pc = 0x3e7b6c    
2024-08-01T03:47:26.070678Z  INFO execute: clk = 330000000 pc = 0x3e8ad4    
2024-08-01T03:47:34.099481Z  INFO execute: clk = 340000000 pc = 0x3edd00    
stdout: Invalid tx at 1: NonceTooLow { tx: 182363, state: 182364 }
2024-08-01T03:47:39.579489Z  INFO execute: clk = 350000000 pc = 0x263300    
stdout: feature = secp256k1_zk
2024-08-01T03:47:40.034719Z DEBUG execute: │ │ ┌╴secp256k1_zk    
2024-08-01T03:47:40.352514Z  INFO execute: │ │ └╴376,552 cycles    
stdout: feature = secp256k1_zk
2024-08-01T03:47:40.376345Z DEBUG execute: │ │ ┌╴secp256k1_zk    
2024-08-01T03:47:40.692645Z  INFO execute: │ │ └╴376,504 cycles    
stdout: feature = secp256k1_zk
2024-08-01T03:47:40.960869Z DEBUG execute: │ │ ┌╴secp256k1_zk    
2024-08-01T03:47:41.277036Z  INFO execute: │ │ └╴376,540 cycles    
2024-08-01T03:47:41.722643Z  INFO execute: clk = 360000000 pc = 0x3c8930    
2024-08-01T03:47:43.037294Z  INFO execute: clk = 370000000 pc = 0x28b968    
2024-08-01T03:47:44.348105Z  INFO execute: clk = 380000000 pc = 0x3c8938    
2024-08-01T03:47:46.003051Z  INFO execute: clk = 390000000 pc = 0x218424    
2024-08-01T03:47:48.014394Z  INFO execute: clk = 400000000 pc = 0x263234    
2024-08-01T03:47:49.949191Z  INFO execute: clk = 410000000 pc = 0x26274c    
stdout: feature = secp256k1_zk
2024-08-01T03:47:51.411158Z DEBUG execute: │ │ ┌╴secp256k1_zk    
2024-08-01T03:47:51.729582Z  INFO execute: │ │ └╴376,468 cycles    
stdout: feature = secp256k1_zk
2024-08-01T03:47:51.854204Z DEBUG execute: │ │ ┌╴secp256k1_zk    
2024-08-01T03:47:52.171467Z  INFO execute: │ │ └╴376,635 cycles    
stdout: feature = secp256k1_zk
2024-08-01T03:47:52.258199Z DEBUG execute: │ │ ┌╴secp256k1_zk    
2024-08-01T03:47:52.570095Z  INFO execute: │ │ └╴376,516 cycles    
stdout: feature = secp256k1_zk
2024-08-01T03:47:52.646517Z DEBUG execute: │ │ ┌╴secp256k1_zk    
2024-08-01T03:47:52.959304Z  INFO execute: │ │ └╴376,575 cycles    
stdout: feature = secp256k1_zk
2024-08-01T03:47:53.063325Z DEBUG execute: │ │ ┌╴secp256k1_zk    
2024-08-01T03:47:53.380776Z  INFO execute: │ │ └╴376,599 cycles    
2024-08-01T03:47:53.938650Z  INFO execute: clk = 420000000 pc = 0x2628bc    
2024-08-01T03:47:56.804458Z  INFO execute: clk = 430000000 pc = 0x262840    
2024-08-01T03:47:57.968622Z  INFO execute: clk = 440000000 pc = 0x486e78    
2024-08-01T03:47:58.504388Z  INFO execute: │ └╴326,509,809 cycles    
2024-08-01T03:47:58.504509Z DEBUG execute: │ ┌╴finalize    
2024-08-01T03:47:59.058955Z  INFO execute: clk = 450000000 pc = 0x2e8d04    
2024-08-01T03:48:00.142496Z  INFO execute: clk = 460000000 pc = 0x2d5af8    
2024-08-01T03:48:01.185583Z  INFO execute: clk = 470000000 pc = 0x2d7fdc    
2024-08-01T03:48:01.405290Z  INFO execute: │ └╴27,388,587 cycles    
2024-08-01T03:48:01.433223Z  INFO execute: └╴453,265,091 cycles    
2024-08-01T03:48:01.433380Z DEBUG execute: ┌╴ProtocolInstance    
2024-08-01T03:48:01.434056Z DEBUG execute: │ ┌╴proof_of_equivalence    
2024-08-01T03:48:02.351414Z  INFO execute: clk = 480000000 pc = 0x2edb38    
2024-08-01T03:48:03.465568Z  INFO execute: clk = 490000000 pc = 0x2d39f8    
2024-08-01T03:48:04.896502Z  INFO execute: clk = 500000000 pc = 0x2e9a70    
2024-08-01T03:48:05.899474Z  INFO execute: clk = 510000000 pc = 0x2ea3a4    
2024-08-01T03:48:06.900815Z  INFO execute: clk = 520000000 pc = 0x2ea1a4    
2024-08-01T03:48:07.764103Z  INFO execute: │ └╴56,578,574 cycles    
2024-08-01T03:48:07.797593Z  INFO execute: └╴56,874,188 cycles    
2024-08-01T03:48:15.463613Z  INFO execute: close time.busy=146s time.idle=2.58µs
2024-08-01T03:48:15.612395Z DEBUG ==> Verification complete in 157.214 seconds
 *  Terminal will be reused by tasks, press any key to close it. 
CeciliaZ030 commented 4 months ago

ZkOP test at #333 ecdsa

2024-08-01T07:27:21.458140Z  INFO prove_core: clk = 0 pc = 0x2022e0    
2024-08-01T07:27:21.534985Z  INFO prove_core: └╴229,100 cycles  

sha256

2024-08-01T07:28:55.060745Z  INFO prove_core: clk = 0 pc = 0x201cb8    
2024-08-01T07:28:55.062476Z  INFO prove_core: └╴1,950 cycles 

BN254 Add

2024-08-01T07:31:21.170964Z  INFO prove_core: clk = 0 pc = 0x202028    
2024-08-01T07:31:21.293590Z  INFO prove_core: └╴941,417 cycles 

BN254 Mul

2024-08-01T07:40:50.830607Z  INFO prove_core: clk = 480000000 pc = 0x20ef18    
2024-08-01T07:40:51.120379Z  INFO prove_core: └╴483,833,516 cycles    

the whole block

2024-08-01T07:46:18.497027Z  INFO execute: clk = 0 pc = 0x215b6c    
2024-08-01T07:46:18.498095Z DEBUG execute: ┌╴input    
stdout: WARNING: Using insecure random number generator.
2024-08-01T07:46:20.012383Z  INFO execute: clk = 10000000 pc = 0x2157ac    
2024-08-01T07:46:21.346217Z  INFO execute: └╴18,870,418 cycles    
2024-08-01T07:46:21.346411Z DEBUG execute: ┌╴calculate_block_header    
2024-08-01T07:46:21.346562Z DEBUG execute: │ ┌╴initialize_database    
2024-08-01T07:46:21.597560Z  INFO execute: clk = 20000000 pc = 0x2e90b4    
2024-08-01T07:46:23.323369Z  INFO execute: clk = 30000000 pc = 0x2cd350    
2024-08-01T07:46:24.488203Z  INFO execute: clk = 40000000 pc = 0x2f98c8    
2024-08-01T07:46:25.674444Z  INFO execute: clk = 50000000 pc = 0x2f94f4    
2024-08-01T07:46:26.862355Z  INFO execute: clk = 60000000 pc = 0x2f9b7c    
2024-08-01T07:46:28.049792Z  INFO execute: clk = 70000000 pc = 0x2f9480    
2024-08-01T07:46:29.236494Z  INFO execute: clk = 80000000 pc = 0x2f9844    
2024-08-01T07:46:30.417384Z  INFO execute: clk = 90000000 pc = 0x4b1028    
2024-08-01T07:46:31.673903Z  INFO execute: clk = 100000000 pc = 0x48b394    
2024-08-01T07:46:32.811790Z  INFO execute: clk = 110000000 pc = 0x48b33c    
2024-08-01T07:46:33.200016Z  INFO execute: │ └╴93,910,644 cycles    
2024-08-01T07:46:34.579855Z DEBUG execute: │ ┌╴execute_transactions    
2024-08-01T07:46:34.762115Z  INFO execute: clk = 120000000 pc = 0x450dc8    
2024-08-01T07:46:35.857756Z  INFO execute: clk = 130000000 pc = 0x4868b8    
2024-08-01T07:46:36.845009Z  INFO execute: clk = 140000000 pc = 0x48686c    
2024-08-01T07:46:37.949023Z  INFO execute: clk = 150000000 pc = 0x450d24    
2024-08-01T07:46:39.042679Z  INFO execute: clk = 160000000 pc = 0x4504a8    
2024-08-01T07:46:40.035076Z  INFO execute: clk = 170000000 pc = 0x450e68    
2024-08-01T07:46:41.138768Z  INFO execute: clk = 180000000 pc = 0x48adf0    
2024-08-01T07:46:42.217643Z  INFO execute: clk = 190000000 pc = 0x4517ec    
2024-08-01T07:46:43.217148Z  INFO execute: clk = 200000000 pc = 0x4504fc    
2024-08-01T07:46:44.322750Z  INFO execute: clk = 210000000 pc = 0x450cd0    
2024-08-01T07:46:45.397262Z  INFO execute: clk = 220000000 pc = 0x437cec    
2024-08-01T07:46:46.402173Z  INFO execute: clk = 230000000 pc = 0x4b1040    
2024-08-01T07:46:47.504365Z  INFO execute: clk = 240000000 pc = 0x450c1c    
2024-08-01T07:46:48.565307Z  INFO execute: clk = 250000000 pc = 0x450480    
2024-08-01T07:46:49.845675Z  INFO execute: clk = 260000000 pc = 0x4b8c10    
2024-08-01T07:46:52.068774Z  INFO execute: clk = 270000000 pc = 0x21581c    
2024-08-01T07:46:54.320997Z  INFO execute: clk = 280000000 pc = 0x4b9004    
2024-08-01T07:46:56.574379Z  INFO execute: clk = 290000000 pc = 0x4b8f70    
2024-08-01T07:46:58.823681Z  INFO execute: clk = 300000000 pc = 0x4b9340    
2024-08-01T07:47:01.074311Z  INFO execute: clk = 310000000 pc = 0x4b8bcc    
stdout: Invalid tx at 1: NonceTooLow { tx: 182363, state: 182364 }
2024-08-01T07:47:02.363716Z  INFO execute: clk = 320000000 pc = 0x2de58c    
2024-08-01T07:47:03.565843Z  INFO execute: clk = 330000000 pc = 0x21587c    
2024-08-01T07:47:04.730044Z  INFO execute: clk = 340000000 pc = 0x3dbbb0    
2024-08-01T07:47:05.927500Z  INFO execute: clk = 350000000 pc = 0x2dc954    
2024-08-01T07:47:07.822830Z  INFO execute: clk = 360000000 pc = 0x3dbbb4    
2024-08-01T07:47:09.563078Z  INFO execute: clk = 370000000 pc = 0x215878    
2024-08-01T07:47:11.600574Z  INFO execute: clk = 380000000 pc = 0x4b921c    
2024-08-01T07:47:14.748874Z  INFO execute: clk = 390000000 pc = 0x3dbbe8    
2024-08-01T07:47:17.094302Z  INFO execute: clk = 400000000 pc = 0x215890    
2024-08-01T07:47:17.996042Z  INFO execute: │ └╴289,782,350 cycles    
2024-08-01T07:47:17.996166Z DEBUG execute: │ ┌╴finalize    
2024-08-01T07:47:18.199967Z  INFO execute: clk = 410000000 pc = 0x2f9638    
2024-08-01T07:47:19.235206Z  INFO execute: clk = 420000000 pc = 0x48b390    
2024-08-01T07:47:20.328208Z  INFO execute: clk = 430000000 pc = 0x215b40    
2024-08-01T07:47:20.950224Z  INFO execute: │ └╴27,404,605 cycles    
2024-08-01T07:47:20.978236Z  INFO execute: └╴416,753,819 cycles    
2024-08-01T07:47:20.978392Z DEBUG execute: ┌╴ProtocolInstance    
2024-08-01T07:47:20.979061Z DEBUG execute: │ ┌╴proof_of_equivalence    
2024-08-01T07:47:21.500150Z  INFO execute: clk = 440000000 pc = 0x2faf2c    
2024-08-01T07:47:22.501050Z  INFO execute: clk = 450000000 pc = 0x4681c4    
2024-08-01T07:47:23.825336Z  INFO execute: clk = 460000000 pc = 0x215890    
2024-08-01T07:47:25.112245Z  INFO execute: clk = 470000000 pc = 0x2fa298    
2024-08-01T07:47:26.114764Z  INFO execute: clk = 480000000 pc = 0x2fa234    
2024-08-01T07:47:27.118590Z  INFO execute: clk = 490000000 pc = 0x2fa8e8    
2024-08-01T07:47:27.341910Z  INFO execute: │ └╴56,578,682 cycles    
2024-08-01T07:47:27.373771Z  INFO execute: └╴56,876,400 cycles    
2024-08-01T07:47:35.126514Z  INFO execute: close time.busy=76.9s time.idle=2.24µs
2024-08-01T07:47:35.276857Z DEBUG ==> Verification complete in 87.913 seconds