SystemContractsCaller

Git Source

Author: Matter Labs

A library that allows calling contracts with the isSystem flag.

It is needed to call ContractDeployer and NonceHolder.

Note: security-contact: security@matterlabs.dev

Functions

systemCall

Makes a call with the isSystem flag.

Note, that the isSystem flag can only be set when calling system contracts.

function systemCall(
  uint32 gasLimit,
  address to,
  uint256 value,
  bytes memory data
) internal returns (bool success);

Parameters

NameTypeDescription
gasLimituint32The gas limit for the call.
toaddressThe address to call.
valueuint256The value to pass with the transaction.
databytesThe calldata.

Returns

NameTypeDescription
successboolWhether the transaction has been successful.

systemCallWithReturndata

Makes a call with the isSystem flag.

Note, that the isSystem flag can only be set when calling system contracts.

function systemCallWithReturndata(
  uint32 gasLimit,
  address to,
  uint128 value,
  bytes memory data
) internal returns (bool success, bytes memory returnData);

Parameters

NameTypeDescription
gasLimituint32The gas limit for the call.
toaddressThe address to call.
valueuint128The value to pass with the transaction.
databytesThe calldata.

Returns

NameTypeDescription
successboolWhether the transaction has been successful.
returnDatabytesThe returndata of the transaction (revert reason in case the transaction has failed).

systemCallWithPropagatedRevert

Makes a call with the isSystem flag.

Note, that the isSystem flag can only be set when calling system contracts.

function systemCallWithPropagatedRevert(
  uint32 gasLimit,
  address to,
  uint128 value,
  bytes memory data
) internal returns (bytes memory returnData);

Parameters

NameTypeDescription
gasLimituint32The gas limit for the call.
toaddressThe address to call.
valueuint128The value to pass with the transaction.
databytesThe calldata.

Returns

NameTypeDescription
returnDatabytesThe returndata of the transaction. In case the transaction reverts, the error bubbles up to the parent frame.

getFarCallABI

Calculates the packed representation of the FarCallABI.

The FarCallABI has the following structure: pub struct FarCallABI { pub memory_quasi_fat_pointer: FatPointer, pub gas_passed: u32, pub shard_id: u8, pub forwarding_mode: FarCallForwardPageType, pub constructor_call: bool, pub to_system: bool, } The FatPointer struct: pub struct FatPointer { pub offset: u32, // offset relative to start pub memory_page: u32, // memory page where slice is located pub start: u32, // absolute start of the slice pub length: u32, // length of the slice }

Note, that the actual layout is the following: [0..32) bits -- the calldata offset [32..64) bits -- the memory page to use. Can be left blank in most of the cases. [64..96) bits -- the absolute start of the slice [96..128) bits -- the length of the slice. [128..192) bits -- empty bits. [192..224) bits -- gasPassed. [224..232) bits -- forwarding_mode [232..240) bits -- shard id. [240..248) bits -- constructor call flag [248..256] bits -- system call flag

function getFarCallABI(
  uint32 dataOffset,
  uint32 memoryPage,
  uint32 dataStart,
  uint32 dataLength,
  uint32 gasPassed,
  uint8 shardId,
  CalldataForwardingMode forwardingMode,
  bool isConstructorCall,
  bool isSystemCall
) internal pure returns (uint256 farCallAbi);

Parameters

NameTypeDescription
dataOffsetuint32Calldata offset in memory. Provide 0 unless using custom pointer.
memoryPageuint32Memory page to use. Provide 0 unless using custom pointer.
dataStartuint32The start of the calldata slice. Provide the offset in memory if not using custom pointer.
dataLengthuint32The calldata length. Provide the length of the calldata in bytes unless using custom pointer.
gasPasseduint32The gas to pass with the call.
shardIduint8Of the account to call. Currently only 0 is supported.
forwardingModeCalldataForwardingModeThe forwarding mode to use: - provide CalldataForwardingMode.UseHeap when using your current memory - provide CalldataForwardingMode.ForwardFatPointer when using custom pointer.
isConstructorCallboolWhether the call will be a call to the constructor (ignored when the caller is not a system contract).
isSystemCallboolWhether the call will have the isSystem flag.

Returns

NameTypeDescription
farCallAbiuint256The far call ABI.

getFarCallABIWithEmptyFatPointer

Calculates the packed representation of the FarCallABI with zero fat pointer fields.

function getFarCallABIWithEmptyFatPointer(
  uint32 gasPassed,
  uint8 shardId,
  CalldataForwardingMode forwardingMode,
  bool isConstructorCall,
  bool isSystemCall
) internal pure returns (uint256 farCallAbiWithEmptyFatPtr);

Parameters

NameTypeDescription
gasPasseduint32The gas to pass with the call.
shardIduint8Of the account to call. Currently only 0 is supported.
forwardingModeCalldataForwardingModeThe forwarding mode to use: - provide CalldataForwardingMode.UseHeap when using your current memory - provide CalldataForwardingMode.ForwardFatPointer when using custom pointer.
isConstructorCallboolWhether the call will be a call to the constructor (ignored when the caller is not a system contract).
isSystemCallboolWhether the call will have the isSystem flag.

Returns

NameTypeDescription
farCallAbiWithEmptyFatPtruint256The far call ABI with zero fat pointer fields.