Skip to content

Commit

Permalink
Merge pull request #721 from kettlebell/ecpoint_derive_from
Browse files Browse the repository at this point in the history
`EcPoint` derive from `ProjectivePoint` + update `k256` dependency
  • Loading branch information
greenhat committed Sep 4, 2023
2 parents 5b1291c + daf06a9 commit 418e8e7
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 13 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ ergo-nipopow = { version = "^0.11", path = "./ergo-nipopow" }
ergo-merkle-tree = { version = "^0.11.0", path = "./ergo-merkle-tree" }
ergo-rest = { version = "^0.9.0", path = "./ergo-rest" }
ergo-lib = { version = "^0.24.0", path = "./ergo-lib"}
k256 = { version = "0.11", features = ["arithmetic", "ecdsa"] }
k256 = { version = "0.13.1", features = ["arithmetic", "ecdsa"] }
elliptic-curve = {version = "0.12", features = [ "ff"]}
thiserror = "1"
bounded-vec = { version = "^0.7.0" }
Expand Down
5 changes: 3 additions & 2 deletions ergo-chain-types/src/ec_point.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! Elliptic curve point.

use elliptic_curve::group::prime::PrimeCurveAffine;
use derive_more::From;
use k256::elliptic_curve::group::prime::PrimeCurveAffine;
use k256::elliptic_curve::sec1::ToEncodedPoint;
use k256::{ProjectivePoint, PublicKey, Scalar};
use sigma_ser::vlq_encode::{ReadSigmaVlqExt, WriteSigmaVlqExt};
Expand All @@ -9,7 +10,7 @@ use std::convert::TryFrom;
use std::ops::{Add, Mul, Neg};

/// Elliptic curve point
#[derive(PartialEq, Clone, Default)]
#[derive(PartialEq, Clone, Default, From)]
#[cfg_attr(
feature = "json",
derive(serde::Serialize, serde::Deserialize),
Expand Down
4 changes: 2 additions & 2 deletions ergotree-interpreter/src/sigma_protocol/private_input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
use std::convert::TryInto;
use std::fmt::Formatter;

use elliptic_curve::group::ff::PrimeField;
use ergo_chain_types::EcPoint;
use ergotree_ir::serialization::SigmaSerializable;
use ergotree_ir::sigma_protocol::dlog_group;
Expand All @@ -13,6 +12,7 @@ use ergotree_ir::sigma_protocol::sigma_boolean::SigmaBoolean;

extern crate derive_more;
use derive_more::From;
use k256::elliptic_curve::PrimeField;
use num_bigint::BigUint;
use num_traits::ToPrimitive;

Expand Down Expand Up @@ -155,7 +155,7 @@ impl DhTupleProverInput {
#[allow(clippy::unwrap_used)]
pub fn to_bytes(&self) -> [u8; DhTupleProverInput::SIZE_BYTES] {
let mut bytes = Vec::with_capacity(DhTupleProverInput::SIZE_BYTES);
bytes.extend_from_slice(&self.w.as_scalar_ref().to_bytes());
bytes.extend_from_slice(self.w.as_scalar_ref().to_bytes().as_slice());
bytes.extend_from_slice(&self.common_input.g.sigma_serialize_bytes().unwrap());
bytes.extend_from_slice(&self.common_input.h.sigma_serialize_bytes().unwrap());
bytes.extend_from_slice(&self.common_input.u.sigma_serialize_bytes().unwrap());
Expand Down
10 changes: 5 additions & 5 deletions ergotree-interpreter/src/sigma_protocol/wscalar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ use std::fmt::Formatter;

use derive_more::From;
use derive_more::Into;
use elliptic_curve::generic_array::GenericArray;
use elliptic_curve::ops::Reduce;
use ergo_chain_types::Base16DecodedBytes;
use ergo_chain_types::Base16EncodedBytes;
use k256::elliptic_curve::generic_array::GenericArray;
use k256::elliptic_curve::ops::Reduce;
use k256::Scalar;
use k256::U256;

Expand Down Expand Up @@ -40,7 +40,7 @@ impl Wscalar {
impl From<GroupSizedBytes> for Wscalar {
fn from(b: GroupSizedBytes) -> Self {
let sl: &[u8] = b.0.as_ref();
let s = <Scalar as Reduce<U256>>::from_be_bytes_reduced(GenericArray::clone_from_slice(sl));
let s = <Scalar as Reduce<U256>>::reduce_bytes(&GenericArray::clone_from_slice(sl));
Wscalar(s)
}
}
Expand All @@ -51,7 +51,7 @@ impl From<Challenge> for Scalar {
// prepend zeroes to 32 bytes (big-endian)
let mut prefix = vec![0u8; 8];
prefix.append(&mut v.to_vec());
<Scalar as Reduce<U256>>::from_be_bytes_reduced(GenericArray::clone_from_slice(&prefix))
<Scalar as Reduce<U256>>::reduce_bytes(&GenericArray::clone_from_slice(&prefix))
}
}

Expand Down Expand Up @@ -85,7 +85,7 @@ mod arbitrary {
use crate::sigma_protocol::GROUP_SIZE;

use super::Wscalar;
use elliptic_curve::{generic_array::GenericArray, PrimeField};
use k256::elliptic_curve::{generic_array::GenericArray, PrimeField};
use k256::Scalar;
use proptest::{collection::vec, prelude::*};

Expand Down
6 changes: 3 additions & 3 deletions ergotree-ir/src/sigma_protocol/dlog_group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ use crate::serialization::SigmaSerializeResult;
use crate::serialization::{
sigma_byte_reader::SigmaByteRead, SigmaParsingError, SigmaSerializable,
};
use elliptic_curve::group::ff::PrimeField;
use elliptic_curve::rand_core::RngCore;
use k256::elliptic_curve::PrimeField;
use k256::Scalar;
use num_bigint::Sign;
use num_bigint::ToBigUint;
Expand All @@ -39,8 +39,8 @@ use std::convert::TryFrom;

/// Creates a random scalar, a big-endian integer in the range [0, n), where n is group order
/// Use cryptographically secure PRNG (like rand::thread_rng())
pub fn random_scalar_in_group_range(rng: impl RngCore) -> Scalar {
Scalar::generate_vartime(rng)
pub fn random_scalar_in_group_range(mut rng: impl RngCore) -> Scalar {
Scalar::generate_vartime(&mut rng)
}

/// Attempts to create BigInt256 from Scalar
Expand Down

0 comments on commit 418e8e7

Please sign in to comment.