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
3 changes: 1 addition & 2 deletions evm-tests/test/uid.precompile.lookup.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,11 @@ describe("Test the UID Lookup precompile", () => {
const signature = await evmWallet.signMessage(concatenatedArray);
const associateEvmKeyTx = api.tx.SubtensorModule.associate_evm_key({
netuid: netuid,
hotkey: convertPublicKeyToSs58(hotkey.publicKey),
evm_key: convertToFixedSizeBinary(evmWallet.address, 20),
block_number: BigInt(blockNumber),
signature: convertToFixedSizeBinary(signature, 65)
});
const signer = getSignerFromKeypair(coldkey);
const signer = getSignerFromKeypair(hotkey);
await waitForTransactionCompletion(api, associateEvmKeyTx, signer)
.then(() => { })
.catch((error) => { console.log(`transaction error ${error}`) });
Expand Down
3 changes: 1 addition & 2 deletions pallets/subtensor/src/macros/dispatches.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2001,12 +2001,11 @@ mod dispatches {
pub fn associate_evm_key(
origin: T::RuntimeOrigin,
netuid: NetUid,
hotkey: T::AccountId,
evm_key: H160,
block_number: u64,
signature: Signature,
) -> DispatchResult {
Self::do_associate_evm_key(origin, netuid, hotkey, evm_key, block_number, signature)
Self::do_associate_evm_key(origin, netuid, evm_key, block_number, signature)
}

/// Recycles alpha from a cold/hot key pair, reducing AlphaOut on a subnet
Expand Down
49 changes: 4 additions & 45 deletions pallets/subtensor/src/tests/evm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,8 @@ fn test_associate_evm_key_success() {
let signature = sign_evm_message(&pair, message);

assert_ok!(SubtensorModule::associate_evm_key(
RuntimeOrigin::signed(coldkey),
RuntimeOrigin::signed(hotkey),
netuid,
hotkey,
evm_key,
block_number,
signature,
Expand Down Expand Up @@ -105,9 +104,8 @@ fn test_associate_evm_key_different_block_number_success() {
let signature = sign_evm_message(&pair, message);

assert_ok!(SubtensorModule::associate_evm_key(
RuntimeOrigin::signed(coldkey),
RuntimeOrigin::signed(hotkey),
netuid,
hotkey,
evm_key,
block_number,
signature,
Expand All @@ -125,43 +123,6 @@ fn test_associate_evm_key_different_block_number_success() {
});
}

#[test]
fn test_associate_evm_key_coldkey_does_not_own_hotkey() {
new_test_ext(1).execute_with(|| {
let netuid = NetUid::from(1);

let tempo: u16 = 2;
let modality: u16 = 2;

add_network(netuid, tempo, modality);

let coldkey = U256::from(1);
let hotkey = U256::from(2);

let pair = ecdsa::Pair::generate().0;
let public = pair.public();
let evm_key = public_to_evm_key(&public);
let block_number = frame_system::Pallet::<Test>::block_number();
let hashed_block_number = keccak_256(block_number.encode().as_ref());
let hotkey_bytes = hotkey.encode();

let message = [hotkey_bytes.as_ref(), hashed_block_number.as_ref()].concat();
let signature = sign_evm_message(&pair, message);

assert_err!(
SubtensorModule::associate_evm_key(
RuntimeOrigin::signed(coldkey),
netuid,
hotkey,
evm_key,
block_number,
signature,
),
Error::<Test>::NonAssociatedColdKey
);
});
}

#[test]
fn test_associate_evm_key_hotkey_not_registered_in_subnet() {
new_test_ext(1).execute_with(|| {
Expand All @@ -188,9 +149,8 @@ fn test_associate_evm_key_hotkey_not_registered_in_subnet() {

assert_err!(
SubtensorModule::associate_evm_key(
RuntimeOrigin::signed(coldkey),
RuntimeOrigin::signed(hotkey),
netuid,
hotkey,
evm_key,
block_number,
signature,
Expand Down Expand Up @@ -229,9 +189,8 @@ fn test_associate_evm_key_using_wrong_hash_function() {

assert_err!(
SubtensorModule::associate_evm_key(
RuntimeOrigin::signed(coldkey),
RuntimeOrigin::signed(hotkey),
netuid,
hotkey,
evm_key,
block_number,
signature,
Expand Down
8 changes: 1 addition & 7 deletions pallets/subtensor/src/utils/evm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,11 @@ impl<T: Config> Pallet<T> {
pub fn do_associate_evm_key(
origin: T::RuntimeOrigin,
netuid: NetUid,
hotkey: T::AccountId,
evm_key: H160,
block_number: u64,
mut signature: Signature,
) -> dispatch::DispatchResult {
let coldkey = ensure_signed(origin)?;

ensure!(
Self::get_owning_coldkey_for_hotkey(&hotkey) == coldkey,
Error::<T>::NonAssociatedColdKey
);
let hotkey = ensure_signed(origin)?;

// Normalize the v value to 0 or 1
if signature.0[64] >= 27 {
Expand Down
2 changes: 1 addition & 1 deletion runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
// `spec_version`, and `authoring_version` are the same between Wasm and native.
// This value is set to 100 to notify Polkadot-JS App (https://polkadot.js.org/apps) to use
// the compatible custom types.
spec_version: 278,
spec_version: 279,
impl_version: 1,
apis: RUNTIME_API_VERSIONS,
transaction_version: 1,
Expand Down
Loading