Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
72 changes: 72 additions & 0 deletions rust-src/concordium_base/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,77 @@
## Unreleased

- The flag `serde_deprecated` now guards `serde::Serialize` and `serde::Deserialize` implemetations on the following types. The implementations will eventually be removed.
- `protocol_level_tokens::token_metadata_url::MetadataUrl`
- `protocol_level_tokens::token_amount::TokenAmount`
- `protocol_level_tokens::token_amount::TokenAmountJson`
- `protocol_level_tokens::token_reject_reason::TokenModuleRejectReason`
- `protocol_level_tokens::token_reject_reason::TokenModuleRejectReasonType`
- `protocol_level_tokens::token_reject_reason::AddressNotFoundRejectReason`
- `protocol_level_tokens::token_reject_reason::TokenBalanceInsufficientRejectReason`
- `protocol_level_tokens::token_reject_reason::DeserializationFailureRejectReason`
- `protocol_level_tokens::token_reject_reason::UnsupportedOperationRejectReason`
- `protocol_level_tokens::token_reject_reason::OperationNotPermittedRejectReason`
- `protocol_level_tokens::token_reject_reason::MintWouldOverflowRejectReason`
- `protocol_level_tokens::token_operations::TokenOperationsPayload`
- `protocol_level_tokens::token_operations::TokenSupplyUpdateDetails`
- `protocol_level_tokens::token_operations::TokenPauseDetails`
- `protocol_level_tokens::token_operations::TokenListUpdateDetails`
- `protocol_level_tokens::token_operations::TokenTransfer`
- `protocol_level_tokens::token_operations::CborMemo`
- `protocol_level_tokens::token_event::TokenEvent`
- `protocol_level_tokens::token_event::TokenEventDetails`
- `protocol_level_tokens::token_event::TokenModuleEvent`
- `protocol_level_tokens::token_event::TokenModuleEventType`
- `protocol_level_tokens::token_event::TokenListUpdateEventDetails`
- `protocol_level_tokens::token_event::TokenPauseEventDetails`
- `protocol_level_tokens::token_event::TokenHolder`
- `protocol_level_tokens::token_event::TokenTransferEvent`
- `protocol_level_tokens::token_event::TokenSupplyUpdateEvent`
- `protocol_level_tokens::token_holder::CborHolderAccount`
- `common::types::TransactionSignature`
- `smart_contracts::WasmModule`
- `smart_contracts::InstanceUpdatedEvent`
- `transaction::TransactionHeader`
- `transaction::AccountTransaction`
- `transaction::BakerKeysPayload`
- `transaction::AddBakerPayload`
- `transaction::InitContractPayload`
- `transaction::UpdateContractPayload`
- `transaction::ConfigureBakerPayload`
- `transaction::ConfigureDelegationPayload`
- `transaction::Payload`
- `transaction::PreAccountTransaction`
- `base::DelegationTarget`
- `base::CommissionRates`
- `base::CommissionRanges`
- `base::InclusiveRange`
- `base::MintDistributionV0`
- `base::MintDistributionV1`
- `update::ProtocolUpdate`
- `update::TransactionFeeDistribution`
- `update::GASRewards`
- `update::GASRewardsV1`
- `update::RootUpdate`
- `update::Level1Update`
- `update::HigherLevelAccessStructure`
- `update::AccessStructure`
- `update::AuthorizationsV0`
- `update::AuthorizationsV1`
- `update::BakerParameters`
- `update::CooldownParameters`
- `update::TimeoutParameters`
- `update::RewardPeriodLength`
- `update::TimeParameters`
- `update::PoolParameters`
- `update::FinalizationCommitteeParameters`
- `update::ValidatorScoreParameters`
- `update::UpdatePayload`
- `update::CreatePlt`
- `encrypted_transfers::types::IndexedEncryptedAmount`
- `encrypted_transfers::types::EncryptedAmountTransferData`
- `encrypted_transfers::types::SecToPubAmountTransferData`
- `encrypted_transfers::types::AggregatedDecryptedAmount`

## 9.0.0 (2025-10-29)

- Changed `Debug` implementation of secret keys and cleartext values to not print the key or value.
Expand Down
4 changes: 3 additions & 1 deletion rust-src/concordium_base/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@ version = "1.1.0-alpha.3"
path = "../concordium_base_derive"

[features]
default = []
default = ["serde_deprecated"]
# enables `serde` for composite data structures; see `README.md` for more information
serde_deprecated = []
ffi = ["rand_chacha"]
internal-test-helpers = []
encryption = ["cbc", "aes", "base64", "pbkdf2", "hmac"]
Expand Down
8 changes: 7 additions & 1 deletion rust-src/concordium_base/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,13 @@ The library covers the following areas

### Features

The library has no default features and the following optional ones:
The library has `serde_deprecated` as a default feature:

- `serde_deprecated` - Guards `serde::Serialize` and `serde::Deserialize`
implementations for composite data structures where these implementations will
eventually be deprecated. Enable the flag to use them.

Along with optional features:

- `encryption` - additionally exposes the `common::encryption` module for
handling the encryption format used by various Concordium tools (such as
Expand Down
53 changes: 34 additions & 19 deletions rust-src/concordium_base/src/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ impl TryFrom<String> for UrlText {

fn try_from(value: String) -> Result<Self, Self::Error> {
anyhow::ensure!(
value.as_bytes().len() <= crate::constants::MAX_URL_TEXT_LENGTH,
value.len() <= crate::constants::MAX_URL_TEXT_LENGTH,
"URL length exceeds maximum allowed."
);
Ok(Self { url: value })
Expand Down Expand Up @@ -249,17 +249,21 @@ impl Deserial for OpenStatus {
}
}

#[derive(SerdeSerialize, SerdeDeserialize, PartialEq, Eq, Debug, Clone)]
#[serde(rename_all = "camelCase", tag = "delegateType")]
#[derive(PartialEq, Eq, Debug, Clone)]
#[cfg_attr(feature = "serde_deprecated", derive(SerdeSerialize, SerdeDeserialize))]
#[cfg_attr(
feature = "serde_deprecated",
serde(rename_all = "camelCase", tag = "delegateType")
)]
/// Target of delegation.
pub enum DelegationTarget {
#[serde(rename = "Passive")]
#[cfg_attr(feature = "serde_deprecated", serde(rename = "Passive"))]
/// Delegate passively, i.e., to no specific baker.
Passive,
#[serde(rename = "Baker")]
#[cfg_attr(feature = "serde_deprecated", serde(rename = "Baker"))]
/// Delegate to a specific baker.
Baker {
#[serde(rename = "bakerId")]
#[cfg_attr(feature = "serde_deprecated", serde(rename = "bakerId"))]
baker_id: BakerId,
},
}
Expand Down Expand Up @@ -1060,34 +1064,43 @@ impl fmt::Display for PartsPerHundredThousands {
}
}

#[derive(SerdeSerialize, SerdeDeserialize, PartialEq, Eq, Serialize, Debug, Clone, Copy)]
#[derive(PartialEq, Eq, Serialize, Debug, Clone, Copy)]
#[cfg_attr(feature = "serde_deprecated", derive(SerdeSerialize, SerdeDeserialize))]
pub struct CommissionRates {
/// Fraction of finalization rewards charged by the pool owner.
#[serde(rename = "finalizationCommission")]
#[cfg_attr(feature = "serde_deprecated", serde(rename = "finalizationCommission"))]
pub finalization: AmountFraction,
/// Fraction of baking rewards charged by the pool owner.
#[serde(rename = "bakingCommission")]
#[cfg_attr(feature = "serde_deprecated", serde(rename = "bakingCommission"))]
pub baking: AmountFraction,
/// Fraction of transaction rewards charged by the pool owner.
#[serde(rename = "transactionCommission")]
#[cfg_attr(feature = "serde_deprecated", serde(rename = "transactionCommission"))]
pub transaction: AmountFraction,
}

#[derive(Serialize, SerdeSerialize, SerdeDeserialize, Debug, Clone)]
#[derive(Serialize, Debug, Clone)]
#[cfg_attr(feature = "serde_deprecated", derive(SerdeSerialize, SerdeDeserialize))]
/// Ranges of allowed commission values that pools may choose from.
pub struct CommissionRanges {
/// The range of allowed finalization commissions.
#[serde(rename = "finalizationCommissionRange")]
#[cfg_attr(
feature = "serde_deprecated",
serde(rename = "finalizationCommissionRange")
)]
pub finalization: InclusiveRange<AmountFraction>,
/// The range of allowed baker commissions.
#[serde(rename = "bakingCommissionRange")]
#[cfg_attr(feature = "serde_deprecated", serde(rename = "bakingCommissionRange"))]
pub baking: InclusiveRange<AmountFraction>,
/// The range of allowed transaction commissions.
#[serde(rename = "transactionCommissionRange")]
#[cfg_attr(
feature = "serde_deprecated",
serde(rename = "transactionCommissionRange")
)]
pub transaction: InclusiveRange<AmountFraction>,
}

#[derive(Debug, Copy, Clone, SerdeSerialize, SerdeDeserialize, Eq, PartialEq)]
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
#[cfg_attr(feature = "serde_deprecated", derive(SerdeSerialize, SerdeDeserialize))]
pub struct InclusiveRange<T> {
pub min: T,
pub max: T,
Expand Down Expand Up @@ -1181,8 +1194,9 @@ impl Deserial for LeverageFactor {
}
}

#[derive(SerdeSerialize, SerdeDeserialize, Serial, Debug, Clone)]
#[serde(rename_all = "camelCase")]
#[derive(Serial, Debug, Clone)]
#[cfg_attr(feature = "serde_deprecated", derive(SerdeSerialize, SerdeDeserialize))]
#[cfg_attr(feature = "serde_deprecated", serde(rename_all = "camelCase"))]
/// Mint distribution that applies to protocol versions 1-3.
pub struct MintDistributionV0 {
/// The increase in CCD amount per slot.
Expand All @@ -1193,8 +1207,9 @@ pub struct MintDistributionV0 {
pub finalization_reward: AmountFraction,
}

#[derive(SerdeSerialize, SerdeDeserialize, Serial, Debug, Clone)]
#[serde(rename_all = "camelCase")]
#[derive(Serial, Debug, Clone)]
#[cfg_attr(feature = "serde_deprecated", derive(SerdeSerialize, SerdeDeserialize))]
#[cfg_attr(feature = "serde_deprecated", serde(rename_all = "camelCase"))]
/// Mint distribution parameters that apply to protocol version 4 and up.
pub struct MintDistributionV1 {
/// Fraction of newly minted CCD allocated to baker rewards.
Expand Down
5 changes: 1 addition & 4 deletions rust-src/concordium_base/src/bulletproofs/range_proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -426,10 +426,7 @@ pub fn prove<C: Curve, T: Rng>(
// compute scalars such that c*H = H', that is H_prime_scalars = (1, y^-1,
// \dots, y^-(nm-1))
let mut H_prime_scalars: Vec<C::Scalar> = Vec::with_capacity(nm);
let y_inv = match y.inverse() {
Some(inv) => inv,
None => return None,
};
let y_inv = y.inverse()?;
let mut y_inv_i = C::Scalar::one();
for _i in 0..nm {
// H_prime.push(H[i].mul_by_scalar(&y_inv_i));
Expand Down
2 changes: 1 addition & 1 deletion rust-src/concordium_base/src/common/cbor/primitives.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ impl TryFrom<MapKey> for u64 {
}

impl MapKey {
pub fn as_ref(&self) -> MapKeyRef {
pub fn as_ref(&self) -> MapKeyRef<'_> {
match self {
MapKey::Positive(positive) => MapKeyRef::Positive(*positive),
MapKey::Text(text) => MapKeyRef::Text(text),
Expand Down
2 changes: 2 additions & 0 deletions rust-src/concordium_base/src/common/cbor/serde.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ pub mod map_hex_cbor_values {
use crate::common::cbor::{cbor_decode, cbor_encode, value};

/// Serialize a `HashMap<String, value::Value>` as hex-encoded CBOR.
#[allow(dead_code)]
pub fn serialize<S>(
map: &HashMap<String, value::Value>,
serializer: S,
Expand All @@ -26,6 +27,7 @@ pub mod map_hex_cbor_values {
}

/// Deserialize a `HashMap<String, value::Value>` from hex-encoded CBOR.
#[allow(dead_code)]
pub fn deserialize<'de, D>(deserializer: D) -> Result<HashMap<String, value::Value>, D::Error>
where
D: Deserializer<'de>,
Expand Down
13 changes: 7 additions & 6 deletions rust-src/concordium_base/src/common/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -384,8 +384,9 @@ impl AsRef<[u8]> for Signature {
}

/// Transaction signature structure, to match the one on the Haskell side.
#[derive(SerdeDeserialize, SerdeSerialize, Clone, PartialEq, Eq, Debug, derive_more::AsRef)]
#[serde(transparent)]
#[derive(Clone, PartialEq, Eq, Debug, derive_more::AsRef)]
#[cfg_attr(feature = "serde_deprecated", derive(SerdeDeserialize, SerdeSerialize))]
#[cfg_attr(feature = "serde_deprecated", serde(transparent))]
pub struct TransactionSignature {
pub signatures: BTreeMap<CredentialIndex, BTreeMap<KeyIndex, Signature>>,
}
Expand Down Expand Up @@ -563,11 +564,11 @@ impl KeyPair {
#[cfg(test)]
mod tests {
use super::*;
use rand::{
distributions::{Distribution, Uniform},
Rng,
};
#[cfg(feature = "serde_deprecated")]
use rand::distributions::{Distribution, Uniform};
use rand::Rng;

#[cfg(feature = "serde_deprecated")]
#[test]
fn transaction_signature_serialization() {
let mut rng = rand::thread_rng();
Expand Down
2 changes: 1 addition & 1 deletion rust-src/concordium_base/src/elgamal/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub(crate) enum InternalError {
/// * A problem decoding to a scalar,
///
/// * A problem decoding to a group element

#[allow(dead_code)]
#[derive(Error, Debug)]
#[error("{0}")]
pub struct ElgamalError(pub(crate) InternalError);
1 change: 0 additions & 1 deletion rust-src/concordium_base/src/encrypted_transfers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,6 @@ pub fn make_sec_to_pub_transfer_data<C: Curve, R: Rng>(
///
/// The return value is going to be `true` if verification succeeds and `false`
/// if not.

pub fn verify_sec_to_pub_transfer_data<C: Curve>(
ctx: &GlobalContext<C>,
pk: &PublicKey<C>,
Expand Down
42 changes: 29 additions & 13 deletions rust-src/concordium_base/src/encrypted_transfers/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,13 @@ pub struct EncryptedAmountRandomness<C: Curve> {
}

/// An encrypted amount that we know the index of.
#[derive(Serialize, SerdeSerialize, SerdeDeserialize)]
#[serde(bound(serialize = "C: Curve", deserialize = "C: Curve"))]
#[serde(rename_all = "camelCase")]
#[derive(Serialize)]
#[cfg_attr(feature = "serde_deprecated", derive(SerdeSerialize, SerdeDeserialize))]
#[cfg_attr(
feature = "serde_deprecated",
serde(bound(serialize = "C: Curve", deserialize = "C: Curve"))
)]
#[cfg_attr(feature = "serde_deprecated", serde(rename_all = "camelCase"))]
pub struct IndexedEncryptedAmount<C: Curve> {
/// The actual encrypted amount.
pub encrypted_chunks: EncryptedAmount<C>,
Expand All @@ -79,9 +83,13 @@ pub struct IndexedEncryptedAmount<C: Curve> {
pub const CHUNK_SIZE: ChunkSize = ChunkSize::ThirtyTwo;

/// Data that will go onto an encrypted amount transfer.
#[derive(Serialize, SerdeSerialize, SerdeDeserialize, Clone, Debug)]
#[serde(bound(serialize = "C: Curve", deserialize = "C: Curve"))]
#[serde(rename_all = "camelCase")]
#[derive(Serialize, Clone, Debug)]
#[cfg_attr(feature = "serde_deprecated", derive(SerdeSerialize, SerdeDeserialize))]
#[cfg_attr(
feature = "serde_deprecated",
serde(bound(serialize = "C: Curve", deserialize = "C: Curve"))
)]
#[cfg_attr(feature = "serde_deprecated", serde(rename_all = "camelCase"))]
pub struct EncryptedAmountTransferData<C: Curve> {
/// Encryption of the remaining amount.
pub remaining_amount: EncryptedAmount<C>,
Expand All @@ -97,9 +105,13 @@ pub struct EncryptedAmountTransferData<C: Curve> {
}

/// Data that will go onto a secret to public amount transfer.
#[derive(Serialize, SerdeSerialize, SerdeDeserialize, Debug, Clone)]
#[serde(bound(serialize = "C: Curve", deserialize = "C: Curve"))]
#[serde(rename_all = "camelCase")]
#[derive(Serialize, Debug, Clone)]
#[cfg_attr(feature = "serde_deprecated", derive(SerdeSerialize, SerdeDeserialize))]
#[cfg_attr(
feature = "serde_deprecated",
serde(bound(serialize = "C: Curve", deserialize = "C: Curve"))
)]
#[cfg_attr(feature = "serde_deprecated", serde(rename_all = "camelCase"))]
pub struct SecToPubAmountTransferData<C: Curve> {
/// Encryption of the remaining amount.
pub remaining_amount: EncryptedAmount<C>,
Expand All @@ -117,17 +129,21 @@ pub struct SecToPubAmountTransferData<C: Curve> {
/// An aggregated encrypted amount with a decrypted plaintext, collecting
/// encrypted amounts with decryption. The only real difference from the above
/// is the meaning of the index field.
#[derive(Serialize, SerdeSerialize, SerdeDeserialize)]
#[serde(bound(serialize = "C: Curve", deserialize = "C: Curve"))]
#[serde(rename_all = "camelCase")]
#[derive(Serialize)]
#[cfg_attr(feature = "serde_deprecated", derive(SerdeSerialize, SerdeDeserialize))]
#[cfg_attr(
feature = "serde_deprecated",
serde(bound(serialize = "C: Curve", deserialize = "C: Curve"))
)]
#[cfg_attr(feature = "serde_deprecated", serde(rename_all = "camelCase"))]
pub struct AggregatedDecryptedAmount<C: Curve> {
/// The aggregated encrypted amount.
pub agg_encrypted_amount: EncryptedAmount<C>,
/// The plaintext corresponding to the aggregated encrypted amount.
pub agg_amount: Amount,
/// Index such that the `agg_amount` is the sum of all encrypted amounts
/// on an account with indices strictly below `agg_index`.
#[serde(default)]
#[cfg_attr(feature = "serde_deprecated", serde(default))]
pub agg_index: EncryptedAmountAggIndex,
}

Expand Down
2 changes: 1 addition & 1 deletion rust-src/concordium_base/src/id/account_holder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ pub fn build_pub_info_for_ip<C: Curve>(
///
/// The `generate_pio_common` function also produces the bulletproofs rangeproof
/// used in both flows. The version 0 flow is kept for backwards compatibility.

///
/// Generate a version 0 PreIdentityObject out of the account holder
/// information, the chosen anonymity revoker information, and the necessary
/// contextual information (group generators, shared commitment keys, etc).
Expand Down
Loading