Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: hint if the point can be decompressed #10

Open
wants to merge 1 commit into
base: patch-curve25519-v4.1.3
Choose a base branch
from
Open
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
5 changes: 5 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,8 @@ resolver = "2"
[profile.dev]
opt-level = 2


[patch.crates-io]
sp1-lib = { git = "https://github.com/succinctlabs/sp1", branch = "n/fix-eddcompress" }
sp1-curves = { git = "https://github.com/succinctlabs/sp1", branch = "n/fix-eddcompress" }

1 change: 1 addition & 0 deletions curve25519-dalek/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ fiat-crypto = { version = "0.2.1", default-features = false }

[target.'cfg(all(target_os = "zkvm", target_vendor = "succinct"))'.dependencies]
sp1-lib = "3.0.0"
sp1-curves = "3.0.0"
anyhow = "1.0"

[features]
Expand Down
19 changes: 15 additions & 4 deletions curve25519-dalek/src/edwards.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,12 +230,22 @@ impl CompressedEdwardsY {
self.0
}

#[cfg(not(all(target_os = "zkvm", target_vendor = "succinct")))]
/// Attempt to decompress to an `EdwardsPoint`.
///
/// Returns `None` if the input is not the \\(y\\)-coordinate of a
/// curve point.
pub fn decompress(&self) -> Option<EdwardsPoint> {
#[cfg(all(target_os = "zkvm", target_vendor = "succinct"))]
{
sp1_lib::unconstrained! {
sp1_lib::io::write(sp1_lib::io::FD_EDDECOMPRESS, self.as_bytes());
}

if sp1_lib::io::read_vec().first().expect("We should have a status from the hook") == &1 {
return Some(self.decompress_with_syscall());
}
}

let (is_valid_y_coord, X, Y, Z) = decompress::step_1(self);

if is_valid_y_coord.into() {
Expand All @@ -252,7 +262,7 @@ impl CompressedEdwardsY {
/// curve point.
///
/// Accelerated with SP1's EdDecompress syscall.
pub fn decompress(&self) -> Option<EdwardsPoint> {
fn decompress_with_syscall(&self) -> EdwardsPoint {
let mut XY_bytes = [0_u8; 64];
XY_bytes[32..].copy_from_slice(self.as_bytes());
unsafe {
Expand All @@ -261,12 +271,13 @@ impl CompressedEdwardsY {
let X = FieldElement::from_bytes(&XY_bytes[0..32].try_into().unwrap());
let Y = FieldElement::from_bytes(&XY_bytes[32..].try_into().unwrap());
let Z = FieldElement::ONE;
return Some(EdwardsPoint {

EdwardsPoint {
X,
Y,
Z,
T: &X * &Y,
});
}
}
}

Expand Down
3 changes: 0 additions & 3 deletions curve25519-dalek/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,6 @@ extern crate alloc;
#[macro_use]
extern crate std;

#[cfg(all(target_os = "zkvm", target_vendor = "succinct"))]
extern crate sp1_lib;

#[cfg(feature = "digest")]
pub use digest;

Expand Down