Skip to content

Tracking Sp1 cycles optimization and benchmarks #280

@CeciliaZ030

Description

@CeciliaZ030

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

Latest results

Before Txs

�[2m2024-06-04T10:42:40.092527Z�[0m �[34mDEBUG�[0m �[1mexecute�[0m: ┌╴initialize_database    
stdout: initialize_db Account touch 496
stdout: initialize_db Storage touch 1564
�[2m2024-06-04T10:42:48.471586Z�[0m �[32m INFO�[0m �[1mexecute�[0m: └╴312,728,708 cycles    
�[2m2024-06-04T10:42:48.471737Z�[0m �[34mDEBUG�[0m �[1mexecute�[0m: ┌╴prepare_header    
�[2m2024-06-04T10:42:48.472237Z�[0m �[32m INFO�[0m �[1mexecute�[0m: └╴16,184 cycles   

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

�[2m2024-06-04T10:43:06.677300Z�[0m �[34mDEBUG�[0m �[1mexecute�[0m: │ ┌╴Eip1559    
�[2m2024-06-04T10:43:06.677317Z�[0m �[34mDEBUG�[0m �[1mexecute�[0m: │ │ ┌╴signature_hash    
�[2m2024-06-04T10:43:06.677428Z�[0m �[32m INFO�[0m �[1mexecute�[0m: │ │ └╴3,606 cycles    
�[2m2024-06-04T10:43:06.677445Z�[0m �[34mDEBUG�[0m �[1mexecute�[0m: │ │ ┌╴recover_address_from_prehash    
�[2m2024-06-04T10:43:06.977910Z�[0m �[32m INFO�[0m �[1mexecute�[0m: │ │ └╴218,247 cycles    
�[2m2024-06-04T10:43:06.977942Z�[0m �[32m INFO�[0m �[1mexecute�[0m: │ └╴223,150 cycles    
�[2m2024-06-04T10:43:06.977974Z�[0m �[34mDEBUG�[0m �[1mexecute�[0m: │ ┌╴evm.transact()    
�[2m2024-06-04T10:43:06.979178Z�[0m �[32m INFO�[0m �[1mexecute�[0m: │ └╴43,155 cycles  

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

�[2m2024-06-04T10:42:49.303667Z�[0m �[34mDEBUG�[0m �[1mexecute�[0m: │ ┌╴Eip1559    
�[2m2024-06-04T10:42:49.303684Z�[0m �[34mDEBUG�[0m �[1mexecute�[0m: │ │ ┌╴signature_hash    
�[2m2024-06-04T10:42:49.303875Z�[0m �[32m INFO�[0m �[1mexecute�[0m: │ │ └╴6,166 cycles    
�[2m2024-06-04T10:42:49.303892Z�[0m �[34mDEBUG�[0m �[1mexecute�[0m: │ │ ┌╴recover_address_from_prehash    
�[2m2024-06-04T10:42:49.603095Z�[0m �[32m INFO�[0m �[1mexecute�[0m: │ │ └╴218,247 cycles    
�[2m2024-06-04T10:42:49.603124Z�[0m �[32m INFO�[0m �[1mexecute�[0m: │ └╴225,710 cycles    
�[2m2024-06-04T10:42:49.603156Z�[0m �[34mDEBUG�[0m �[1mexecute�[0m: │ ┌╴evm.transact()    
�[2m2024-06-04T10:42:49.643565Z�[0m �[32m INFO�[0m �[1mexecute�[0m: │ └╴1,529,795 cycles    

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

�[2m2024-06-04T10:42:50.671066Z�[0m �[34mDEBUG�[0m �[1mexecute�[0m: │ ┌╴Eip1559    
�[2m2024-06-04T10:42:50.671083Z�[0m �[34mDEBUG�[0m �[1mexecute�[0m: │ │ ┌╴signature_hash    
�[2m2024-06-04T10:42:50.671510Z�[0m �[32m INFO�[0m �[1mexecute�[0m: │ │ └╴14,551 cycles    
�[2m2024-06-04T10:42:50.671528Z�[0m �[34mDEBUG�[0m �[1mexecute�[0m: │ │ ┌╴recover_address_from_prehash    
�[2m2024-06-04T10:42:50.970735Z�[0m �[32m INFO�[0m �[1mexecute�[0m: │ │ └╴218,247 cycles    
�[2m2024-06-04T10:42:50.970762Z�[0m �[32m INFO�[0m �[1mexecute�[0m: │ └╴234,095 cycles    
�[2m2024-06-04T10:42:50.970797Z�[0m �[34mDEBUG�[0m �[1mexecute�[0m: │ ┌╴evm.transact()    
�[2m2024-06-04T10:42:51.068495Z�[0m �[32m INFO�[0m �[1mexecute�[0m: │ └╴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

  • todo: constarint this with sp1-precompile SDK's secp256 functions but it might add thousands of cycles
revm-precompile = { git = "https://github.com/taikoxyz/revm.git", branch = "v35_taiko_v2", default-features = false, features = [
    "taiko",
    "std",
    "c-kzg",
] }

Added ZkOp, see #85

Modifications for Cycle Tracking

Some code need to be modified for printing cycles: https://succinctlabs.github.io/sp1/writing-programs/cycle-tracking.html?highlight=cycle#tracking-cycles

raiko-lib = {  git = "https://github.com/taikoxyz/raiko.git", branch = "sp1-cycle-tracker", features = ["std", "sp1"] }

In raiko, need to change alloy related crates:

alloy-rpc-types = { git = "https://github.com/ceciliaz030/alloy", branch = "175_4e22b9e-cycle" }
alloy-rpc-client = { git = "https://github.com/ceciliaz030/alloy", branch = "175_4e22b9e-cycle" }
alloy-consensus = { git = "https://github.com/ceciliaz030/alloy", branch = "175_4e22b9e-cycle", features = [
    "serde",
] }
alloy-network = { git = "https://github.com/ceciliaz030/alloy", branch = "175_4e22b9e-cycle", features = [
    "k256",
] }
alloy-contract = { git = "https://github.com/ceciliaz030/alloy", branch = "175_4e22b9e-cycle" }
alloy-eips = { git = "https://github.com/ceciliaz030/alloy", branch = "175_4e22b9e-cycle", features = [
    "serde",
] }
alloy-provider = { git = "https://github.com/ceciliaz030/alloy", branch = "175_4e22b9e-cycle" }
alloy-transport-http = { git = "https://github.com/ceciliaz030/alloy", branch = "175_4e22b9e-cycle" }
alloy-signer = { git = "https://github.com/ceciliaz030/alloy", branch = "175_4e22b9e-cycle" }
alloy-signer-wallet = { git = "https://github.com/ceciliaz030/alloy", branch = "175_4e22b9e-cycle" }

Also in raiko, swap revm as well:

revm-primitives = { git = "https://github.com/taikoxyz/revm.git", branch = "v35_taiko_v2-cycls", default-features = false }
revm = { git = "https://github.com/taikoxyz/revm.git", branch = "v35_taiko_v2-cycls", default-features = false, features = [
    "serde",
    "std",
    "c-kzg",
    "taiko",
] }

Spam policy

  • I verify that this issue is NOT SPAM and understand SPAM issues will be closed and reported to GitHub, resulting in ACCOUNT TERMINATION.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions