Skip to content

Commit 299cfe3

Browse files
committed
revert UA pallet changes
1 parent a73eb88 commit 299cfe3

File tree

2 files changed

+14
-47
lines changed

2 files changed

+14
-47
lines changed

pallets/unified-accounts/src/lib.rs

+7-8
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ use frame_support::{
7676
},
7777
};
7878
use frame_system::{ensure_signed, pallet_prelude::*};
79-
pub use pallet::*;
8079
use pallet_evm::AddressMapping;
8180
use precompile_utils::keccak256;
8281
use sp_core::{H160, H256, U256};
@@ -87,6 +86,8 @@ use sp_runtime::{
8786
};
8887
use sp_std::marker::PhantomData;
8988

89+
pub use pallet::*;
90+
9091
pub mod weights;
9192
pub use weights::WeightInfo;
9293

@@ -192,8 +193,7 @@ pub mod pallet {
192193
);
193194

194195
// recover evm address from signature
195-
let payload_hash = Self::build_signing_payload(&who);
196-
let address = Self::verify_signature(&signature, payload_hash)
196+
let address = Self::verify_signature(&who, &signature)
197197
.ok_or(Error::<T>::UnexpectedSignatureFormat)?;
198198

199199
ensure!(evm_address == address, Error::<T>::InvalidSignature);
@@ -296,13 +296,12 @@ impl<T: Config> Pallet<T> {
296296
keccak_256(&payload)
297297
}
298298

299-
pub fn recover_pubkey(sig: &EvmSignature, payload_hash: [u8; 32]) -> Option<[u8; 64]> {
300-
sp_io::crypto::secp256k1_ecdsa_recover(sig, &payload_hash).ok()
301-
}
299+
pub fn verify_signature(who: &T::AccountId, sig: &EvmSignature) -> Option<EvmAddress> {
300+
let payload_hash = Self::build_signing_payload(who);
302301

303-
pub fn verify_signature(sig: &EvmSignature, payload_hash: [u8; 32]) -> Option<EvmAddress> {
304-
Self::recover_pubkey(sig, payload_hash)
302+
sp_io::crypto::secp256k1_ecdsa_recover(sig, &payload_hash)
305303
.map(|pubkey| H160::from(H256::from_slice(&keccak_256(&pubkey))))
304+
.ok()
306305
}
307306

308307
fn build_domain_separator() -> [u8; 32] {

pallets/unified-accounts/src/tests.rs

+7-39
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,12 @@ use sp_runtime::{traits::StaticLookup, AccountId32, MultiAddress};
3232
/// EIP712 Payload struct
3333
#[derive(Eip712, EthAbiType, Clone)]
3434
#[eip712(
35-
name = "Astar EVM Claim",
36-
version = "1",
37-
chain_id = 1024,
38-
// mock genisis hash
39-
raw_salt = "0x4545454545454545454545454545454545454545454545454545454545454545"
40-
)]
35+
name = "Astar EVM Claim",
36+
version = "1",
37+
chain_id = 1024,
38+
// mock genisis hash
39+
raw_salt = "0x4545454545454545454545454545454545454545454545454545454545454545"
40+
)]
4141
struct Claim {
4242
substrate_address: Bytes,
4343
}
@@ -83,7 +83,7 @@ fn eip712_signature_verify_works() {
8383
let sig = UnifiedAccounts::eth_sign_prehash(&claim_hash, &alice_secret());
8484
assert_eq!(
8585
Some(UnifiedAccounts::eth_address(&alice_secret())),
86-
UnifiedAccounts::verify_signature(&sig, claim_hash),
86+
UnifiedAccounts::verify_signature(&ALICE, &sig),
8787
"signature verification should work"
8888
);
8989
});
@@ -397,35 +397,3 @@ fn charging_storage_fee_should_not_reap_account() {
397397
);
398398
});
399399
}
400-
401-
#[test]
402-
fn recover_public_key_works() {
403-
ExtBuilder::default().build().execute_with(|| {
404-
let claim = Claim {
405-
substrate_address: ALICE.encode().into(),
406-
};
407-
408-
let claim_hash = UnifiedAccounts::build_signing_payload(&ALICE);
409-
// assert signing payload is correct
410-
assert_eq!(
411-
claim.encode_eip712().unwrap(),
412-
claim_hash,
413-
"signing payload should match"
414-
);
415-
416-
// sign the payload
417-
let signature = UnifiedAccounts::eth_sign_prehash(&claim_hash, &alice_secret());
418-
419-
let expected_pubkey =
420-
&libsecp256k1::PublicKey::from_secret_key(&alice_secret()).serialize()[1..65];
421-
422-
// assert public key recovery works
423-
assert_eq!(
424-
expected_pubkey,
425-
UnifiedAccounts::recover_pubkey(&signature, claim_hash)
426-
.unwrap()
427-
.as_ref(),
428-
"recover public key should work"
429-
);
430-
});
431-
}

0 commit comments

Comments
 (0)