Skip to content

Conversation

tcharding
Copy link
Member

@tcharding tcharding commented Jan 23, 2024

Add a kani test to check div_rem.

@github-actions github-actions bot added the C-bitcoin PRs modifying the bitcoin crate label Jan 23, 2024
Add a kani test to check `div_rem`.
@coveralls
Copy link

coveralls commented Jan 23, 2024

Pull Request Test Coverage Report for Build 7623004415

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 84.258%

Totals Coverage Status
Change from base Build 7616194895: 0.0%
Covered Lines: 19221
Relevant Lines: 22812

💛 - Coveralls

@tcharding
Copy link
Member Author

I"m a bit rusty on kani but this seems pretty straight forward. CI won't test it till we merge but it appears to run ok locally.

Copy link
Collaborator

@Kixunil Kixunil left a comment

Choose a reason for hiding this comment

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

ACK 66352cb

let _ = x.mul_u64(y);
}

#[kani::unwind(5)] // I can't remember exactly why we need this.
Copy link
Collaborator

Choose a reason for hiding this comment

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

I believe the code uses a loop of length 5 somewhere (or more likely 4).

Copy link
Member

@apoelstra apoelstra left a comment

Choose a reason for hiding this comment

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

ACK 66352cb

@apoelstra apoelstra merged commit 8b552c7 into rust-bitcoin:master Jan 23, 2024
@tcharding tcharding deleted the 01-23-kani branch January 25, 2024 00:16
@apoelstra
Copy link
Member

This fails right now because we have a debug_assert in our Mul implementation that checks for overflow.

Do we want to modify the test or what?

@tcharding
Copy link
Member Author

I just clobbered it, onwards and upwards.

@tcharding
Copy link
Member Author

tcharding commented Feb 6, 2024

That does mean we have lost the TODO that this PR removed but since there are loads of things we can do to improve testing I don't think loosing one todo comment is a big loss.

apoelstra added a commit that referenced this pull request Feb 6, 2024
343510d kani: fix Amount overflow test (Andrew Poelstra)

Pull request description:

  Our Kani CI job is currently failing. See https://github.com/rust-bitcoin/rust-bitcoin/actions/runs/7770495422/job/21190756253

  This fixes one of the issues; the other is that we're hitting a multiplication assertion in the test we added in #2393 which I'm unsure how to deal with.

  For reference, testing this was a bit of a PITA. I needed to

  ```
  # Ok, these steps are easy/obvious
  cargo install kani-verifier
  cargo kani
  ```

  This will give you an error located in core/panic.rs or something with the description `This is a placeholder message; Kani doesn't support message formatted at runtime` which is not super helpful. To get the actual failure, you need to write

  ```
  cargo kani --enable-unstable --concrete-playback=inplace
  ```

  which will add a weird unit test which calls into Kani to exercise the original test with a specific input value. Because it calls into Kani you can't just run it with `cargo test`. You need to run

  ```
  RUST_BACKTRACE=1 CARGO_INCREMENTAL=0 cargo kani playback -Z concrete-playback -- kani_concrete_playback_check_div_rem_8626518785677487871
  ```

  where `CARGO_INCREMENTAL=0` disables incremental compilation (this was causing rustc to flame out with a "filename too long" error because it was trying to create some intermediate file with multiple hashes and crate names in it), and the `kani_concrete_playback_123456789` thing is the name of the test that gets added (which you can easily find by reading `git diff`).

ACKs for top commit:
  tcharding:
    ACK 343510d
  Kixunil:
    ACK 343510d

Tree-SHA512: 398ce3c61ffa3246bd27ae5719b4ac4fda587e87b8645ec8418fdfd039e4ed78d58233faab27bc63df7e2a30bb5467660e77a6e3d3a08fe86e7ff3dd31869ec7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bitcoin PRs modifying the bitcoin crate
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants