#risc-v #cycle #sovereign #rollup #trace #instructions #elf

sov-zk-cycle-utils

用于统计Sovereign SDK函数消耗的risc0周期的实用工具

2 个不稳定版本

0.3.0 2023年10月20日
0.2.0 2023年9月14日

#38#rollup

每月 下载 28
3 crates 中使用

MIT/Apache

8KB

跟踪器

  • 跟踪器二进制文件利用goblin,capstone和rustc-demangle来反汇编riscV ELF并构建符号表
  • 通过设置环境变量ROLLUP_TRACE到所需路径并运行demo-prover来生成rollup ELF的执行跟踪
cd examples/demo-prover/host
ROLLUP_TRACE=rollup.trace cargo bench --bench prover_bench --features bench
  • rollup.trace现在包含demo-prover运行时的程序计数器值(无论我们配置了多少块,blob和事务)
  • 用于跟踪的对应ELF文件可以在以下位置找到
$ file target/riscv-guest/riscv32im-risc0-zkvm-elf/release/rollup
target/riscv-guest/riscv32im-risc0-zkvm-elf/release/rollup: ELF 32-bit LSB executable, UCB RISC-V, soft-float ABI, version 1 (SYSV), statically linked, with debug_info, not stripped
  • 上述两个文件都作为输入传递给跟踪器
% cargo run -- --rollup-elf ../../../examples/demo-prover/target/riscv-guest/riscv32im-risc0-zkvm-elf/release/rollup --rollup-trace ../../../examples/demo-prover/rollup.trace
    Finished dev [unoptimized + debuginfo] target(s) in 0.11s
     Running `target/debug/tracer --rollup-elf ../../../examples/demo-prover/target/riscv-guest/riscv32im-risc0-zkvm-elf/release/rollup --rollup-trace ../../../examples/demo-prover/rollup.trace`
  [00:01:04] [########################################] 16154861/16154861 (0s)

Total instructions in trace: 16154861


 Instruction counts considering call graph
+--------------------------------------------------------------------------------------------+-------------------+
| Function Name                                                                              | Instruction Count |
+============================================================================================+===================+
| __start                                                                                    | 16154854          |
+--------------------------------------------------------------------------------------------+-------------------+
| main                                                                                       | 16153565          |
+--------------------------------------------------------------------------------------------+-------------------+
| rollup::main::h089e03181dac539a                                                            | 16153559          |
+--------------------------------------------------------------------------------------------+-------------------+
| sov_modules_stf_template::<impl                                                            | 15350436          |
| sov_rollup_interface::state_machine::stf::StateTransitionFunction<Vm,B> for                |                   |
| sov_modules_stf_template::app_template::AppTemplate<C,Cond,Vm,RT,B>>::apply_slot::h820293d |                   |
| c8d744201                                                                                  |                   |
+--------------------------------------------------------------------------------------------+-------------------+
| ed25519_dalek::public::PublicKey::verify_strict::hfad17f99efbd2cd0                         | 13528566          |
+--------------------------------------------------------------------------------------------+-------------------+
| <&curve25519_dalek::backend::serial::u64::field::FieldElement51 as                         | 8295218           |
| core::ops::arith::Mul<&curve25519_dalek::backend::serial::u64::field::FieldElement51>>::mu |                   |
| l::h39351372a97422dd                                                                       |                   |
.
.
.
+--------------------------------------------------------------------------------------------+-------------------+
  • 跟踪器还生成不考虑堆栈的纯指令计数
  • 还有其他可以通过cli传递的选项,这些选项在cli中有自我文档
Usage: tracer [OPTIONS] --rollup-elf <ROLLUP_ELF> --rollup-trace <ROLLUP_TRACE>

Options:
  -t, --top <TOP>                    Include the "top" number of functions [default: 30]
      --no-stack-counts              Don't print stack aware instruction counts
      --no-raw-counts                Don't print raw (stack un-aware) instruction counts
      --rollup-elf <ROLLUP_ELF>      Path to the riscv32 elf
      --rollup-trace <ROLLUP_TRACE>  Path to the rollup trace. File must be one u64 program counter per line
  -s, --strip-hashes                 Strip the hashes from the function name while printing
  -h, --help                         Print help
  -V, --version                      Print version

依赖关系

~10–26MB
~328K SLoC