2_特殊特性

地址注册

每条Arbitrum链都包含了原生的、预编译的Address Table Registry合约。该合约允许用户注册一个地址,并将其映射至某些索引上,可用来检索地址,以节省calldata字节。

接口如下:

  1. /** @title Precompiled contract that exists in every Arbitrum chain at 0x0000000000000000000000000000000000000066.
  2. * Allows registering / retrieving addresses at uint indices, saving calldata.
  3. */
  4. interface ArbAddressTable {
  5. /**
  6. * @notice Register an address in the address table
  7. * @param addr address to register
  8. * @return index of the address (existing index, or newly created index if not already registered)
  9. */
  10. function register(address addr) external returns(uint);
  11. /**
  12. * @param addr address to lookup
  13. * @return index of an address in the address table (revert if address isn't in the table)
  14. */
  15. function lookup(address addr) external view returns(uint);
  16. /**
  17. * @notice Check whether an address exists in the address table
  18. * @param addr address to check for presence in table
  19. * @return true if address is in table
  20. */
  21. function addressExists(address addr) external view returns(bool);
  22. /**
  23. * @return size of address table (= first unused index)
  24. */
  25. function size() external view returns(uint);
  26. /**
  27. * @param index index to lookup address
  28. * @return address at a given index in address table (revert if index is beyond end of table)
  29. */
  30. function lookupIndex(uint index) external view returns(address);
  31. /**
  32. * @notice read a compressed address from a bytes buffer
  33. * @param buf bytes buffer containing an address
  34. * @param offset offset of target address
  35. * @return resulting address and updated offset into the buffer (revert if buffer is too short)
  36. */
  37. function decompress(bytes calldata buf, uint offset) external pure returns(address, uint);
  38. /**
  39. * @notice compress an address and return the result
  40. * @param addr address to compress
  41. * @return compressed address bytes
  42. */
  43. function compress(address addr) external returns(bytes memory);
  44. }

用例请见Arbiswap Demo

参数序列化

一般来说,L1的calldata是Arbitrum交易的主要燃气成本。所以如果你想在Arbitrum上优化合约的燃气成本,可以尽量减少calldata的使用。

对大部分合约来说,可接受的一种方法是,将函数的参数替换为序列化的字节数组,再让合约对数据进行反序列化。

arb-ts中有序列化的方法(以及与Address Table合约互动的方法)。

用例请见Arbiswap Demo:

预编译合约

为实现特定功能,Arbitrum有几个预编译合约:

BLS签名

即将到来! 1_总览 3_Solidity支持