6

In Ethereum, the contract address/account isn't formed trivially from a cryptographically-generated private-public key pair, but rather by using a separate method, as described here.

In Substrate, similar to this, a pallet-account is formed from inside the runtime by passing a PalletId (a unique identifier assigned to the pallet) to the into_account() function instead of passing a random seed as is done for normal account formation. For example: T::PalletId::get().into_account()

My question now is, how can we be sure that the account address won't be replicated by anyone else/ other pallets in the chain?

3
  • are you trying to convert a PalletId into an AccountId type? Feb 17, 2022 at 12:29
  • You mean one could generate accounts until you get the AccountId of a Pallet and then steal the Pallets' funds? Feb 17, 2022 at 17:14
  • @Purple_Turtle Yes, that's the intent. Feb 18, 2022 at 8:37

1 Answer 1

10

You cannot be sure that it won't be replicated. A different pallet could use the same seed (pallet id) to generate an account id and thus "impersonate" your pallet. This is not a problem, though, because the assumptions about pallets are different from smart contracts: Pallets are trusted modules included in the runtime deliberately by the people building the runtime (in contrast to smart contracts that can be created in a permissionless way). Thus it is fine to assume that the pallets included in a runtime cooperate with each other. If you need to generate an account id that cannot be easily replicated, you will want to use hashing on unpredictable/uncontrollable inputs such as the account sending an extrinsic in combination with its nonce and the current block number.

3
  • Thanks a lot for the clarification. Feb 18, 2022 at 8:36
  • 1
    @AsmitaDhungana Could you mark this this reply as the answer? Sep 6, 2022 at 13:10
  • 1
    @AurevoirXavier Sure! Sep 8, 2022 at 10:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.