Skip to content

Commit 8fc1672

Browse files
committed
Move constants into core package
1 parent 38ba7f5 commit 8fc1672

24 files changed

+152
-90
lines changed

.circleci/config.yml

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ workflows:
6363
# Keep those job names in sync with .mergify.yml
6464
jobs:
6565
- arm64
66+
- package_core
6667
- package_crypto
6768
- package_check
6869
- package_schema
@@ -173,6 +174,10 @@ jobs:
173174
name: "contracts/staking: integration-test"
174175
working_directory: ~/project/contracts/staking
175176
command: cargo wasm --locked && cargo integration-test --locked
177+
- run:
178+
name: "packages/core: test"
179+
working_directory: ~/project/packages/core
180+
command: cargo test --all-features --locked
176181
- run:
177182
name: "packages/crypto: test"
178183
working_directory: ~/project/packages/crypto
@@ -233,6 +238,62 @@ jobs:
233238
- contracts/staking/target/wasm32-unknown-unknown/release/build
234239
- contracts/staking/target/wasm32-unknown-unknown/release/deps
235240

241+
package_core:
242+
docker:
243+
- image: rust:1.74
244+
environment:
245+
# Limit the number of parallel jobs to avoid OOM crashes during doc testing
246+
RUST_TEST_THREADS: 8
247+
steps:
248+
- checkout
249+
- run:
250+
name: Version information
251+
command: rustc --version; cargo --version; rustup --version; rustup target list --installed
252+
- restore_cache:
253+
keys:
254+
- cargocache-v2-package_core-rust:1.74-{{ checksum "Cargo.lock" }}
255+
- run:
256+
name: Add thumbv7em-none-eabi target
257+
command: rustup target add thumbv7em-none-eabi && rustup target list --installed
258+
- run:
259+
name: Add wasm32 target
260+
command: rustup target add wasm32-unknown-unknown && rustup target list --installed
261+
- run:
262+
name: Build library for native target (no features)
263+
working_directory: ~/project/packages/core
264+
command: cargo build --locked --no-default-features
265+
- run:
266+
name: Build library for wasm target (no features)
267+
working_directory: ~/project/packages/core
268+
command: cargo wasm --locked --no-default-features
269+
- run:
270+
name: Build library for no_std target (no features)
271+
working_directory: ~/project/packages/core
272+
command: cargo no-std --locked --no-default-features
273+
- run:
274+
name: Run unit tests (no features)
275+
working_directory: ~/project/packages/core
276+
command: cargo test --locked --no-default-features
277+
- run:
278+
name: Build library for native target (all features)
279+
working_directory: ~/project/packages/core
280+
command: cargo build --locked --features std
281+
- run:
282+
name: Build library for wasm target (all features)
283+
working_directory: ~/project/packages/core
284+
command: cargo wasm --locked --features std
285+
- run:
286+
name: Run unit tests (all features)
287+
working_directory: ~/project/packages/core
288+
command: cargo test --locked --features std
289+
- save_cache:
290+
paths:
291+
- /usr/local/cargo/registry
292+
- target/debug/.fingerprint
293+
- target/debug/build
294+
- target/debug/deps
295+
key: cargocache-v2-package_core-rust:1.74-{{ checksum "Cargo.lock" }}
296+
236297
package_crypto:
237298
docker:
238299
- image: rust:1.74
@@ -941,6 +1002,14 @@ jobs:
9411002
#
9421003
# Workspace packages
9431004
#
1005+
- run:
1006+
name: Clippy linting on core (no feature flags)
1007+
working_directory: ~/project/packages/core
1008+
command: cargo clippy --all-targets -- -D warnings
1009+
- run:
1010+
name: Clippy linting on core (all feature flags)
1011+
working_directory: ~/project/packages/core
1012+
command: cargo clippy --all-features --all-targets -- -D warnings
9441013
- run:
9451014
name: Clippy linting on crypto
9461015
working_directory: ~/project/packages/crypto
@@ -1039,6 +1108,7 @@ jobs:
10391108
mkdir -p reports
10401109
cargo test --all-features
10411110
1111+
grcov . -s packages/core --binary-path ./target/debug -t lcov -o ./reports/core.info
10421112
grcov . -s packages/crypto --binary-path ./target/debug -t lcov -o ./reports/crypto.info
10431113
grcov . -s packages/derive --binary-path ./target/debug -t lcov -o ./reports/derive.info
10441114
grcov . -s packages/schema --binary-path ./target/debug -t lcov -o ./reports/schema.info
@@ -1050,6 +1120,9 @@ jobs:
10501120
- run:
10511121
name: Quick fix for GPG error in Codecov
10521122
command: mkdir -p ~/.gnupg
1123+
- codecov/upload:
1124+
file: reports/core.info
1125+
flags: cosmwasm-core
10531126
- codecov/upload:
10541127
file: reports/crypto.info
10551128
flags: cosmwasm-crypto

Cargo.lock

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/core/Cargo.toml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,4 @@ repository = "https://github.com/CosmWasm/cosmwasm/tree/main/packages/core"
77
license = "Apache-2.0"
88
readme = "README.md"
99

10-
[package.metadata.release]
11-
release = false
12-
1310
[dependencies]
14-
15-
[features]
16-
17-
[dev-dependencies]

packages/core/src/crypto.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
pub const BLS12_381_G1_POINT_LEN: usize = 48;
2+
pub const BLS12_381_G2_POINT_LEN: usize = 96;
3+
4+
/// A generator in G1 (in compressed serialization).
5+
///
6+
/// This can be used directly for signature verification
7+
/// (see e.g. https://twitter.com/simon_warta/status/1786342207106019765)
8+
pub const BLS12_381_G1_GENERATOR: [u8; BLS12_381_G1_POINT_LEN] = [
9+
151, 241, 211, 167, 49, 151, 215, 148, 38, 149, 99, 140, 79, 169, 172, 15, 195, 104, 140, 79,
10+
151, 116, 185, 5, 161, 78, 58, 63, 23, 27, 172, 88, 108, 85, 232, 63, 249, 122, 26, 239, 251,
11+
58, 240, 10, 219, 34, 198, 187,
12+
];
13+
14+
/// A generator in G2 (in compressed serialization).
15+
///
16+
/// This can be used directly for signature verification
17+
/// (see e.g. https://twitter.com/simon_warta/status/1786342207106019765)
18+
pub const BLS12_381_G2_GENERATOR: [u8; BLS12_381_G2_POINT_LEN] = [
19+
147, 224, 43, 96, 82, 113, 159, 96, 125, 172, 211, 160, 136, 39, 79, 101, 89, 107, 208, 208,
20+
153, 32, 182, 26, 181, 218, 97, 187, 220, 127, 80, 73, 51, 76, 241, 18, 19, 148, 93, 87, 229,
21+
172, 125, 5, 93, 4, 43, 126, 2, 74, 162, 178, 240, 143, 10, 145, 38, 8, 5, 39, 45, 197, 16, 81,
22+
198, 228, 122, 212, 250, 64, 59, 2, 180, 81, 11, 100, 122, 227, 209, 119, 11, 172, 3, 38, 168,
23+
5, 187, 239, 212, 128, 86, 200, 193, 33, 189, 184,
24+
];

packages/core/src/lib.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,8 @@
1+
#![no_std]
12

3+
mod crypto;
4+
5+
#[doc(hidden)]
6+
pub use self::crypto::{
7+
BLS12_381_G1_GENERATOR, BLS12_381_G1_POINT_LEN, BLS12_381_G2_GENERATOR, BLS12_381_G2_POINT_LEN,
8+
};

packages/crypto/Cargo.toml

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,21 @@ license = "Apache-2.0"
1212
bench = false
1313

1414
[dependencies]
15-
cfg-if = "1.0.0"
15+
ark-bls12-381 = "0.4.0"
16+
ark-ec = { version = "0.4.2", features = ["parallel"] }
17+
ark-ff = { version = "0.4.2", features = ["asm", "parallel"] }
18+
ark-serialize = "0.4.2"
19+
cosmwasm-core = { version = "2.0.1", path = "../core" }
1620
digest = "0.10"
1721
ecdsa = "0.16.2" # Not used directly, but needed to bump transitive dependency, see: https://github.com/CosmWasm/cosmwasm/pull/1899 for details.
1822
ed25519-zebra = { version = "4.0.3", default-features = false }
1923
k256 = { version = "0.13.3", default-features = false, features = ["ecdsa"] }
24+
num-traits = "0.2.18"
2025
p256 = { version = "0.13.2", default-features = false, features = ["ecdsa"] }
2126
rand_core = "0.6"
22-
thiserror = "1.0.26"
23-
24-
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
25-
ark-bls12-381 = "0.4.0"
26-
ark-ec = { version = "0.4.2", features = ["parallel"] }
27-
ark-ff = { version = "0.4.2", features = ["asm", "parallel"] }
28-
ark-serialize = "0.4.2"
29-
num-traits = "0.2.18"
3027
rayon = "1.9.0"
3128
sha2 = "0.10"
29+
thiserror = "1.0.26"
3230

3331
[dev-dependencies]
3432
base64 = "0.22.0"
@@ -44,6 +42,10 @@ hex-literal = "0.4.1"
4442
english-numbers = "0.3"
4543
glob = "0.3.1"
4644

45+
[features]
46+
default = ["std"]
47+
std = []
48+
4749
[[bench]]
4850
name = "main"
4951
harness = false

packages/crypto/benches/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ use digest::Digest;
1515
use k256::ecdsa::SigningKey; // type alias
1616
use sha2::Sha256;
1717

18+
use cosmwasm_core::{BLS12_381_G1_GENERATOR, BLS12_381_G1_POINT_LEN, BLS12_381_G2_POINT_LEN};
1819
use cosmwasm_crypto::{
1920
bls12_381_aggregate_g1, bls12_381_aggregate_g2, bls12_381_hash_to_g1, bls12_381_hash_to_g2,
2021
bls12_381_pairing_equality, ed25519_batch_verify, ed25519_verify, secp256k1_recover_pubkey,
2122
secp256k1_verify, secp256r1_recover_pubkey, secp256r1_verify, HashFunction,
22-
BLS12_381_G1_GENERATOR, BLS12_381_G1_POINT_LEN, BLS12_381_G2_POINT_LEN,
2323
};
2424
use std::cmp::min;
2525

packages/crypto/src/bls12_318/constants.rs

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,11 @@
1-
pub const BLS12_381_G1_POINT_LEN: usize = 48;
2-
pub const BLS12_381_G2_POINT_LEN: usize = 96;
3-
4-
/// A generator in G1 (in compressed serialization).
5-
///
6-
/// This can be used directly for signature verification
7-
/// (see e.g. https://twitter.com/simon_warta/status/1786342207106019765)
8-
pub const BLS12_381_G1_GENERATOR: [u8; BLS12_381_G1_POINT_LEN] = [
9-
151, 241, 211, 167, 49, 151, 215, 148, 38, 149, 99, 140, 79, 169, 172, 15, 195, 104, 140, 79,
10-
151, 116, 185, 5, 161, 78, 58, 63, 23, 27, 172, 88, 108, 85, 232, 63, 249, 122, 26, 239, 251,
11-
58, 240, 10, 219, 34, 198, 187,
12-
];
13-
14-
/// A generator in G2 (in compressed serialization).
15-
///
16-
/// This can be used directly for signature verification
17-
/// (see e.g. https://twitter.com/simon_warta/status/1786342207106019765)
18-
pub const BLS12_381_G2_GENERATOR: [u8; BLS12_381_G2_POINT_LEN] = [
19-
147, 224, 43, 96, 82, 113, 159, 96, 125, 172, 211, 160, 136, 39, 79, 101, 89, 107, 208, 208,
20-
153, 32, 182, 26, 181, 218, 97, 187, 220, 127, 80, 73, 51, 76, 241, 18, 19, 148, 93, 87, 229,
21-
172, 125, 5, 93, 4, 43, 126, 2, 74, 162, 178, 240, 143, 10, 145, 38, 8, 5, 39, 45, 197, 16, 81,
22-
198, 228, 122, 212, 250, 64, 59, 2, 180, 81, 11, 100, 122, 227, 209, 119, 11, 172, 3, 38, 168,
23-
5, 187, 239, 212, 128, 86, 200, 193, 33, 189, 184,
24-
];
25-
26-
#[cfg(all(test, feature = "std"))]
1+
#[cfg(test)]
272
mod test {
283
use ark_bls12_381::{G1Affine, G2Affine};
294
use ark_ec::AffineRepr;
305
use ark_serialize::CanonicalSerialize;
316
use hex_literal::hex;
327

33-
use super::{
8+
use cosmwasm_core::{
349
BLS12_381_G1_GENERATOR, BLS12_381_G1_POINT_LEN, BLS12_381_G2_GENERATOR,
3510
BLS12_381_G2_POINT_LEN,
3611
};

packages/crypto/src/bls12_318/hash.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,10 @@ use ark_ec::{
2727
};
2828
use ark_ff::field_hashers::DefaultFieldHasher;
2929
use ark_serialize::CanonicalSerialize;
30+
use cosmwasm_core::{BLS12_381_G1_POINT_LEN, BLS12_381_G2_POINT_LEN};
3031
use sha2::Sha256;
3132

32-
use crate::{CryptoError, BLS12_381_G1_POINT_LEN, BLS12_381_G2_POINT_LEN};
33+
use crate::CryptoError;
3334

3435
type HashToCurve<CurveConfig, Hash> =
3536
MapToCurveBasedHasher<Projective<CurveConfig>, DefaultFieldHasher<Hash>, WBMap<CurveConfig>>;

packages/crypto/src/bls12_318/mod.rs

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,10 @@
1+
mod aggregate;
12
mod constants;
3+
mod hash;
4+
mod pairing;
5+
mod points;
26

3-
pub use self::constants::{
4-
BLS12_381_G1_GENERATOR, BLS12_381_G1_POINT_LEN, BLS12_381_G2_GENERATOR, BLS12_381_G2_POINT_LEN,
5-
};
6-
7-
cfg_if::cfg_if! {
8-
if #[cfg(not(target_arch = "wasm32"))] {
9-
mod aggregate;
10-
mod hash;
11-
mod pairing;
12-
mod points;
13-
14-
pub use self::aggregate::{bls12_381_aggregate_g1, bls12_381_aggregate_g2};
15-
pub use self::hash::{bls12_381_hash_to_g1, bls12_381_hash_to_g2, HashFunction};
16-
pub use self::pairing::bls12_381_pairing_equality;
17-
pub use self::points::{bls12_381_g1_is_identity, bls12_381_g2_is_identity};
18-
}
19-
}
7+
pub use self::aggregate::{bls12_381_aggregate_g1, bls12_381_aggregate_g2};
8+
pub use self::hash::{bls12_381_hash_to_g1, bls12_381_hash_to_g2, HashFunction};
9+
pub use self::pairing::bls12_381_pairing_equality;
10+
pub use self::points::{bls12_381_g1_is_identity, bls12_381_g2_is_identity};

packages/crypto/src/bls12_318/pairing.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
use core::ops::Neg;
22

3-
use crate::{errors::PairingEquality, CryptoError, BLS12_381_G1_POINT_LEN, BLS12_381_G2_POINT_LEN};
4-
53
use super::points::{g1_from_variable, g2_from_variable};
4+
use crate::{errors::PairingEquality, CryptoError};
5+
66
use ark_bls12_381::Bls12_381;
77
use ark_ec::{
88
bls12::{G1Prepared, G2Prepared},
99
pairing::Pairing,
1010
};
11+
use cosmwasm_core::{BLS12_381_G1_POINT_LEN, BLS12_381_G2_POINT_LEN};
1112
use num_traits::Zero;
1213
use rayon::{
1314
iter::{IndexedParallelIterator, ParallelIterator},

packages/crypto/src/bls12_318/points.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ use core::{fmt, ops::Neg};
77

88
use ark_bls12_381::{G1Affine, G1Projective, G2Affine, G2Projective};
99
use ark_ec::AffineRepr;
10+
use cosmwasm_core::{BLS12_381_G1_POINT_LEN, BLS12_381_G2_POINT_LEN};
1011
use num_traits::Zero;
1112

12-
use crate::errors::InvalidPoint;
13-
use crate::{CryptoError, BLS12_381_G1_POINT_LEN, BLS12_381_G2_POINT_LEN};
13+
use crate::{errors::InvalidPoint, CryptoError};
1414

1515
/// Point on G1
1616
#[derive(Debug, PartialEq, Clone)]
@@ -195,9 +195,9 @@ pub fn bls12_381_g2_is_identity(g2: &[u8; BLS12_381_G2_POINT_LEN]) -> Result<boo
195195

196196
#[cfg(test)]
197197
mod tests {
198-
use crate::{BLS12_381_G1_GENERATOR, BLS12_381_G2_GENERATOR};
199-
200198
use super::*;
199+
200+
use cosmwasm_core::{BLS12_381_G1_GENERATOR, BLS12_381_G2_GENERATOR};
201201
use hex_literal::hex;
202202

203203
#[test]

packages/crypto/src/ed25519.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,17 +48,15 @@ pub fn ed25519_verify(message: &[u8], signature: &[u8], public_key: &[u8]) -> Cr
4848
/// Three Variants are suppported in the input for convenience:
4949
/// - Equal number of messages, signatures, and public keys: Standard, generic functionality.
5050
/// - One message, and an equal number of signatures and public keys: Multiple digital signature
51-
/// (multisig) verification of a single message.
51+
/// (multisig) verification of a single message.
5252
/// - One public key, and an equal number of messages and signatures: Verification of multiple
53-
/// messages, all signed with the same private key.
53+
/// messages, all signed with the same private key.
5454
///
5555
/// Any other variants of input vectors result in an error.
5656
///
5757
/// Notes:
58-
/// - The "one-message, with zero signatures and zero public keys" case, is considered the empty
59-
/// case.
60-
/// - The "one-public key, with zero messages and zero signatures" case, is considered the empty
61-
/// case.
58+
/// - The "one-message, with zero signatures and zero public keys" case, is considered the empty case.
59+
/// - The "one-public key, with zero messages and zero signatures" case, is considered the empty case.
6260
/// - The empty case (no messages, no signatures and no public keys) returns true.
6361
pub fn ed25519_batch_verify<R>(
6462
rng: &mut R,

packages/crypto/src/lib.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,11 @@ mod secp256k1;
1515
mod secp256r1;
1616

1717
#[doc(hidden)]
18-
#[cfg(not(target_arch = "wasm32"))]
1918
pub use crate::bls12_318::{
2019
bls12_381_aggregate_g1, bls12_381_aggregate_g2, bls12_381_g1_is_identity,
2120
bls12_381_g2_is_identity, bls12_381_hash_to_g1, bls12_381_hash_to_g2,
2221
bls12_381_pairing_equality, HashFunction,
2322
};
24-
25-
#[doc(hidden)]
26-
pub use crate::bls12_318::{
27-
BLS12_381_G1_GENERATOR, BLS12_381_G1_POINT_LEN, BLS12_381_G2_GENERATOR, BLS12_381_G2_POINT_LEN,
28-
};
2923
#[doc(hidden)]
3024
pub use crate::ecdsa::{ECDSA_PUBKEY_MAX_LEN, ECDSA_SIGNATURE_LEN, MESSAGE_HASH_MAX_LEN};
3125
#[doc(hidden)]

0 commit comments

Comments
 (0)