Skip to content

Commit 83d100d

Browse files
committed
Make SS58 of precompiles optional
1 parent ef91095 commit 83d100d

File tree

7 files changed

+21
-14
lines changed

7 files changed

+21
-14
lines changed

precompiles/src/balance_transfer.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ where
2424
<R as pallet_balances::Config>::Balance: TryFrom<U256>,
2525
{
2626
const INDEX: u64 = 2048;
27-
const ADDRESS_SS58: [u8; 32] = [
27+
const ADDRESS_SS58: Option<[u8; 32]> = Some([
2828
0x07, 0xec, 0x71, 0x2a, 0x5d, 0x38, 0x43, 0x4d, 0xdd, 0x03, 0x3f, 0x8f, 0x02, 0x4e, 0xcd,
2929
0xfc, 0x4b, 0xb5, 0x95, 0x1c, 0x13, 0xc3, 0x08, 0x5c, 0x39, 0x9c, 0x8a, 0x5f, 0x62, 0x93,
3030
0x70, 0x5d,
31-
];
31+
]);
3232
}
3333

3434
#[precompile_utils::precompile]
@@ -60,6 +60,11 @@ where
6060
value: amount_sub.unique_saturated_into(),
6161
};
6262

63-
handle.try_dispatch_runtime_call::<R, _>(call, contract_to_origin(&Self::ADDRESS_SS58)?)
63+
handle.try_dispatch_runtime_call::<R, _>(
64+
call,
65+
contract_to_origin(
66+
&Self::ADDRESS_SS58.expect("ADDRESS_SS58 is defined for BalanceTransferPrecompile"),
67+
)?,
68+
)
6469
}
6570
}

precompiles/src/ed25519.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ pub(crate) struct Ed25519Verify;
1212

1313
impl PrecompileExt for Ed25519Verify {
1414
const INDEX: u64 = 1026;
15-
const ADDRESS_SS58: [u8; 32] = [0; 32];
15+
const ADDRESS_SS58: Option<[u8; 32]> = None;
1616
}
1717

1818
impl LinearCostPrecompile for Ed25519Verify {

precompiles/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,5 +310,5 @@ trait PrecompileExt: Precompile {
310310
const INDEX: u64;
311311
// ss58 public key i.e., the contract sends funds it received to the destination address from
312312
// the method parameter.
313-
const ADDRESS_SS58: [u8; 32];
313+
const ADDRESS_SS58: Option<[u8; 32]>;
314314
}

precompiles/src/metagraph.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ where
1616
R::AccountId: ByteArray,
1717
{
1818
const INDEX: u64 = 2050;
19-
const ADDRESS_SS58: [u8; 32] = [0; 32];
19+
const ADDRESS_SS58: Option<[u8; 32]> = None;
2020
}
2121

2222
#[precompile_utils::precompile]

precompiles/src/neuron.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ where
2323
<R as pallet_evm::Config>::AddressMapping: AddressMapping<R::AccountId>,
2424
{
2525
const INDEX: u64 = 2052;
26-
const ADDRESS_SS58: [u8; 32] = [
26+
const ADDRESS_SS58: Option<[u8; 32]> = Some([
2727
0xbc, 0x46, 0x35, 0x79, 0xbc, 0x99, 0xf9, 0xee, 0x7c, 0x59, 0xed, 0xee, 0x20, 0x61, 0xa3,
2828
0x09, 0xd2, 0x1e, 0x68, 0xd5, 0x39, 0xb6, 0x40, 0xec, 0x66, 0x46, 0x90, 0x30, 0xab, 0x74,
2929
0xc1, 0xdb,
30-
];
30+
]);
3131
}
3232

3333
#[precompile_utils::precompile]

precompiles/src/staking.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ where
6262
<<R as frame_system::Config>::Lookup as StaticLookup>::Source: From<R::AccountId>,
6363
{
6464
const INDEX: u64 = 2053;
65-
const ADDRESS_SS58: [u8; 32] = [0; 32];
65+
const ADDRESS_SS58: Option<[u8; 32]> = None;
6666
}
6767

6868
#[precompile_utils::precompile]
@@ -211,11 +211,11 @@ where
211211
<<R as frame_system::Config>::Lookup as StaticLookup>::Source: From<R::AccountId>,
212212
{
213213
const INDEX: u64 = 2049;
214-
const ADDRESS_SS58: [u8; 32] = [
214+
const ADDRESS_SS58: Option<[u8; 32]> = Some([
215215
0x26, 0xf4, 0x10, 0x1e, 0x52, 0xb7, 0x57, 0x34, 0x33, 0x24, 0x5b, 0xc3, 0x0a, 0xe1, 0x8b,
216216
0x63, 0x99, 0x53, 0xd8, 0x41, 0x79, 0x33, 0x03, 0x61, 0x4d, 0xfa, 0xcf, 0xf0, 0x37, 0xf7,
217217
0x12, 0x94,
218-
];
218+
]);
219219
}
220220

221221
#[precompile_utils::precompile]
@@ -368,7 +368,9 @@ where
368368
account_id: &<R as frame_system::Config>::AccountId,
369369
amount: U256,
370370
) -> Result<(), PrecompileFailure> {
371-
let smart_contract_account_id = R::AccountId::from(Self::ADDRESS_SS58);
371+
let smart_contract_account_id = R::AccountId::from(
372+
Self::ADDRESS_SS58.expect("ADDRESS_SS58 is defined for StakingPrecompile"),
373+
);
372374
let amount_sub =
373375
<R as pallet_evm::Config>::BalanceConverter::into_substrate_balance(amount)
374376
.ok_or(ExitError::OutOfFund)?;

precompiles/src/subnet.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ where
2929
// <<R as frame_system::Config>::Lookup as StaticLookup>::Source: From<R::AccountId>,
3030
{
3131
const INDEX: u64 = 2051;
32-
const ADDRESS_SS58: [u8; 32] = [
32+
const ADDRESS_SS58: Option<[u8; 32]> = Some([
3333
0x3a, 0x86, 0x18, 0xfb, 0xbb, 0x1b, 0xbc, 0x47, 0x86, 0x64, 0xff, 0x53, 0x46, 0x18, 0x0c,
3434
0x35, 0xd0, 0x9f, 0xac, 0x26, 0xf2, 0x02, 0x70, 0x85, 0xb3, 0x1c, 0x56, 0xc1, 0x06, 0x3c,
3535
0x1c, 0xd3,
36-
];
36+
]);
3737
}
3838

3939
#[precompile_utils::precompile]

0 commit comments

Comments
 (0)