Skip to content

Conversation

@qwang98
Copy link
Collaborator

@qwang98 qwang98 commented Nov 14, 2025

WIP. Read and write data are currently hardcoded to 0 because I still need to figure out their length, which depends on a runtime constant. However the idea should remain the same.

How this works

Cycle -> {
    pc
    reads: Vec<(addr space, addr, value)>
    writes: Vec<(addr space, addr, value)>
}
  • Prints something like the following when you run RUST_LOG=trace cargo test --release --package powdr-openvm --lib -- tests::guest_execution_data --exact --show-output.
Execution data: [
    Cycle {
        pc: 2100976,
        reads: [],
        writes: [
            (
                1,
                12,
                0,
            ),
        ],
    },
    Cycle {
        pc: 2100980,
        reads: [
            (
                1,
                12,
                0,
            ),
        ],
        writes: [
            (
                1,
                12,
                0,
            ),
        ],
    },
    ...
]

Comment on lines 2158 to 2164
#[test]
fn guest_execution_data() {
let mut stdin = StdIn::default();
stdin.write(&GUEST_ITER);
let execution_data = execution_data_from_guest(GUEST, GuestOptions::default(), stdin.clone());
println!("Execution data: {execution_data:#?}");
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Happy to make this a part of our CLI if we run these frequently.

Comment on lines 983 to 1002
pub fn execution_data_from_guest(
guest: &str,
guest_opts: GuestOptions,
inputs: StdIn,
) -> Vec<Cycle> {
let OriginalCompiledProgram { exe, vm_config, .. } = compile_openvm(guest, guest_opts).unwrap();
let program = Prog::from(&exe.program);

// Set app configuration
let app_fri_params =
FriParameters::standard_with_100_bits_conjectured_security(DEFAULT_APP_LOG_BLOWUP);
let app_config = AppConfig::new(app_fri_params, vm_config.clone());

// prepare for execute
let sdk = PowdrExecutionProfileSdkCpu::new(app_config).unwrap();

execution_data::<BabyBearOpenVmApcAdapter>(&program, || {
sdk.execute(exe.clone(), inputs.clone()).unwrap();
})
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO: Top part mostly same as execution_profile_from_guest. Make it a helper.

@qwang98
Copy link
Collaborator Author

qwang98 commented Nov 14, 2025

TODO: Make it a JSON like the following as per @georgwiese.

{
    "runtime_values": [
        {
            "pc": 1024,
            "reads": [
                {
                    "address_space": 1,
                    "address": 40,
                    "value": 16
                },
                {
                    "address_space": 1,
                    "address": 44,
                    "value": 32
                }
            ],
            "writes": [
                {
                    "address_space": 1,
                    "address": 40,
                    "value": 17
                }
            ]
        },
        {
            "pc": 1024,
            "reads": [
                {
                    "address_space": 1,
                    "address": 40,
                    "value": 16
                },
                {
                    "address_space": 1,
                    "address": 44,
                    "value": 17
                }
            ],
            "writes": [
                {
                    "address_space": 1,
                    "address": 40,
                    "value": 17
                }
            ]
        }
    ]
}

@georgwiese
Copy link
Collaborator

Nice! 🤩

Pushed a few commits to update the JSON format and integrate with my notebook (which I pushed too).

E.g., you can run:
mkdir -f keccak100 && cargo run --bin powdr_openvm -r --features metrics prove guest-keccak --input 100 --autoprecompiles 12 --apc-candidates-dir keccak100

Then, the notebook looks at the 9th instruction (1-indexed) of this block.

It works end-to-end, but I think there is currently a bug, because the value is always zero. I haven't looked into this yet, but noting that it is already the case in the example in the PR description.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants