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

common: remove contracts dep #897

Closed
wants to merge 1 commit into from
Closed
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
common: remove contracts dep
akirillo committed Jan 26, 2025
commit 1e71d8ac4a9846f22991fe395d58981cb341a4bb
2 changes: 1 addition & 1 deletion Cargo.lock

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

6 changes: 2 additions & 4 deletions common/Cargo.toml
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@ edition = "2021"
[features]
default = ["all-types"]
hmac = []
wallet = ["hmac", "proof-system-types", "util/matching-engine"]
wallet = ["hmac", "proof-system-types", "util/matching-engine", "ark-ff"]
proof-system-types = ["dep:circuits", "constants/default"]
# Types used by the relayer for internal operation
# We add this feature flag to allow external clients to opt-out of these types
@@ -27,6 +27,7 @@ mocks = [
ark-mpc = { workspace = true }
ark-ec = { version = "0.4", optional = true }
ark-poly = { version = "0.4", optional = true }
ark-ff = { version = "0.4", optional = true }

ecdsa = { version = "0.16", optional = true }
ed25519-dalek = { version = "1.0.1", features = ["serde"] }
@@ -56,9 +57,6 @@ constants = { path = "../constants", default-features = false }
renegade-crypto = { path = "../renegade-crypto" }
util = { path = "../util" }

# === Contracts Repo Dependencies === #
contracts-common = { git = "https://github.com/renegade-fi/renegade-contracts.git" }

# === Misc Dependencies === #
base64 = { version = "0.22" }
bimap = "0.6.2"
5 changes: 1 addition & 4 deletions common/src/types/tasks/descriptors/mod.rs
Original file line number Diff line number Diff line change
@@ -210,7 +210,6 @@ impl TaskDescriptor {
pub mod mocks {
use circuit_types::keychain::SecretSigningKey;
use constants::Scalar;
use contracts_common::custom_serde::BytesSerializable;
use ethers::core::utils::keccak256;
use ethers::signers::Wallet as EthersWallet;
use k256::ecdsa::SigningKey as K256SigningKey;
@@ -227,9 +226,7 @@ pub mod mocks {
pub fn gen_wallet_update_sig(wallet: &Wallet, key: &SecretSigningKey) -> Vec<u8> {
let new_wallet_comm = wallet.get_wallet_share_commitment();

// Serialize the commitment, uses the contract's serialization here:
// https://github.com/renegade-fi/renegade-contracts/blob/main/contracts-common/src/custom_serde.rs#L82-L87
let comm_bytes = new_wallet_comm.inner().serialize_to_bytes();
let comm_bytes = Wallet::serialize_commitment(new_wallet_comm);
let digest = keccak256(comm_bytes);

// Sign the message
5 changes: 1 addition & 4 deletions common/src/types/tasks/descriptors/update_wallet.rs
Original file line number Diff line number Diff line change
@@ -2,7 +2,6 @@

use circuit_types::{keychain::PublicSigningKey, Amount};
use constants::Scalar;
use contracts_common::custom_serde::BytesSerializable;
use ethers::core::types::Signature;
use ethers::utils::{keccak256, public_key_to_address};
use k256::ecdsa::VerifyingKey as K256VerifyingKey;
@@ -212,9 +211,7 @@ pub fn verify_wallet_update_signature(
let key: K256VerifyingKey = key.into();
let new_wallet_comm = wallet.get_wallet_share_commitment();

// Serialize the commitment, uses the contract's serialization here:
// https://github.com/renegade-fi/renegade-contracts/blob/main/contracts-common/src/custom_serde.rs#L82-L87
let comm_bytes = new_wallet_comm.inner().serialize_to_bytes();
let comm_bytes = Wallet::serialize_commitment(new_wallet_comm);
let digest = keccak256(comm_bytes);

// Verify the signature
10 changes: 8 additions & 2 deletions common/src/types/wallet/keychain.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
//! Keychain helpers for the wallet

use ark_ff::{BigInteger, PrimeField};
use circuit_types::keychain::{
PublicIdentificationKey, PublicKeyChain, PublicSigningKey, SecretIdentificationKey,
SecretSigningKey,
};
use constants::Scalar;
use contracts_common::custom_serde::BytesSerializable;
use derivative::Derivative;
use ethers::{
core::k256::ecdsa::SigningKey as EthersSigningKey,
@@ -113,7 +113,7 @@ impl Wallet {
let key = EthersSigningKey::try_from(root_key)?;

// Hash the message and sign it
let comm_bytes = commitment.inner().serialize_to_bytes();
let comm_bytes = Self::serialize_commitment(commitment);
let digest = keccak256(comm_bytes);
let (sig, recovery_id) = key
.sign_prehash_recoverable(&digest)
@@ -125,6 +125,12 @@ impl Wallet {
v: recovery_id.to_byte() as u64,
})
}

/// Serialize the commitment, uses the contract's serialization here:
/// https://github.com/renegade-fi/renegade-contracts/blob/main/contracts-common/src/custom_serde.rs#L82-L87
pub fn serialize_commitment(commitment: Scalar) -> Vec<u8> {
commitment.inner().into_bigint().to_bytes_be()
}
}

#[cfg(test)]