Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,15 @@ members = [
"jolt-inlines/blake2",
"jolt-inlines/blake3",
"jolt-inlines/bigint",
"jolt-inlines/secp256k1",
"examples/btreemap/host",
"examples/btreemap/guest",
"examples/collatz",
"examples/collatz/guest",
"examples/fibonacci",
"examples/fibonacci/guest",
"examples/secp256k1-ecdsa-verify",
"examples/secp256k1-ecdsa-verify/guest",
"examples/sha2-ex",
"examples/sha2-ex/guest",
"examples/sha3-ex",
Expand Down Expand Up @@ -140,6 +143,7 @@ ark-ff = { git = "https://github.com/a16z/arkworks-algebra", branch = "dev/twist
ark-serialize = { git = "https://github.com/a16z/arkworks-algebra", branch = "dev/twist-shout", default-features = false, features = [
"derive",
] }
ark-secp256k1 = { git = "https://github.com/a16z/arkworks-algebra", branch = "dev/twist-shout", default-features = false }
ark-serialize-derive = { version = "0.5.0", default-features = false }
ark-std = { version = "0.5.0", default-features = false }
sha2 = "0.10"
Expand Down Expand Up @@ -181,6 +185,7 @@ toml_edit = "0.22.14"
# Numeric
num = "0.4.3"
num-integer = "0.1.45"
num-bigint = { version = "0.4.6", default-features = false }
num-derive = "0.4.2"
num-traits = "0.2.19"

Expand Down Expand Up @@ -225,6 +230,7 @@ getrandom_v03 = { version = "0.3.3", package = "getrandom", default-features = f
# Build and Development
ctor = { version = "0.2" }
hex-literal = "0.4.1"
hex = "0.4.3"
spinners = { version = "4.1.1", default-features = false }

# Testing
Expand All @@ -244,3 +250,4 @@ jolt-inlines-keccak256 = { path = "./jolt-inlines/keccak256", default-features =
jolt-inlines-blake2 = { path = "./jolt-inlines/blake2", default-features = false }
jolt-inlines-blake3 = { path = "./jolt-inlines/blake3", default-features = false }
jolt-inlines-bigint = { path = "./jolt-inlines/bigint", default-features = false }
jolt-inlines-secp256k1 = { path = "./jolt-inlines/secp256k1", default-features = false }
33 changes: 33 additions & 0 deletions book/src/how/optimizations/inlines.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,39 @@ unsafe {
}
```

Additional inlines for Secp256k1 operations are available but wrapped in a higher-level API. See `jolt-inlines/secp256k1` for details and `examples/secp256k1-ecdsa-verify` for an example of a higher-level ECDSA verification function using the Secp256k1 inlines.

## Error Handling in Secp256k1

When working with inlines that can fail (like cryptographic verification), it's important to understand how different error handling approaches affect the resulting proof.

**Return `Result`** - Use when you want the guest program to handle errors gracefully:
```rust
let result = ecdsa_verify(z, r, s, q);
match result {
Ok(()) => { /* signature valid */ }
Err(e) => { /* handle invalid signature */ }
}
```
The proof is valid regardless of the outcome and proves which branch was taken.

**`.unwrap()`** - Use when an error is unexpected and should terminate execution:
```rust
ecdsa_verify(z, r, s, q).unwrap();
```
If verification fails, the program panics. The proof is still valid and proves that the program panicked at this point.

**`.unwrap_or_spoil_proof()`** - Use when you want to **assert** a condition such that no valid proof can exist if it fails:
```rust
use jolt_inlines_secp256k1::UnwrapOrSpoilProof;

ecdsa_verify(z, r, s, q).unwrap_or_spoil_proof();
```
If verification fails, the proof becomes unsatisfiable. This is appropriate when:
- You want to prove "the signature IS valid" (not "I checked the signature")
- A malicious prover should not be able to produce any proof if the condition fails
- The error case represents something that should be cryptographically impossible

## Benchmarks

The table below compares the performance of reference and inline implementations for each hash function, using identical 32KB inputs and the same API across both reference and inline implementations.
Expand Down
6 changes: 3 additions & 3 deletions examples/alloc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ version = "0.1.0"
edition = "2021"

[dependencies]
jolt-sdk = { path = "../../jolt-sdk", features = ["host"] }
tracing-subscriber = "0.3"
tracing = "0.1"
jolt-sdk = { workspace = true, features = ["host"] }
tracing-subscriber.workspace = true
tracing.workspace = true
guest = { package = "alloc-guest", path = "./guest" }
6 changes: 3 additions & 3 deletions examples/btreemap/host/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ version = "0.1.0"
edition = "2021"

[dependencies]
jolt-sdk = { path = "../../../jolt-sdk", features = ["host"] }
tracing-subscriber = "0.3"
tracing = "0.1"
jolt-sdk = { workspace = true, features = ["host"] }
tracing-subscriber.workspace = true
tracing.workspace = true
guest = { package = "btreemap-guest", path = "../guest" }
spinners = { workspace = true }
6 changes: 3 additions & 3 deletions examples/collatz/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ version = "0.1.0"
edition = "2021"

[dependencies]
jolt-sdk = { path = "../../jolt-sdk", features = ["host"] }
tracing-subscriber = "0.3"
tracing = "0.1"
jolt-sdk = { workspace = true, features = ["host"] }
tracing-subscriber.workspace = true
tracing.workspace = true
guest = { package = "collatz-guest", path = "./guest" }
6 changes: 3 additions & 3 deletions examples/fibonacci/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ version = "0.1.0"
edition = "2021"

[dependencies]
jolt-sdk = { path = "../../jolt-sdk", features = ["host"] }
tracing-subscriber = "0.3"
tracing = "0.1"
jolt-sdk = { workspace = true, features = ["host"] }
tracing-subscriber.workspace = true
tracing.workspace = true
guest = { package = "fibonacci-guest", path = "./guest" }

16 changes: 8 additions & 8 deletions examples/hash-bench/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ version = "0.1.0"
edition = "2021"

[dependencies]
jolt-sdk = { path = "../../jolt-sdk", features = ["host"] }
tracing-subscriber = "0.3"
tracing = "0.1"
jolt-inlines-sha2 = { path = "../../jolt-inlines/sha2", features = ["host"] }
jolt-inlines-keccak256 = { path = "../../jolt-inlines/keccak256", features = ["host"] }
jolt-inlines-blake2 = { path = "../../jolt-inlines/blake2", features = ["host"] }
jolt-inlines-blake3 = { path = "../../jolt-inlines/blake3", features = ["host"] }
jolt-sdk = { workspace = true, features = ["host"] }
tracing-subscriber.workspace = true
tracing.workspace = true
jolt-inlines-sha2 = { workspace = true, features = ["host"] }
jolt-inlines-keccak256 = { workspace = true, features = ["host"] }
jolt-inlines-blake2 = { workspace = true, features = ["host"] }
jolt-inlines-blake3 = { workspace = true, features = ["host"] }
guest = { package = "hashbench-guest", path = "./guest" }
hex = "0.4.3"
hex.workspace = true
8 changes: 4 additions & 4 deletions examples/hash-bench/guest/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ guest = []

[dependencies]
jolt = { package = "jolt-sdk", path = "../../../jolt-sdk", features = [] }
jolt-inlines-sha2 = { package = "jolt-inlines-sha2", path = "../../../jolt-inlines/sha2" }
jolt-inlines-keccak256 = { package = "jolt-inlines-keccak256", path = "../../../jolt-inlines/keccak256" }
jolt-inlines-blake2 = { package = "jolt-inlines-blake2", path = "../../../jolt-inlines/blake2" }
jolt-inlines-blake3 = { package = "jolt-inlines-blake3", path = "../../../jolt-inlines/blake3" }
jolt-inlines-sha2.workspace = true
jolt-inlines-keccak256.workspace = true
jolt-inlines-blake2.workspace = true
jolt-inlines-blake3.workspace = true

sha2 = { version = "0.10.9", default-features = false }
sha3 = { version = "0.10", default-features = false }
Expand Down
2 changes: 1 addition & 1 deletion examples/malloc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ version = "0.1.0"
edition = "2021"

[dependencies]
jolt-sdk = { path = "../../jolt-sdk", features = ["host"] }
jolt-sdk = { workspace = true, features = ["host"] }
guest = { package = "malloc-guest", path = "./guest" }
6 changes: 3 additions & 3 deletions examples/memory-ops/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ version = "0.1.0"
edition = "2021"

[dependencies]
jolt-sdk = { path = "../../jolt-sdk", features = ["host"] }
tracing-subscriber = "0.3"
tracing = "0.1"
jolt-sdk = { workspace = true, features = ["host"] }
tracing-subscriber.workspace = true
tracing.workspace = true
guest = { package = "memory-ops-guest", path = "./guest" }

hex = "0.4.3"
10 changes: 5 additions & 5 deletions examples/merkle-tree/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ version = "0.1.0"
edition = "2021"

[dependencies]
jolt-sdk = { path = "../../jolt-sdk", features = ["host"] }
tracing-subscriber = "0.3"
tracing = "0.1"
jolt-inlines-sha2 = { path = "../../jolt-inlines/sha2", features = ["host"] }
jolt-sdk = { workspace = true, features = ["host"] }
tracing-subscriber.workspace = true
tracing.workspace = true
jolt-inlines-sha2 = { workspace = true, features = ["host"] }
guest = { package = "merkle-tree-guest", path = "./guest" }

hex = "0.4.3"
hex.workspace = true
2 changes: 1 addition & 1 deletion examples/merkle-tree/guest/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ guest = []

[dependencies]
jolt = { package = "jolt-sdk", path = "../../../jolt-sdk", features = [] }
jolt-inlines-sha2 = { package = "jolt-inlines-sha2", path = "../../../jolt-inlines/sha2" }
jolt-inlines-sha2.workspace = true
6 changes: 3 additions & 3 deletions examples/muldiv/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ version = "0.1.0"
edition = "2021"

[dependencies]
jolt-sdk = { path = "../../jolt-sdk", features = ["host"] }
tracing-subscriber = "0.3"
tracing = "0.1"
jolt-sdk = { workspace = true, features = ["host"] }
tracing-subscriber.workspace = true
tracing.workspace = true
guest = { package = "muldiv-guest", path = "./guest" }
6 changes: 3 additions & 3 deletions examples/multi-function/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ version = "0.1.0"
edition = "2021"

[dependencies]
jolt-sdk = { path = "../../jolt-sdk", features = ["host"] }
tracing-subscriber = "0.3"
tracing = "0.1"
jolt-sdk = { workspace = true, features = ["host"] }
tracing-subscriber.workspace = true
tracing.workspace = true
guest = { package = "multi-function-guest", path = "./guest" }

6 changes: 3 additions & 3 deletions examples/overflow/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ version = "0.1.0"
edition = "2021"

[dependencies]
jolt-sdk = { path = "../../jolt-sdk", features = ["host"] }
tracing-subscriber = "0.3"
tracing = "0.1"
jolt-sdk = { workspace = true, features = ["host"] }
tracing-subscriber.workspace = true
tracing.workspace = true
guest = { package = "overflow-guest", path = "./guest" }
6 changes: 3 additions & 3 deletions examples/random/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ version = "0.1.0"
edition = "2021"

[dependencies]
jolt-sdk = { path = "../../jolt-sdk", features = ["host"] }
tracing-subscriber = "0.3"
tracing = "0.1"
jolt-sdk = { workspace = true, features = ["host"] }
tracing-subscriber.workspace = true
tracing.workspace = true
guest = { package = "random-guest", path = "./guest" }
6 changes: 3 additions & 3 deletions examples/recover-ecdsa/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ version = "0.1.0"
edition = "2021"

[dependencies]
jolt-sdk = { path = "../../jolt-sdk", features = ["host"] }
tracing-subscriber = "0.3"
tracing = "0.1"
jolt-sdk = { workspace = true, features = ["host"] }
tracing-subscriber.workspace = true
tracing.workspace = true
guest = { package = "recover-ecdsa-guest", path = "./guest" }
secp256k1 = { version = "0.30", default-features = false, features = ["alloc", "recovery", "serde"] }
12 changes: 6 additions & 6 deletions examples/recursion/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ name = "recursion"
path = "src/main.rs"

[dependencies]
jolt-sdk = { path = "../../jolt-sdk", features = ["host"] }
tracing-subscriber = "0.3"
tracing = "0.1"
ark-serialize = { version = "0.5.0", default-features = false }
postcard = { version = "1.0.8", default-features = false, features = ["use-std"] }
clap = { version = "4.0", features = ["derive"] }
jolt-sdk = { workspace = true, features = ["host"] }
tracing-subscriber.workspace = true
tracing.workspace = true
ark-serialize.workspace = true
postcard.workspace = true
clap.workspace = true
4 changes: 2 additions & 2 deletions examples/recursion/guest/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ guest = []

[dependencies]
jolt_sdk = { package = "jolt-sdk", path = "../../../jolt-sdk", features = ["guest-verifier"] }
postcard = { version = "1.0.8", default-features = false, features = ["use-std"] }
ark-serialize = { version = "0.5.0", default-features = false }
postcard.workspace = true
ark-serialize.workspace = true
11 changes: 11 additions & 0 deletions examples/secp256k1-ecdsa-verify/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[package]
name = "secp256k1-ecdsa-verify"
version = "0.1.0"
edition = "2021"

[dependencies]
jolt-sdk = { workspace = true, features = ["host"] }
tracing-subscriber.workspace = true
tracing.workspace = true
jolt-inlines-secp256k1 = { workspace = true, features = ["host"] }
guest = { package = "secp256k1-ecdsa-verify-guest", path = "./guest" }
11 changes: 11 additions & 0 deletions examples/secp256k1-ecdsa-verify/guest/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[package]
name = "secp256k1-ecdsa-verify-guest"
version = "0.1.0"
edition = "2021"

[features]
guest = []

[dependencies]
jolt = { package = "jolt-sdk", path = "../../../jolt-sdk" }
jolt-inlines-secp256k1.workspace = true
Loading