[Referendum: 83] Set Code for AuthorMapping, Randomness and XcmUtils Precompiles

Polkassembly post

TL: DR

Sets a dummy code for AuthorMapping, Randomness and XcmUtils precompiles so smart contracts can more easily interact with them.

Summary

Precompiles are system contracts that don’t have any code in it. Therefore, eth_getCode returns 0x or emtpy.

When smart contracts make calls to other contracts like Contract.functionName there is code.length check which fails. Consequently, smart contracts can’t easily call/interact with precompiles.

By setting this dummy code (0x60006000fd, which is a basic revert opcode) smart contracts can now more easily interact with these precompiles.

Proposal

Proposal #X19 with the following hash: 0x9e4ca11e73b4b33d47ceee3cae51326b5df3ffd91ee58c6c8866496b5e82ee66

Technical details:

The storage key for an address can be calculated using the following code:

const getStorageKey = async (address) => {
  let palletEncoder = new TextEncoder().encode('EVM');
  let palletHash = xxhashAsU8a(palletEncoder, 128);
  let storageEncoder = new TextEncoder().encode('AccountCodes');
  let storageHash = xxhashAsU8a(storageEncoder, 128);
  let assetAddress = new Uint8Array(hexToU8a(address));
  let addressHash = blake2AsU8a(assetAddress, 128);
  let concatKey = new Uint8Array([...palletHash, ...storageHash, ...addressHash, ...assetAddress]);

  return u8aToHex(concatKey);
};

The SCALE encoded call data is:

0x00050c11011da53b775b270400e7e61ed5cbc5a146ea70f53d5a3306ce02aaf97049cf181abbb77f5fe3a60fd004a7063f17f63dda0000000000000000000000000000000000000807181460006000fd11011da53b775b270400e7e61ed5cbc5a146ea70f53d5a3306ce02aaf97049cf181ac1c062eb3ecc887abc7fd90c52bc68420000000000000000000000000000000000000809181460006000fd11011da53b775b270400e7e61ed5cbc5a146ea70f53d5a3306ce02aaf97049cf181a5ae0b760b393d12e71ff11e979ba8fdc000000000000000000000000000000000000080c181460006000fd

You can find the code use to calculate the SCALE encoded call data here.

3 Likes