Skip to content

Commit

Permalink
Make Account Derivation More Unique (paritytech#686)
Browse files Browse the repository at this point in the history
* Use more unique prefix when generating account IDs

* Update derived addresses used in tests

* Make `account` prefix more unique

Co-authored-by: Tomasz Drwięga <tomusdrw@users.noreply.github.com>

* Update test account IDs again

Co-authored-by: Tomasz Drwięga <tomusdrw@users.noreply.github.com>
  • Loading branch information
2 people authored and serban300 committed Apr 9, 2024
1 parent 4062a62 commit b1492bd
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion bridges/bin/millau/node/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,6 @@ fn derived_dave_account_is_as_expected() {
let derived: AccountId = derive_account_from_rialto_id(bp_runtime::SourceAccount::Account(dave));
assert_eq!(
derived.to_string(),
"5G81vRqUUysQGtN5aEThD5UsLdt4rZWSbVLkjuZzLHadp8ZD".to_string()
"5DNW6UVnb7TN6wX5KwXtDYR3Eccecbdzuw89HqjyNfkzce6J".to_string()
);
}
2 changes: 1 addition & 1 deletion bridges/bin/rialto/node/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,6 @@ fn derived_dave_account_is_as_expected() {
let derived: AccountId = derive_account_from_millau_id(bp_runtime::SourceAccount::Account(dave));
assert_eq!(
derived.to_string(),
"5Hg7WQyk8C1FmPzxY3xSjR7S6zZZC5sAL35vMr6NpW17jBhQ".to_string()
"5HZhdv53gSJmWWtD8XR5Ypu4PgbT5JNWwGw2mkE75cN61w9t".to_string()
);
}
10 changes: 8 additions & 2 deletions bridges/primitives/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ pub const CALL_DISPATCH_MODULE_PREFIX: &[u8] = b"pallet-bridge/call-dispatch";
/// Message-lane module prefix.
pub const MESSAGE_LANE_MODULE_PREFIX: &[u8] = b"pallet-bridge/message-lane";

/// A unique prefix for entropy when generating cross-chain account IDs.
pub const ACCOUNT_DERIVATION_PREFIX: &[u8] = b"pallet-bridge/account-derivation/account";

/// A unique prefix for entropy when generating a cross-chain account ID for the Root account.
pub const ROOT_ACCOUNT_DERIVATION_PREFIX: &[u8] = b"pallet-bridge/account-derivation/root";

/// Id of deployed module instance. We have a bunch of pallets that may be used in
/// different bridges. E.g. message-lane pallet may be deployed twice in the same
/// runtime to bridge ThisChain with Chain1 and Chain2. Sometimes we need to be able
Expand Down Expand Up @@ -80,8 +86,8 @@ where
AccountId: Encode,
{
match id {
SourceAccount::Root => ("root", bridge_id).using_encoded(blake2_256),
SourceAccount::Account(id) => ("account", bridge_id, id).using_encoded(blake2_256),
SourceAccount::Root => (ROOT_ACCOUNT_DERIVATION_PREFIX, bridge_id).using_encoded(blake2_256),
SourceAccount::Account(id) => (ACCOUNT_DERIVATION_PREFIX, bridge_id, id).using_encoded(blake2_256),
}
.into()
}
Expand Down

0 comments on commit b1492bd

Please sign in to comment.