Skip to content

Latest commit

 

History

History
100 lines (69 loc) · 3.58 KB

File metadata and controls

100 lines (69 loc) · 3.58 KB

2_特殊特性

地址注册

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

接口如下:


/** @title Precompiled contract that exists in every Arbitrum chain at 0x0000000000000000000000000000000000000066.
* Allows registering / retrieving addresses at uint indices, saving calldata.
*/
interface ArbAddressTable {
    /**
    * @notice Register an address in the address table
    * @param addr address to register
    * @return index of the address (existing index, or newly created index if not already registered)
    */
    function register(address addr) external returns(uint);

    /**
    * @param addr address to lookup
    * @return index of an address in the address table (revert if address isn't in the table)
    */
    function lookup(address addr) external view returns(uint);

    /**
    * @notice Check whether an address exists in the address table
    * @param addr address to check for presence in table
    * @return true if address is in table
    */
    function addressExists(address addr) external view returns(bool);

    /**
    * @return size of address table (= first unused index)
     */
    function size() external view returns(uint);

    /**
    * @param index index to lookup address
    * @return address at a given index in address table (revert if index is beyond end of table)
    */
    function lookupIndex(uint index) external view returns(address);

    /**
    * @notice read a compressed address from a bytes buffer
    * @param buf bytes buffer containing an address
    * @param offset offset of target address
    * @return resulting address and updated offset into the buffer (revert if buffer is too short)
    */
    function decompress(bytes calldata buf, uint offset) external pure returns(address, uint);

    /**
    * @notice compress an address and return the result
    * @param addr address to compress
    * @return compressed address bytes
    */
    function compress(address addr) external returns(bytes memory);
}

用例请见Arbiswap Demo

参数序列化

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

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

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

用例请见Arbiswap Demo:

预编译合约

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

BLS签名

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