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

Bump fastcrypto version #8228

Merged
merged 11 commits into from
Feb 13, 2023
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
16 changes: 8 additions & 8 deletions Cargo.lock

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

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,9 @@ move-prover-boogie-backend = { git = "https://github.com/move-language/move", re
move-stackless-bytecode = { git = "https://github.com/move-language/move", rev = "9b2bbcc14958f37c9adeab933f1e1d6b0db81691" }
move-symbol-pool = { git = "https://github.com/move-language/move", rev = "9b2bbcc14958f37c9adeab933f1e1d6b0db81691" }

fastcrypto = { git = "https://github.com/MystenLabs/fastcrypto", rev = "b2c77ad4aff173462a1270b4ce0be63ef37db06b" }
fastcrypto-zkp = { git = "https://github.com/MystenLabs/fastcrypto", rev = "b2c77ad4aff173462a1270b4ce0be63ef37db06b", package = "fastcrypto-zkp" }
fastcrypto-tbls = { git = "https://github.com/MystenLabs/fastcrypto", rev = "b2c77ad4aff173462a1270b4ce0be63ef37db06b", package = "fastcrypto-tbls" }
fastcrypto = { git = "https://github.com/MystenLabs/fastcrypto", rev = "9a41ba511899c0d7efd9e047af2e968cdc54f77d" }
fastcrypto-zkp = { git = "https://github.com/MystenLabs/fastcrypto", rev = "9a41ba511899c0d7efd9e047af2e968cdc54f77d", package = "fastcrypto-zkp" }
fastcrypto-tbls = { git = "https://github.com/MystenLabs/fastcrypto", rev = "9a41ba511899c0d7efd9e047af2e968cdc54f77d", package = "fastcrypto-tbls" }

# anemo dependencies
anemo = { git = "https://github.com/mystenlabs/anemo.git", rev = "d4017b6cefad7ebc5e84b5c6b8eeff4668f719ff" }
Expand Down
7 changes: 3 additions & 4 deletions crates/sui-core/src/authority.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ use sui_storage::{
IndexStore,
};
use sui_types::committee::{EpochId, ProtocolVersion};
use sui_types::crypto::{sha3_hash, AuthorityKeyPair, NetworkKeyPair};
use sui_types::crypto::{sha3_hash, AuthorityKeyPair, NetworkKeyPair, Signer};
use sui_types::dynamic_field::{DynamicFieldInfo, DynamicFieldType};
use sui_types::event::{Event, EventID};
use sui_types::gas::{GasCostSummary, GasPrice, SuiGasStatus};
Expand Down Expand Up @@ -398,14 +398,13 @@ impl AuthorityMetrics {
}
}

/// a Trait object for `signature::Signer` that is:
/// a Trait object for `Signer` that is:
/// - Pin, i.e. confined to one place in memory (we don't want to copy private keys).
/// - Sync, i.e. can be safely shared between threads.
///
/// Typically instantiated with Box::pin(keypair) where keypair is a `KeyPair`
///
pub type StableSyncAuthoritySigner =
Pin<Arc<dyn signature::Signer<AuthoritySignature> + Send + Sync>>;
pub type StableSyncAuthoritySigner = Pin<Arc<dyn Signer<AuthoritySignature> + Send + Sync>>;

pub struct AuthorityState {
// Fixed size, static, identity of the authority
Expand Down
6 changes: 3 additions & 3 deletions crates/sui-core/src/generate_format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ use move_core_types::{
};
use pretty_assertions::assert_str_eq;
use serde_reflection::{Registry, Result, Samples, Tracer, TracerConfig};
use signature::Signer;
use std::{fs::File, io::Write};
use sui_types::crypto::Signer;
use sui_types::{
base_types::{self, ObjectDigest, ObjectID, TransactionDigest, TransactionEffectsDigest},
crypto::{
Expand Down Expand Up @@ -49,11 +49,11 @@ fn get_registry() -> Result<Registry> {
tracer.trace_value(&mut samples, &s_kp)?;

// We have two signature types: one for Authority Signatures, which don't include the PubKey ...
let sig: AuthoritySignature = kp.sign(b"hello world");
let sig: AuthoritySignature = Signer::sign(&kp, b"hello world");
tracer.trace_value(&mut samples, &sig)?;
// ... and the user signature which does

let sig: Signature = s_kp.sign(b"hello world");
let sig: Signature = Signer::sign(&s_kp, b"hello world");
tracer.trace_value(&mut samples, &sig)?;

// ObjectID and SuiAddress are the same length
Expand Down
3 changes: 1 addition & 2 deletions crates/sui-core/src/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use crate::epoch::committee_store::CommitteeStore;
use crate::test_authority_clients::LocalAuthorityClient;
use fastcrypto::traits::KeyPair;
use prometheus::Registry;
use signature::Signer;
use std::collections::BTreeMap;
use std::path::PathBuf;
use std::sync::Arc;
Expand All @@ -16,11 +15,11 @@ use sui_config::genesis::Genesis;
use sui_config::ValidatorInfo;
use sui_framework_build::compiled_package::{BuildConfig, CompiledPackage};
use sui_types::base_types::ObjectID;
use sui_types::crypto::AuthorityKeyPair;
use sui_types::crypto::{
generate_proof_of_possession, get_key_pair, AccountKeyPair, AuthorityPublicKeyBytes,
NetworkKeyPair, SuiKeyPair,
};
use sui_types::crypto::{AuthorityKeyPair, Signer};
use sui_types::messages::{TransactionData, VerifiedTransaction, DUMMY_GAS_PRICE};
use sui_types::utils::create_fake_transaction;
use sui_types::utils::to_sender_signed_transaction;
Expand Down
16 changes: 8 additions & 8 deletions crates/sui-core/src/unit_tests/authority_aggregator_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ use std::collections::HashSet;
use std::path::PathBuf;
use std::sync::{Arc, Mutex};
use sui_framework_build::compiled_package::BuildConfig;
use sui_types::crypto::AuthoritySignature;
use sui_types::crypto::{
get_authority_key_pair, get_key_pair, AccountKeyPair, AuthorityKeyPair, AuthorityPublicKeyBytes,
};
use sui_types::crypto::{AuthoritySignature, Signer};
use sui_types::crypto::{KeypairTraits, Signature};
use test_utils::sui_system_state::{test_sui_system_state, test_validator};

Expand Down Expand Up @@ -50,7 +50,7 @@ pub fn get_local_client(

pub fn transfer_coin_transaction(
src: SuiAddress,
secret: &dyn signature::Signer<Signature>,
secret: &dyn Signer<Signature>,
dest: SuiAddress,
object_ref: ObjectRef,
gas_object_ref: ObjectRef,
Expand All @@ -69,7 +69,7 @@ pub fn transfer_coin_transaction(

pub fn transfer_object_move_transaction(
src: SuiAddress,
secret: &dyn signature::Signer<Signature>,
secret: &dyn Signer<Signature>,
dest: SuiAddress,
object_ref: ObjectRef,
framework_obj_id: ObjectID,
Expand Down Expand Up @@ -97,7 +97,7 @@ pub fn transfer_object_move_transaction(

pub fn create_object_move_transaction(
src: SuiAddress,
secret: &dyn signature::Signer<Signature>,
secret: &dyn Signer<Signature>,
dest: SuiAddress,
value: u64,
package_id: ObjectID,
Expand Down Expand Up @@ -126,7 +126,7 @@ pub fn create_object_move_transaction(

pub fn delete_object_move_transaction(
src: SuiAddress,
secret: &dyn signature::Signer<Signature>,
secret: &dyn Signer<Signature>,
object_ref: ObjectRef,
framework_obj_id: ObjectID,
gas_object_ref: ObjectRef,
Expand All @@ -148,7 +148,7 @@ pub fn delete_object_move_transaction(

pub fn set_object_move_transaction(
src: SuiAddress,
secret: &dyn signature::Signer<Signature>,
secret: &dyn Signer<Signature>,
object_ref: ObjectRef,
value: u64,
framework_obj_id: ObjectID,
Expand Down Expand Up @@ -933,7 +933,7 @@ fn sign_tx(
tx: VerifiedTransaction,
epoch: EpochId,
authority: AuthorityName,
secret: &dyn signature::Signer<AuthoritySignature>,
secret: &dyn Signer<AuthoritySignature>,
) -> SignedTransaction {
SignedTransaction::new(epoch, tx.into_inner().into_data(), secret, authority)
}
Expand All @@ -942,7 +942,7 @@ fn sign_tx_effects(
effects: TransactionEffects,
epoch: EpochId,
authority: AuthorityName,
secret: &dyn signature::Signer<AuthoritySignature>,
secret: &dyn Signer<AuthoritySignature>,
) -> SignedTransactionEffects {
SignedTransactionEffects::new(epoch, effects, secret, authority)
}
Expand Down
3 changes: 1 addition & 2 deletions crates/sui-framework/src/natives/crypto/bls12381.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
use crate::legacy_empty_cost;
use fastcrypto::{
bls12381::{min_pk, min_sig},
traits::ToFromBytes,
Verifier,
traits::{ToFromBytes, VerifyingKey},
};
use move_binary_format::errors::PartialVMResult;
use move_vm_runtime::native_functions::NativeContext;
Expand Down
19 changes: 7 additions & 12 deletions crates/sui-framework/src/natives/crypto/ecdsa_k1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
use crate::legacy_empty_cost;
use fastcrypto::{
secp256k1::{
recoverable::{Secp256k1RecoverablePublicKey, Secp256k1RecoverableSignature},
Secp256k1PublicKey, Secp256k1Signature,
recoverable::Secp256k1RecoverableSignature, Secp256k1PublicKey, Secp256k1Signature,
},
traits::ToFromBytes,
};
Expand Down Expand Up @@ -52,10 +51,7 @@ pub fn ecrecover(
}
}

fn recover_pubkey(
signature: &[u8],
hashed_msg: &[u8],
) -> Result<Secp256k1RecoverablePublicKey, SuiError> {
fn recover_pubkey(signature: &[u8], hashed_msg: &[u8]) -> Result<Secp256k1PublicKey, SuiError> {
match <Secp256k1RecoverableSignature as ToFromBytes>::from_bytes(signature) {
Ok(signature) => match signature.recover_hashed(hashed_msg) {
Ok(pubkey) => Ok(pubkey),
Expand Down Expand Up @@ -153,14 +149,13 @@ pub fn secp256k1_verify_recoverable(
Err(_) => return Ok(NativeResult::ok(cost, smallvec![Value::bool(false)])),
};

let public_key =
match <Secp256k1RecoverablePublicKey as ToFromBytes>::from_bytes(&public_key_bytes_ref) {
Ok(public_key) => public_key,
Err(_) => return Ok(NativeResult::ok(cost, smallvec![Value::bool(false)])),
};
let public_key = match <Secp256k1PublicKey as ToFromBytes>::from_bytes(&public_key_bytes_ref) {
Ok(public_key) => public_key,
Err(_) => return Ok(NativeResult::ok(cost, smallvec![Value::bool(false)])),
};

let result = public_key
.verify_hashed(&hashed_msg_ref, &signature)
.verify_recoverable_hashed(&hashed_msg_ref, &signature)
.is_ok();
Ok(NativeResult::ok(cost, smallvec![Value::bool(result)]))
}
3 changes: 1 addition & 2 deletions crates/sui-framework/src/natives/crypto/ed25519.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
use crate::legacy_empty_cost;
use fastcrypto::{
ed25519::{Ed25519PublicKey, Ed25519Signature},
traits::ToFromBytes,
Verifier,
traits::{ToFromBytes, VerifyingKey},
};
use move_binary_format::errors::PartialVMResult;
use move_vm_runtime::native_functions::NativeContext;
Expand Down
2 changes: 1 addition & 1 deletion crates/sui-json-rpc/src/transaction_execution_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ use crate::SuiRpcModule;
use anyhow::anyhow;
use async_trait::async_trait;
use fastcrypto::encoding::Base64;
use fastcrypto::traits::ToFromBytes;
use jsonrpsee::core::RpcResult;
use jsonrpsee::RpcModule;
use move_bytecode_utils::module_cache::SyncModuleCache;
use mysten_metrics::spawn_monitored_task;
use signature::Signature;
use std::sync::Arc;
use sui_core::authority::{AuthorityStore, ResolverWrapper};
use sui_core::authority_client::NetworkAuthorityClient;
Expand Down
13 changes: 7 additions & 6 deletions crates/sui-keys/src/keystore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use bip32::DerivationPath;
use bip39::{Language, Mnemonic, Seed};
use rand::{rngs::StdRng, SeedableRng};
use serde::{Deserialize, Deserializer, Serialize, Serializer};
use signature::Signer;
use std::collections::BTreeMap;
use std::fmt::Write;
use std::fmt::{Display, Formatter};
Expand All @@ -19,7 +18,7 @@ use sui_types::intent::{Intent, IntentMessage};
use sui_types::base_types::SuiAddress;
use sui_types::crypto::{
enum_dispatch, get_key_pair_from_rng, EncodeDecodeBase64, PublicKey, Signature,
SignatureScheme, SuiKeyPair,
SignatureScheme, Signer, SuiKeyPair,
};

use crate::key_derive::{derive_key_pair_from_path, generate_new_key};
Expand Down Expand Up @@ -131,12 +130,13 @@ impl<'de> Deserialize<'de> for FileBasedKeystore {
impl AccountKeystore for FileBasedKeystore {
#[warn(deprecated)]
fn sign(&self, address: &SuiAddress, msg: &[u8]) -> Result<Signature, signature::Error> {
self.keys
Ok(self
.keys
.get(address)
.ok_or_else(|| {
signature::Error::from_source(format!("Cannot find key for address: [{address}]"))
})?
.try_sign(msg)
.sign(msg))
}

fn sign_secure<T>(
Expand Down Expand Up @@ -230,12 +230,13 @@ pub struct InMemKeystore {
impl AccountKeystore for InMemKeystore {
#[warn(deprecated)]
fn sign(&self, address: &SuiAddress, msg: &[u8]) -> Result<Signature, signature::Error> {
self.keys
Ok(self
.keys
.get(address)
.ok_or_else(|| {
signature::Error::from_source(format!("Cannot find key for address: [{address}]"))
})?
.try_sign(msg)
.sign(msg))
}

fn sign_secure<T>(
Expand Down
Loading