Skip to content

fix: pass real ELF to SP1 mock prover in property tests#7

Closed
Copilot wants to merge 1 commit intomainfrom
copilot/investigate-historical-avg-failing-test
Closed

fix: pass real ELF to SP1 mock prover in property tests#7
Copilot wants to merge 1 commit intomainfrom
copilot/investigate-historical-avg-failing-test

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 7, 2026

Both proptest cases in crates/prover/tests/property.rs were calling run_historical_avg_program(&[], ...) — passing an empty byte slice as the ELF. The SP1 SDK's prover.setup() attempts to read ELF header bytes at [0x0, 0x10) and immediately fails on an empty slice, causing every property test iteration to error with failed to disassemble program: Could not read bytes in range [0x0, 0x10).

Changes

  • crates/prover/tests/property.rs
    • Import build_sp1_program and HISTORICAL_AVG_ELF_PATH (already used the same way in lib.rs tests and prove())
    • Add a static HISTORICAL_AVG_ELF: OnceLock<Vec<u8>> initialized lazily via build_sp1_program(HISTORICAL_AVG_ELF_PATH), exposed through a historical_avg_elf() helper
    • Replace &[] with historical_avg_elf() in both affected proptest cases
static HISTORICAL_AVG_ELF: OnceLock<Vec<u8>> = OnceLock::new();

fn historical_avg_elf() -> &'static [u8] {
    HISTORICAL_AVG_ELF.get_or_init(|| {
        build_sp1_program(HISTORICAL_AVG_ELF_PATH).expect("historical_avg ELF should load")
    })
}

// was: run_historical_avg_program(&[], &encoded)
let outcome = with_mock_prover(|| run_historical_avg_program(historical_avg_elf(), &encoded));

The pre-built ELF (programs/historical_avg/elf/historical-avg-program) is already committed; no build step changes are needed.

Both proptest cases in crates/prover/tests/property.rs were passing
&[] as the ELF argument to run_historical_avg_program, causing the SP1
SDK to fail when attempting to disassemble an empty byte slice.

Fix: introduce a OnceLock<Vec<u8>> that loads the pre-built ELF once
via build_sp1_program(HISTORICAL_AVG_ELF_PATH) and expose it through a
historical_avg_elf() helper. Both failing test cases now pass the real
ELF bytes.

Agent-Logs-Url: https://github.com/bit2swaz/sonar/sessions/64dea247-0607-400d-81f0-d9621ac2ca7c

Co-authored-by: bit2swaz <209277869+bit2swaz@users.noreply.github.com>
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes failing SP1 property tests by ensuring the mock prover is initialized with a real ELF bytecode blob instead of an empty slice (which causes prover.setup() to fail when reading the ELF header).

Changes:

  • Import HISTORICAL_AVG_ELF_PATH and build_sp1_program into the property tests.
  • Add a lazily-initialized, cached OnceLock<Vec<u8>> to load the historical-avg ELF once for the whole test process.
  • Update both proptest cases to call run_historical_avg_program(historical_avg_elf(), ...) instead of run_historical_avg_program(&[], ...).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@bit2swaz bit2swaz marked this pull request as ready for review April 7, 2026 13:18
@bit2swaz bit2swaz closed this Apr 9, 2026
@bit2swaz bit2swaz deleted the copilot/investigate-historical-avg-failing-test branch April 9, 2026 10:06
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