SystemContractsCaller
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
Name | Type | Description |
---|---|---|
gasLimit | uint32 | The gas limit for the call. |
to | address | The address to call. |
value | uint256 | The value to pass with the transaction. |
data | bytes | The calldata. |
Returns
Name | Type | Description |
---|---|---|
success | bool | Whether 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
Name | Type | Description |
---|---|---|
gasLimit | uint32 | The gas limit for the call. |
to | address | The address to call. |
value | uint128 | The value to pass with the transaction. |
data | bytes | The calldata. |
Returns
Name | Type | Description |
---|---|---|
success | bool | Whether the transaction has been successful. |
returnData | bytes | The 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
Name | Type | Description |
---|---|---|
gasLimit | uint32 | The gas limit for the call. |
to | address | The address to call. |
value | uint128 | The value to pass with the transaction. |
data | bytes | The calldata. |
Returns
Name | Type | Description |
---|---|---|
returnData | bytes | The 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
Name | Type | Description |
---|---|---|
dataOffset | uint32 | Calldata offset in memory. Provide 0 unless using custom pointer. |
memoryPage | uint32 | Memory page to use. Provide 0 unless using custom pointer. |
dataStart | uint32 | The start of the calldata slice. Provide the offset in memory if not using custom pointer. |
dataLength | uint32 | The calldata length. Provide the length of the calldata in bytes unless using custom pointer. |
gasPassed | uint32 | The gas to pass with the call. |
shardId | uint8 | Of the account to call. Currently only 0 is supported. |
forwardingMode | CalldataForwardingMode | The forwarding mode to use: - provide CalldataForwardingMode.UseHeap when using your current memory - provide CalldataForwardingMode.ForwardFatPointer when using custom pointer. |
isConstructorCall | bool | Whether the call will be a call to the constructor (ignored when the caller is not a system contract). |
isSystemCall | bool | Whether the call will have the isSystem flag. |
Returns
Name | Type | Description |
---|---|---|
farCallAbi | uint256 | The 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
Name | Type | Description |
---|---|---|
gasPassed | uint32 | The gas to pass with the call. |
shardId | uint8 | Of the account to call. Currently only 0 is supported. |
forwardingMode | CalldataForwardingMode | The forwarding mode to use: - provide CalldataForwardingMode.UseHeap when using your current memory - provide CalldataForwardingMode.ForwardFatPointer when using custom pointer. |
isConstructorCall | bool | Whether the call will be a call to the constructor (ignored when the caller is not a system contract). |
isSystemCall | bool | Whether the call will have the isSystem flag. |
Returns
Name | Type | Description |
---|---|---|
farCallAbiWithEmptyFatPtr | uint256 | The far call ABI with zero fat pointer fields. |