Skip to content

Commit c92519e

Browse files
committed
remove mainnet feature
1 parent 40f220b commit c92519e

File tree

7 files changed

+6
-115
lines changed

7 files changed

+6
-115
lines changed

pallets/drand/Cargo.toml

-3
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,3 @@ try-runtime = [
8888
"frame-system/try-runtime",
8989
"sp-runtime/try-runtime",
9090
]
91-
92-
# use the drand mainnet configuration
93-
mainnet = []

pallets/drand/src/benchmarking.rs

-8
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,9 @@ use crate::Pallet as Drand;
2222
use frame_benchmarking::v2::*;
2323
use frame_system::RawOrigin;
2424

25-
#[cfg(not(feature = "mainnet"))]
2625
pub const DRAND_PULSE: &str = "{\"round\":1000,\"randomness\":\"fe290beca10872ef2fb164d2aa4442de4566183ec51c56ff3cd603d930e54fdd\",\"signature\":\"b44679b9a59af2ec876b1a6b1ad52ea9b1615fc3982b19576350f93447cb1125e342b73a8dd2bacbe47e4b6b63ed5e39\"}";
27-
#[cfg(not(feature = "mainnet"))]
2826
pub const DRAND_INFO_RESPONSE: &str = "{\"public_key\":\"83cf0f2896adee7eb8b5f01fcad3912212c437e0073e911fb90022d3e760183c8c4b450b6a0a6c3ac6a5776a2d1064510d1fec758c921cc22b0e17e63aaf4bcb5ed66304de9cf809bd274ca73bab4af5a6e9c76a4bc09e76eae8991ef5ece45a\",\"period\":3,\"genesis_time\":1692803367,\"hash\":\"52db9ba70e0cc0f6eaf7803dd07447a1f5477735fd3f661792ba94600c84e971\",\"groupHash\":\"f477d5c89f21a17c863a7f937c6a6d15859414d2be09cd448d4279af331c5d3e\",\"schemeID\":\"bls-unchained-g1-rfc9380\",\"metadata\":{\"beaconID\":\"quicknet\"}}";
2927

30-
// mainnet parameters
31-
#[cfg(feature = "mainnet")]
32-
pub const DRAND_PULSE: &str = "{\"round\":1000,\"randomness\":\"a40d3e0e7e3c71f28b7da2fd339f47f0bcf10910309f5253d7c323ec8cea3212\",\"signature\":\"99bf96de133c3d3937293cfca10c8152b18ab2d034ccecf115658db324d2edc00a16a2044cd04a8a38e2a307e5ecff3511315be8d282079faf24098f283e0ed2c199663b334d2e84c55c032fe469b212c5c2087ebb83a5b25155c3283f5b79ac\",\"previous_signature\":\"af0d93299a363735fe847f5ea241442c65843dc1bd3a7b79646b3b10072e908bf034d35cd69d378e3341f139100cd4cd03030399864ef8803a5a4f5e64fccc20bbae36d1ca22a6ddc43d2630c41105e90598fab11e5c7456df3925d4b577b113\"}";
33-
#[cfg(feature = "mainnet")]
34-
pub const DRAND_INFO_RESPONSE: &str = "{\"public_key\":\"868f005eb8e6e4ca0a47c8a77ceaa5309a47978a7c71bc5cce96366b5d7a569937c529eeda66c7293784a9402801af31\",\"period\":30,\"genesis_time\":1595431050,\"hash\":\"8990e7a9aaed2ffed73dbd7092123d6f289930540d7651336225dc172e51b2ce\",\"groupHash\":\"176f93498eac9ca337150b46d21dd58673ea4e3581185f869672e59fa4cb390a\",\"schemeID\":\"pedersen-bls-chained\",\"metadata\":{\"beaconID\":\"default\"}}";
35-
3628
#[benchmarks(
3729
where
3830
T::Public: From<sp_core::sr25519::Public>,

pallets/drand/src/lib.rs

-8
Original file line numberDiff line numberDiff line change
@@ -83,15 +83,7 @@ pub const API_ENDPOINT: &str = "https://drand.cloudflare.com";
8383
/// quicknet uses 'Tiny' BLS381, with small 48-byte sigs in G1 and 96-byte pubkeys in G2
8484
pub const QUICKNET_CHAIN_HASH: &str =
8585
"52db9ba70e0cc0f6eaf7803dd07447a1f5477735fd3f661792ba94600c84e971";
86-
/// the drand mainnet chain hash
87-
/// mainnext uses 'Usual' BLS381, with 96-byte sigs in G2 and 48-byte pubkeys in G1
88-
pub const MAINNET_CHAIN_HASH: &str =
89-
"8990e7a9aaed2ffed73dbd7092123d6f289930540d7651336225dc172e51b2ce";
9086

91-
#[cfg(feature = "mainnet")]
92-
const CHAIN_HASH: &str = MAINNET_CHAIN_HASH;
93-
94-
#[cfg(not(feature = "mainnet"))]
9587
const CHAIN_HASH: &str = QUICKNET_CHAIN_HASH;
9688

9789
pub const MAX_PULSES_TO_FETCH: u64 = 50;

pallets/drand/src/mock.rs

-5
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,7 @@ impl pallet_drand_bridge::Config for Test {
8989
type AuthorityId = crypto::TestAuthId;
9090
type RuntimeEvent = RuntimeEvent;
9191
type WeightInfo = pallet_drand_bridge::weights::SubstrateWeight<Test>;
92-
93-
#[cfg(feature = "mainnet")]
94-
type Verifier = MainnetVerifier;
95-
#[cfg(not(feature = "mainnet"))]
9692
type Verifier = QuicknetVerifier;
97-
9893
type UnsignedPriority = UnsignedPriority;
9994
type HttpFetchTimeout = ConstU64<1_000>;
10095
}

pallets/drand/src/tests.rs

+2-13
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,9 @@ use sp_runtime::{
3636
pub const ROUND_NUMBER: u64 = 1000;
3737

3838
// Quicknet parameters
39-
#[cfg(not(feature = "mainnet"))]
4039
pub const DRAND_PULSE: &str = "{\"round\":1000,\"randomness\":\"fe290beca10872ef2fb164d2aa4442de4566183ec51c56ff3cd603d930e54fdd\",\"signature\":\"b44679b9a59af2ec876b1a6b1ad52ea9b1615fc3982b19576350f93447cb1125e342b73a8dd2bacbe47e4b6b63ed5e39\"}";
41-
#[cfg(not(feature = "mainnet"))]
4240
pub const DRAND_INFO_RESPONSE: &str = "{\"public_key\":\"83cf0f2896adee7eb8b5f01fcad3912212c437e0073e911fb90022d3e760183c8c4b450b6a0a6c3ac6a5776a2d1064510d1fec758c921cc22b0e17e63aaf4bcb5ed66304de9cf809bd274ca73bab4af5a6e9c76a4bc09e76eae8991ef5ece45a\",\"period\":3,\"genesis_time\":1692803367,\"hash\":\"52db9ba70e0cc0f6eaf7803dd07447a1f5477735fd3f661792ba94600c84e971\",\"groupHash\":\"f477d5c89f21a17c863a7f937c6a6d15859414d2be09cd448d4279af331c5d3e\",\"schemeID\":\"bls-unchained-g1-rfc9380\",\"metadata\":{\"beaconID\":\"quicknet\"}}";
4341

44-
// Mainnet parameters
45-
#[cfg(feature = "mainnet")]
46-
pub const DRAND_PULSE: &str = "{\"round\":1000,\"randomness\":\"a40d3e0e7e3c71f28b7da2fd339f47f0bcf10910309f5253d7c323ec8cea3212\",\"signature\":\"99bf96de133c3d3937293cfca10c8152b18ab2d034ccecf115658db324d2edc00a16a2044cd04a8a38e2a307e5ecff3511315be8d282079faf24098f283e0ed2c199663b334d2e84c55c032fe469b212c5c2087ebb83a5b25155c3283f5b79ac\",\"previous_signature\":\"af0d93299a363735fe847f5ea241442c65843dc1bd3a7b79646b3b10072e908bf034d35cd69d378e3341f139100cd4cd03030399864ef8803a5a4f5e64fccc20bbae36d1ca22a6ddc43d2630c41105e90598fab11e5c7456df3925d4b577b113\"}";
47-
#[cfg(feature = "mainnet")]
48-
pub const DRAND_INFO_RESPONSE: &str = "{\"public_key\":\"868f005eb8e6e4ca0a47c8a77ceaa5309a47978a7c71bc5cce96366b5d7a569937c529eeda66c7293784a9402801af31\",\"period\":30,\"genesis_time\":1595431050,\"hash\":\"8990e7a9aaed2ffed73dbd7092123d6f289930540d7651336225dc172e51b2ce\",\"groupHash\":\"176f93498eac9ca337150b46d21dd58673ea4e3581185f869672e59fa4cb390a\",\"schemeID\":\"pedersen-bls-chained\",\"metadata\":{\"beaconID\":\"default\"}}";
49-
5042
#[test]
5143
fn it_can_submit_valid_pulse_when_beacon_config_exists() {
5244
new_test_ext().execute_with(|| {
@@ -117,10 +109,7 @@ fn it_rejects_invalid_pulse_due_to_bad_signature() {
117109
));
118110

119111
// Get a bad pulse (invalid signature within the pulse data)
120-
#[cfg(not(feature = "mainnet"))]
121112
let bad_http_response = "{\"round\":1000,\"randomness\":\"87f03ef5f62885390defedf60d5b8132b4dc2115b1efc6e99d166a37ab2f3a02\",\"signature\":\"b0a8b04e009cf72534321aca0f50048da596a3feec1172a0244d9a4a623a3123d0402da79854d4c705e94bc73224c341\"}";
122-
#[cfg(feature = "mainnet")]
123-
let bad_http_response = "{\"round\":1000,\"randomness\":\"87f03ef5f62885390defedf60d5b8132b4dc2115b1efc6e99d166a37ab2f3a02\",\"signature\":\"b0a8b04e009cf72534321aca0f50048da596a3feec1172a0244d9a4a623a3123d0402da79854d4c705e94bc73224c341\", \"previous_signature\":\"af0d93299a363735fe847f5ea241442c65843dc1bd3a7b79646b3b10072e908bf034d35cd69d378e3341f139100cd4cd03030399864ef8803a5a4f5e64fccc20bbae36d1ca22a6ddc43d2630c41105e90598fab11e5c7456df3925d4b577b113\"}";
124113
let u_p: DrandResponseBody = serde_json::from_str(bad_http_response).unwrap();
125114
let p: Pulse = u_p.try_into_pulse().unwrap();
126115

@@ -380,14 +369,14 @@ fn can_execute_and_handle_valid_http_responses() {
380369
let mut state = state.write();
381370
state.expect_request(PendingRequest {
382371
method: "GET".into(),
383-
uri: "https://drand.cloudflare.com/8990e7a9aaed2ffed73dbd7092123d6f289930540d7651336225dc172e51b2ce/public/1".into(),
372+
uri: "https://drand.cloudflare.com/52db9ba70e0cc0f6eaf7803dd07447a1f5477735fd3f661792ba94600c84e971/public/1".into(),
384373
response: Some(DRAND_PULSE.as_bytes().to_vec()),
385374
sent: true,
386375
..Default::default()
387376
});
388377
state.expect_request(PendingRequest {
389378
method: "GET".into(),
390-
uri: "https://drand.cloudflare.com/8990e7a9aaed2ffed73dbd7092123d6f289930540d7651336225dc172e51b2ce/public/latest".into(),
379+
uri: "https://drand.cloudflare.com/52db9ba70e0cc0f6eaf7803dd07447a1f5477735fd3f661792ba94600c84e971/public/latest".into(),
391380
response: Some(DRAND_PULSE.as_bytes().to_vec()),
392381
sent: true,
393382
..Default::default()

pallets/drand/src/types.rs

+4-20
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,9 @@ use frame_support::pallet_prelude::*;
2020
use serde::{Deserialize, Serialize};
2121
use subtensor_macros::freeze_struct;
2222

23-
/// Represents an opaque public key used in drand's mainnet
24-
#[cfg(not(feature = "mainnet"))]
25-
pub type OpaquePublicKey = BoundedVec<u8, ConstU32<96>>;
2623
/// Represents an opaque public key used in drand's quicknet
27-
#[cfg(feature = "mainnet")]
28-
pub type OpaquePublicKey = BoundedVec<u8, ConstU32<48>>;
24+
pub type OpaquePublicKey = BoundedVec<u8, ConstU32<96>>;
25+
2926
/// an opaque hash type
3027
pub type BoundedHash = BoundedVec<u8, ConstU32<32>>;
3128
/// the round number to track rounds of the beacon
@@ -87,7 +84,7 @@ impl BeaconInfoResponse {
8784

8885
/// a pulse from the drand beacon
8986
/// the expected response body from the drand api endpoint `api.drand.sh/{chainId}/public/latest`
90-
#[freeze_struct("fa1e760d5c707d26")]
87+
#[freeze_struct("a3fed2c99a0638bf")]
9188
#[derive(Debug, Decode, Default, PartialEq, Encode, Serialize, Deserialize)]
9289
pub struct DrandResponseBody {
9390
/// the randomness round number
@@ -100,10 +97,6 @@ pub struct DrandResponseBody {
10097
// TODO: use Signature (https://github.com/ideal-lab5/pallet-drand/issues/2)
10198
#[serde(with = "hex::serde")]
10299
pub signature: Vec<u8>,
103-
/// only used when running in 'chained' mode using drand's mainnet
104-
#[cfg(feature = "mainnet")]
105-
#[serde(with = "hex::serde")]
106-
pub previous_signature: Vec<u8>,
107100
}
108101

109102
impl DrandResponseBody {
@@ -115,17 +108,10 @@ impl DrandResponseBody {
115108
let bounded_signature = BoundedVec::<u8, ConstU32<144>>::try_from(self.signature.clone())
116109
.map_err(|_| "Failed to convert signature")?;
117110

118-
#[cfg(feature = "mainnet")]
119-
let bounded_prev_signature =
120-
BoundedVec::<u8, ConstU32<144>>::try_from(self.signature.clone())
121-
.map_err(|_| "Failed to convert signature")?;
122-
123111
Ok(Pulse {
124112
round: self.round,
125113
randomness: bounded_randomness,
126114
signature: bounded_signature,
127-
#[cfg(feature = "mainnet")]
128-
previous_signature: bounded_prev_signature,
129115
})
130116
}
131117
}
@@ -182,7 +168,7 @@ pub struct Metadata {
182168
}
183169

184170
/// A pulse from the drand beacon
185-
#[freeze_struct("cedd7283835f3f56")]
171+
#[freeze_struct("de1a209f66f482b4")]
186172
#[derive(
187173
Clone,
188174
Debug,
@@ -206,8 +192,6 @@ pub struct Pulse {
206192
// TODO: use Signature (https://github.com/ideal-lab5/pallet-drand/issues/2)
207193
// maybe add the sig size as a generic?
208194
pub signature: BoundedVec<u8, ConstU32<144>>,
209-
#[cfg(feature = "mainnet")]
210-
pub previous_signature: BoundedVec<u8, ConstU32<144>>,
211195
}
212196

213197
/// Payload used by to hold the pulse

pallets/drand/src/verifier.rs

-58
Original file line numberDiff line numberDiff line change
@@ -102,64 +102,6 @@ impl Verifier for QuicknetVerifier {
102102
}
103103
}
104104

105-
/// A verifier to check values received from drand's mainnet. It outputs true if valid, false otherwise
106-
///
107-
/// The [Mainnet](https://drand.love/) operates in an chained mode.
108-
/// so each round signs messages that hash the previous signature with the round number.
109-
/// It uses a 'usual' BLS approach, with 48-byte public keys in G1 and 96-byte signatures in G2
110-
///
111-
/// Values are valid if the pairing equality holds:
112-
/// $e(g_1, sig) == e(pk, msg_on_curve)$
113-
///
114-
/// where
115-
/// $sig \in \mathbb{G}_2$ is the signature
116-
/// $g_1 \in \mathbb{G}_1$ is a generator
117-
/// $msg_on_curve \in \mathbb{G}_1$ is a hash of the previous signature and current round number (hash(prev_sig || round_number))
118-
/// $pk \in \mathbb{G}_1$ is the public key, read from the input public parameters
119-
///
120-
pub struct MainnetVerifier;
121-
#[cfg(feature = "mainnet")]
122-
use w3f_bls::ZBLS;
123-
#[cfg(feature = "mainnet")]
124-
#[allow(clippy::let_unit_value)]
125-
#[allow(clippy::unit_cmp)]
126-
impl Verifier for MainnetVerifier {
127-
fn verify(beacon_config: BeaconConfiguration, pulse: Pulse) -> Result<bool, String> {
128-
// decode public key (pk)
129-
let pk =
130-
ArkScale::<G1AffineOpt>::decode(&mut beacon_config.public_key.into_inner().as_slice())
131-
.map_err(|e| format!("Failed to decode public key: {}", e))?;
132-
133-
// decode signature (sigma)
134-
let signature =
135-
ArkScale::<G2AffineOpt>::decode(&mut pulse.signature.into_inner().as_slice())
136-
.map_err(|e| format!("Failed to decode signature: {}", e))?;
137-
138-
// m = sha256(previous_signature || round)
139-
let message = message(pulse.round, &pulse.previous_signature);
140-
let hasher = <ZBLS as EngineBLS>::hash_to_curve_map();
141-
// H(m) \in G1
142-
let message_hash = hasher
143-
.hash(&message)
144-
.map_err(|e| format!("Failed to hash message: {}", e))?;
145-
146-
let mut bytes = Vec::new();
147-
message_hash
148-
.serialize_compressed(&mut bytes)
149-
.map_err(|e| format!("Failed to serialize message hash: {}", e))?;
150-
151-
let message_on_curve = ArkScale::<G2AffineOpt>::decode(&mut &bytes[..])
152-
.map_err(|e| format!("Failed to decode message on curve: {}", e))?;
153-
154-
let g1 = G1AffineOpt::generator();
155-
156-
let p1 = bls12_381::pairing_opt(g1, -signature.0);
157-
let p2 = bls12_381::pairing_opt(pk.0, message_on_curve.0);
158-
159-
Ok(p1 == p2)
160-
}
161-
}
162-
163105
/// The unsafe skip verifier is just a pass-through verification, always returns true
164106
pub struct UnsafeSkipVerifier;
165107
impl Verifier for UnsafeSkipVerifier {

0 commit comments

Comments
 (0)