Documentation ¶
Index ¶
- Constants
- Variables
- func ABIEncodeProof(proof *types.COAOwnershipProofInContext) ([]byte, error)
- func ArchContract(address types.Address, heightProvider func() (uint64, error), ...) types.Precompile
- func DecodeABIEncodedProof(input []byte) (*types.COAOwnershipProofInContext, error)
- func EncodeAddress(address gethCommon.Address, buffer []byte, index int) error
- func EncodeBool(bitSet bool, buffer []byte, index int) error
- func EncodeBytes(data []byte, buffer []byte, headerIndex, payloadIndex int) error
- func EncodeBytes32(data []byte, buffer []byte, index int) error
- func EncodeUint64(inp uint64, buffer []byte, index int) error
- func MultiFunctionPrecompileContract(address types.Address, functions []Function) types.Precompile
- func ReadAddress(buffer []byte, index int) (gethCommon.Address, error)
- func ReadBool(buffer []byte, index int) (bool, error)
- func ReadBytes(buffer []byte, index int) ([]byte, error)
- func ReadBytes32(buffer []byte, index int) ([]byte, error)
- func ReadBytes4(buffer []byte, index int) ([]byte, error)
- func ReadBytes8(buffer []byte, index int) ([]byte, error)
- func ReadUint256(buffer []byte, index int) (*big.Int, error)
- func ReadUint64(buffer []byte, index int) (uint64, error)
- func SizeNeededForBytesEncoding(data []byte) int
- type Function
- type FunctionSelector
Constants ¶
const ( FixedSizeUnitDataReadSize = 32 Bytes4DataReadSize = 4 Bytes8DataReadSize = 8 Bytes32DataReadSize = 32 Uint64ByteSize = 8 EncodedBoolSize = FixedSizeUnitDataReadSize EncodedAddressSize = FixedSizeUnitDataReadSize EncodedBytes32Size = FixedSizeUnitDataReadSize EncodedBytes4Size = FixedSizeUnitDataReadSize EncodedBytes8Size = FixedSizeUnitDataReadSize EncodedUint64Size = FixedSizeUnitDataReadSize EncodedUint256Size = FixedSizeUnitDataReadSize )
This package provides fast and efficient utilities needed for abi encoding and decoding encodings are mostly used for testing purpose if more complex encoding and decoding is needed please use the abi package and pass the ABIs, though that has a performance overhead.
const FunctionSelectorLength = 4
const InvalidMethodCallGasUsage = uint64(1)
InvalidMethodCallGasUsage captures how much gas we charge for invalid method call
Variables ¶
var ( FlowBlockHeightFuncSig = ComputeFunctionSelector("flowBlockHeight", nil) // TODO: fix me ProofVerifierFuncSig = ComputeFunctionSelector( "verifyCOAOwnershipProof", []string{"address", "bytes32", "bytes"}, ) RandomSourceFuncSig = ComputeFunctionSelector("getRandomSource", []string{"uint64"}) RevertibleRandomFuncSig = ComputeFunctionSelector("revertibleRandom", nil) // FlowBlockHeightFixedGas is set to match the `number` opCode (0x43) FlowBlockHeightFixedGas = uint64(2) // ProofVerifierBaseGas covers the cost of decoding, checking capability the resource // and the rest of operations excluding signature verification ProofVerifierBaseGas = uint64(1_000) // ProofVerifierGasMultiplerPerSignature is set to match `ECRECOVER` // but we might increase this in the future ProofVerifierGasMultiplerPerSignature = uint64(3_000) // RandomSourceGas covers the cost of obtaining random sournce bytes RandomSourceGas = uint64(1_000) // RevertibleRandomGas covers the cost of calculating a revertible random bytes RevertibleRandomGas = uint64(1_000) )
var ErrBufferTooSmall = errors.New("buffer too small for encoding")
var ErrDataTooLarge = errors.New("input data is too large for encoding")
var ErrInputDataTooSmall = errors.New("input data is too small for decoding")
var ErrInvalidMethodCall = errors.New("invalid method call")
ErrInvalidMethodCall is returned when the method is not available on the contract
Functions ¶
func ABIEncodeProof ¶
func ABIEncodeProof(proof *types.COAOwnershipProofInContext) ([]byte, error)
func ArchContract ¶
func ArchContract( address types.Address, heightProvider func() (uint64, error), proofVer func(*types.COAOwnershipProofInContext) (bool, error), randomSourceProvider func(uint64) (uint64, error), revertibleRandomGenerator func() (uint64, error), ) types.Precompile
ArchContract return a procompile for the Cadence Arch contract which facilitates access of Flow EVM environment into the Cadence environment. for more details see this Flip 223.
func DecodeABIEncodedProof ¶
func DecodeABIEncodedProof(input []byte) (*types.COAOwnershipProofInContext, error)
func EncodeAddress ¶
func EncodeAddress(address gethCommon.Address, buffer []byte, index int) error
EncodeAddress encodes the address and add it to the buffer at the index
func EncodeBool ¶
EncodeBool encodes a boolean into fixed size unit of encoded data
func EncodeBytes ¶
EncodeBytes encodes the data into the buffer at index and append payload to the end of buffer
func EncodeBytes32 ¶
EncodeBytes32 encodes data into a bytes 32
func EncodeUint64 ¶
EncodeUint64 encodes a uint64 into fixed size unit of encoded data (zero-padded on the left side)
func MultiFunctionPrecompileContract ¶
func MultiFunctionPrecompileContract( address types.Address, functions []Function, ) types.Precompile
MultiFunctionPrecompileContract constructs a multi-function precompile smart contract
func ReadAddress ¶
func ReadAddress(buffer []byte, index int) (gethCommon.Address, error)
ReadAddress reads an address from the buffer at index
func ReadBytes32 ¶
ReadBytes32 reads a 32 byte slice from the buffer at index
func ReadBytes4 ¶
ReadBytes4 reads a 4 byte slice from the buffer at index
func ReadBytes8 ¶
ReadBytes8 reads a 8 byte slice from the buffer at index
func ReadUint256 ¶
ReadUint256 reads an address from the buffer at index
func ReadUint64 ¶
ReadUint64 reads a uint64 from the buffer at index
func SizeNeededForBytesEncoding ¶
SizeNeededForBytesEncoding computes the number of bytes needed for bytes encoding
Types ¶
type Function ¶
type Function interface { // FunctionSelector returns the function selector bytes for this function FunctionSelector() FunctionSelector // ComputeGas computes the gas needed for the given input ComputeGas(input []byte) uint64 // Run runs the function on the given data Run(input []byte) ([]byte, error) }
Function is an interface for a function in a multi-function precompile contract
type FunctionSelector ¶
type FunctionSelector [FunctionSelectorLength]byte
This is derived as the first 4 bytes of the Keccak hash of the ASCII form of the signature of the method
func ComputeFunctionSelector ¶
func ComputeFunctionSelector(name string, args []string) FunctionSelector
ComputeFunctionSelector computes the function selector given the canonical name of function and args. for example the canonical format for int is int256
func SplitFunctionSelector ¶
func SplitFunctionSelector(input []byte) (FunctionSelector, []byte)
SplitFunctionSelector splits the function signature from input data and returns the rest of the data
func (FunctionSelector) Bytes ¶
func (fs FunctionSelector) Bytes() []byte