> For the complete documentation index, see [llms.txt](https://thias-organization.gitbook.io/p256-documentation/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://thias-organization.gitbook.io/p256-documentation/risc-zero-p256-accelerator/tests-and-usage.md).

# Tests and Usage

## Testing Correctness

Now that we have optimised field and scalar operations, we need to test the correctness of it. Test code for ECDSA is already included in the original implementation, together with a library of test vectors.

For example in this test found in `ecdsa.rs`,

```rust
// Test vector from RFC 6979 Appendix 2.5 (NIST P-256 + SHA-256)
// <https://tools.ietf.org/html/rfc6979#appendix-A.2.5>
#[test]
fn rfc6979() {
    let x = hex!("c9afa9d845ba75166b5c215767b1d6934e50c3db36e89b127b8a622b120f6721");
    let signer = SigningKey::from_bytes(&x.into()).unwrap();
    let signature: Signature = signer.sign(b"sample");
    assert_eq!(
        signature.to_bytes().as_slice(),
        &hex!(
            "efd48b2aacb6a8fd1140dd9cd45e81d69d2c877b56aaf991c34d0ea84eaf3716
             f7cb1c942d657c41d436c7a1b6e29f65f3e900dbb9aff4064dc4ab2f843acda8"
        )
    );
    let signature: Signature = signer.sign(b"test");
    assert_eq!(
        signature.to_bytes().as_slice(),
        &hex!(
            "f1abb023518351cd71d881567b1ea663ed3efcf6c5132b354f28d3b0b7d38367
             019f4113742a2b14bd25926b49c649155f267e60d3814b4c0cc84250e46f0083"
        )
    );
}
```

`x` refers to the private key, and the messages we are trying to sign are "sample" and "test". The test verifies that the [signature proof](/p256-documentation/elliptic-curve-digital-signature-algorithm-ecdsa.md#id-4-calculate-the-signature-proof) `(r, s)` is as expected after signing.

All internal tests have passed and it indicates that our implementation is on the right track!

## Usage in zkVM Guest Code

Here we show how we can use the optimised version in the [ECDSA example by RISC Zero](https://github.com/risc0/risc0/tree/release-0.21/examples/ecdsa). The guest code is relatively simple but it is implemented using the k256 curve

```rust
use k256::{
    ecdsa::{signature::Verifier, Signature, VerifyingKey},
    EncodedPoint,
};
use risc0_zkvm::guest::env;

fn main() {
    // Decode the verifying key, message, and signature from the inputs.
    let (encoded_verifying_key, message, signature): (EncodedPoint, Vec<u8>, Signature) =
        env::read();
    let verifying_key = VerifyingKey::from_encoded_point(&encoded_verifying_key).unwrap();

    // Verify the signature, panicking if verification fails.
    verifying_key
        .verify(&message, &signature)
        .expect("ECDSA signature verification failed");

    // Commit to the journal the verifying key and message that was signed.
    env::commit(&(encoded_verifying_key, message));
}
```

To be able to use our optimised p256 curve, we need to add the dependencies.

1. Pull the repo from <https://github.com/automata-network/RustCrypto-elliptic-curves/tree/risczero-sm>
2. Update both `Cargo.toml` for `examples/ecdsa` and `examples/ecdsa/methods/guest`to include

   <pre class="language-toml" data-title="examples/ecdsa/Cargo.toml" data-overflow="wrap"><code class="lang-toml">[dependencies]
   # ...
   # replace `yourPath` with the correct path
   p256 = { path = "../yourPath/automata/RustCrypto-elliptic-curves/p256", features = ["serde"] }
   </code></pre>

   &#x20;

   <pre class="language-toml" data-title="examples/ecdsa/methods/guest/Cargo.toml" data-overflow="wrap"><code class="lang-toml">[dependencies]
   # ...
   # replace `yourPath` with the correct path
   p256 = { path = "../../../../../automata/RustCrypto-elliptic-curves/p256", features = ["arithmetic", "serde", "expose-field", "std", "ecdsa"], default_features = false}
   </code></pre>
3. In `Cargo.toml` for `examples/ecdsa/methods/guest` include the [patch](https://github.com/risc0/risc0/blob/release-1.0/examples/ecdsa/methods/guest/Cargo.toml#L13-L18)

   <pre class="language-toml" data-overflow="wrap"><code class="lang-toml">[patch.crates-io]
   # Placing these patch statement in the workspace Cargo.toml will add RISC Zero SHA-256 and bigint
   # multiplication accelerator support for all downstream usages of the following crates.
   sha2 = { git = "https://github.com/risc0/RustCrypto-hashes", tag = "sha2-v0.10.6-risczero.0" }
   crypto-bigint = { git = "https://github.com/risc0/RustCrypto-crypto-bigint", tag = "v0.5.2-risczero.0" }
   </code></pre>
4. Change import from `k256` to `p256` in `main.rs` and `ecdsa_verify.rs`
5. Run `cargo run --release` or `RUST_LOG="[executor]=info" cargo run --release` to get the cycle count
6. This is what you will expect to see if the execution runs successfully

   <figure><img src="https://1780071093-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FeLYKxjsq3SxfdkqYTylK%2Fuploads%2FnuzKiwi17vVPSxETIaEp%2Fimage.png?alt=media&amp;token=4d83c011-ff3a-4e0d-a491-b074f4381c33" alt=""><figcaption><p>Expected execution result</p></figcaption></figure>

And with that, we have come to the end of the documentation :tada:
