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
27 changes: 1 addition & 26 deletions soroban-sdk/src/bytes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,14 +105,8 @@ macro_rules! bytesn {
/// Internal macro that generates all `BytesN` wrapper methods and trait impls
/// *except* `from_bytes`. Types using this macro must provide their own
/// `from_bytes(BytesN<$size>) -> Self` (e.g. to add validation).
///
/// This macro exists for backward compatibility: `impl_bytesn_repr` was
/// accidentally exported via `#[macro_export]` and cannot be changed until the
/// next protocol boundary. Once we remove the `#[macro_export]` from
/// `impl_bytesn_repr`, this macro should be consolidated back into it.
#[doc(hidden)]
#[macro_export]
macro_rules! impl_bytesn_repr_without_from_bytes {
macro_rules! impl_bytesn_repr {
($elem: ident, $size: expr) => {
impl $elem {
pub fn into_bytes(self) -> BytesN<$size> {
Expand Down Expand Up @@ -231,25 +225,6 @@ macro_rules! impl_bytesn_repr_without_from_bytes {
};
}

/// Generates all `BytesN` wrapper methods and trait impls including a default
/// `from_bytes` that wraps the bytes without validation.
///
/// NOTE: This macro was not intended to be exported. Remove the
/// `#[macro_export]` at the next protocol boundary, and consolidate
/// `impl_bytesn_repr_without_from_bytes` back into this macro.
#[macro_export]
macro_rules! impl_bytesn_repr {
($elem: ident, $size: expr) => {
impl $elem {
pub fn from_bytes(bytes: BytesN<$size>) -> Self {
Self(bytes)
}
}

impl_bytesn_repr_without_from_bytes!($elem, $size);
};
}

/// Bytes is a contiguous growable array type containing `u8`s.
///
/// The array is stored in the Host and available to the Guest through the
Expand Down
10 changes: 4 additions & 6 deletions soroban-sdk/src/crypto/bls12_381.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use crate::xdr::ScVal;
use crate::{
crypto::utils::BigInt,
env::internal::{self, BytesObject, U256Val, U64Val},
impl_bytesn_repr_without_from_bytes,
unwrap::{UnwrapInfallible, UnwrapOptimized},
Bytes, BytesN, ConversionError, Env, IntoVal, TryFromVal, Val, Vec, U256,
};
Expand Down Expand Up @@ -116,10 +115,10 @@ pub type Fp2 = Bls12381Fp2;
#[repr(transparent)]
pub struct Fr(U256);

impl_bytesn_repr_without_from_bytes!(Bls12381G1Affine, G1_SERIALIZED_SIZE);
impl_bytesn_repr_without_from_bytes!(Bls12381G2Affine, G2_SERIALIZED_SIZE);
impl_bytesn_repr_without_from_bytes!(Bls12381Fp, FP_SERIALIZED_SIZE);
impl_bytesn_repr_without_from_bytes!(Bls12381Fp2, FP2_SERIALIZED_SIZE);
impl_bytesn_repr!(Bls12381G1Affine, G1_SERIALIZED_SIZE);
impl_bytesn_repr!(Bls12381G2Affine, G2_SERIALIZED_SIZE);
impl_bytesn_repr!(Bls12381Fp, FP_SERIALIZED_SIZE);
impl_bytesn_repr!(Bls12381Fp2, FP2_SERIALIZED_SIZE);

// BLS12-381 base field modulus p in big-endian bytes.
// p = 0x1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffaaab
Expand Down Expand Up @@ -808,7 +807,6 @@ impl Bls12_381 {
#[cfg(test)]
mod test {
use super::*;
use crate::bytesn;

#[test]
fn test_g1affine_to_val() {
Expand Down
8 changes: 3 additions & 5 deletions soroban-sdk/src/crypto/bn254.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use crate::xdr::ScVal;
use crate::{
crypto::utils::BigInt,
env::internal::{self, BytesObject, U256Val, U64Val},
impl_bytesn_repr_without_from_bytes,
unwrap::{UnwrapInfallible, UnwrapOptimized},
Bytes, BytesN, ConversionError, Env, IntoVal, TryFromVal, Val, Vec, U256,
};
Expand Down Expand Up @@ -74,9 +73,9 @@ pub struct Fr(U256);
#[repr(transparent)]
pub struct Bn254Fp(BytesN<BN254_FP_SERIALIZED_SIZE>);

impl_bytesn_repr_without_from_bytes!(Bn254G1Affine, BN254_G1_SERIALIZED_SIZE);
impl_bytesn_repr_without_from_bytes!(Bn254G2Affine, BN254_G2_SERIALIZED_SIZE);
impl_bytesn_repr_without_from_bytes!(Bn254Fp, BN254_FP_SERIALIZED_SIZE);
impl_bytesn_repr!(Bn254G1Affine, BN254_G1_SERIALIZED_SIZE);
impl_bytesn_repr!(Bn254G2Affine, BN254_G2_SERIALIZED_SIZE);
impl_bytesn_repr!(Bn254Fp, BN254_FP_SERIALIZED_SIZE);

// BN254 base field modulus p in big-endian bytes.
// p = 0x30644e72e131a029b85045b68181585d97816a916871ca8d3c208c16d87cfd47
Expand Down Expand Up @@ -476,7 +475,6 @@ impl Bn254 {
#[cfg(test)]
mod test {
use super::*;
use crate::bytesn;

#[test]
fn test_g1affine_to_val() {
Expand Down
1 change: 1 addition & 0 deletions soroban-sdk/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1190,6 +1190,7 @@ pub mod data {
pub use super::storage::Storage as Data;
}
pub mod auth;
#[macro_use]
mod bytes;
pub mod crypto;
pub mod deploy;
Expand Down
2 changes: 1 addition & 1 deletion soroban-sdk/src/tests/crypto_bls12_381.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{self as soroban_sdk};
use soroban_sdk::{
bytes, bytesn, contract, contractimpl,
contract, contractimpl,
crypto::bls12_381::{Bls12_381, Fp, Fp2, Fr, G1Affine, G2Affine},
vec, Address, Bytes, BytesN, Env, Vec, U256,
};
Expand Down
1 change: 0 additions & 1 deletion soroban-sdk/src/tests/crypto_bn254.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use crate::{self as soroban_sdk};
use soroban_sdk::{
bytes, bytesn,
crypto::bn254::{Bn254, Bn254G1Affine, Fr},
vec, Env, Vec, U256,
};
Expand Down
2 changes: 1 addition & 1 deletion soroban-sdk/src/tests/crypto_ed25519.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{bytes, bytesn, Env};
use crate::Env;

#[test]
fn test_verify_sig_ed25519() {
Expand Down
2 changes: 1 addition & 1 deletion soroban-sdk/src/tests/crypto_keccak256.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{bytesn, BytesN, Env, IntoVal};
use crate::{BytesN, Env, IntoVal};

#[test]
fn test_keccak256() {
Expand Down
2 changes: 1 addition & 1 deletion soroban-sdk/src/tests/crypto_poseidon.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::crypto::CryptoHazmat;
use crate::{bytesn, vec, Env, Symbol, U256};
use crate::{vec, Env, Symbol, U256};

// This test uses dummy MDS matrix and round constants with a minimal number of
// rounds (t=2, rounds_f=2, rounds_p=1) as a sanity check against the
Expand Down
2 changes: 1 addition & 1 deletion soroban-sdk/src/tests/crypto_secp256k1.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{bytesn, crypto::Hash, Env};
use crate::{crypto::Hash, Env};

#[test]
fn test_recover_key_ecdsa_secp256k1() {
Expand Down
2 changes: 1 addition & 1 deletion soroban-sdk/src/tests/crypto_secp256r1.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{bytesn, crypto::Hash, Env};
use crate::{crypto::Hash, Env};

#[test]
fn test_verify_sig_ecdsa_secp256r1() {
Expand Down
2 changes: 1 addition & 1 deletion soroban-sdk/src/tests/crypto_sha256.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{bytes, bytesn, BytesN, Env};
use crate::{BytesN, Env};

#[test]
fn test_sha256() {
Expand Down
2 changes: 1 addition & 1 deletion soroban-sdk/src/tests/prng.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::{self as soroban_sdk, Bytes, BytesN};
use crate::{bytes, vec, Env, Vec};
use crate::{vec, Env, Vec};
use soroban_sdk::contract;

#[contract]
Expand Down
Loading