Skip to content
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
4 changes: 4 additions & 0 deletions .github/workflows/build-test-sources.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -266,5 +266,9 @@ jobs:
- name: Test Rust crates
run: |
cargo test --manifest-path rust-src/Cargo.toml --all --verbose --release
# Verify that the `concordium_base` crate and its tests compile correctly
# with the `serde_deprecated` feature disabled (no default features enabled).
# We do not run the tests here because the full test suite is already executed above.
cargo test --manifest-path rust-src/Cargo.toml -p concordium_base --no-default-features --no-run
cargo test --manifest-path identity-provider-service/Cargo.toml --features=vendored-ssl --all --verbose --release
cargo bench --manifest-path rust-src/Cargo.toml --features concordium_base/internal-test-helpers --no-run
75 changes: 75 additions & 0 deletions rust-src/concordium_base/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,80 @@
## 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::TransactionHeaderV1`
- `common::types::TransactionSignaturesV1`
- `common::types::TransactionSignature`
- `smart_contracts::WasmModule`
- `smart_contracts::InstanceUpdatedEvent`
- `transactions::AccountTransactionV1`
- `transactions::construct::PreAccountTransactionV1`
- `transactions::AccountTransaction`
- `transactions::TransactionHeader`
- `transactions::BakerKeysPayload`
- `transactions::AddBakerPayload`
- `transactions::InitContractPayload`
- `transactions::UpdateContractPayload`
- `transactions::ConfigureBakerPayload`
- `transactions::ConfigureDelegationPayload`
- `transactions::Payload`
- `transactions::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`
- Memory pre allocation is capped to `MAX_PRE_ALLOCATED_SIZE=4096` when cbor decoding vectors and maps.

## 10.0.0 (2026-01-09)
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.2.0"
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 @@ -1066,34 +1070,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 @@ -1187,8 +1200,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 @@ -1199,8 +1213,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 @@ -425,10 +425,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
1 change: 1 addition & 0 deletions rust-src/concordium_base/src/common/cbor/serde.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/// This module provides serialization and deserialization functions for hash
/// maps with string keys and CBOR values, where the values are represented as
/// hex strings of the CBOR encoding.
#[cfg(feature = "serde_deprecated")]
pub mod map_hex_cbor_values {
use std::collections::HashMap;

Expand Down
14 changes: 10 additions & 4 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 @@ -438,7 +439,8 @@ impl Deserial for TransactionSignature {
}

/// Transaction signatures v1 structure, to match the one on the Haskell side.
#[derive(SerdeDeserialize, SerdeSerialize, Clone, PartialEq, Eq, Debug)]
#[derive(Clone, PartialEq, Eq, Debug)]
#[cfg_attr(feature = "serde_deprecated", derive(SerdeSerialize, SerdeDeserialize))]
pub struct TransactionSignaturesV1 {
// The signature of the sender of the transaction.
pub sender: TransactionSignature,
Expand Down Expand Up @@ -603,13 +605,15 @@ impl KeyPair {
#[cfg(test)]
mod tests {
use super::*;
use rand::Rng;
#[cfg(feature = "serde_deprecated")]
use rand::{
distributions::{Distribution, Uniform},
rngs::ThreadRng,
Rng,
};

// Create a random transasction signature given a random generator.
#[cfg(feature = "serde_deprecated")]
fn create_signature(rng: &mut ThreadRng) -> TransactionSignature {
let num_creds = rng.gen_range(1..30);
let mut signatures = BTreeMap::new();
Expand All @@ -631,6 +635,7 @@ mod tests {
TransactionSignature { signatures }
}

#[cfg(feature = "serde_deprecated")]
#[test]
fn transaction_signature_serialization() {
let mut rng = rand::thread_rng();
Expand All @@ -651,6 +656,7 @@ mod tests {
}
}

#[cfg(feature = "serde_deprecated")]
#[test]
fn test_transaction_signature_v1_serialization() {
let mut rng = rand::thread_rng();
Expand Down
31 changes: 0 additions & 31 deletions rust-src/concordium_base/src/elgamal/errors.rs

This file was deleted.

1 change: 0 additions & 1 deletion rust-src/concordium_base/src/elgamal/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
//! Implementation of elgamal public key encryption and decryption over a Curve.

mod cipher;
mod errors;
mod message;
mod public;
mod secret;
Expand Down
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 @@ -279,7 +279,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
Loading