Documentation
¶
Overview ¶
Package bytecode provides tools for decoding and analyzing Ethereum contract, transaction, event and log bytecode. The package is designed to extract and interpret metadata from Ethereum contract creation bytecode. It provides a Metadata struct that represents the metadata contained in the bytecode, as defined by the Solidity compiler. This includes information such as the IPFS hash of the metadata, the Swarm hash of the metadata, experimental metadata, and the version of the Solidity compiler used.
Index ¶
- type Argument
- type Constructor
- type Metadata
- func (m *Metadata) AuxFound(b []byte) bool
- func (m *Metadata) GetAuxBytecode() []byte
- func (m *Metadata) GetBzzr0() string
- func (m *Metadata) GetBzzr1() string
- func (m *Metadata) GetCborLength() int16
- func (m *Metadata) GetCompilerVersion() string
- func (m *Metadata) GetExecutionBytecode() []byte
- func (m *Metadata) GetExperimental() bool
- func (m *Metadata) GetIPFS() string
- func (m *Metadata) GetUrls() []string
- func (m *Metadata) ToProto() *metadata_pb.BytecodeMetadata
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Argument ¶
type Argument struct {
Name string `json:"name"` // Name of the argument
Type string `json:"type"` // Type of the argument
Value string `json:"value"` // Value of the argument
Indexed bool `json:"indexed"` // Indicates if the argument is indexed
}
Argument represents a single argument in a contract constructor. It includes the argument's name, type, value, and whether it is indexed.
type Constructor ¶
type Constructor struct {
Abi string `json:"abi"` // ABI of the constructor
Parsed abi.ABI `json:"-"` // Parsed ABI of the constructor
SignatureRaw string `json:"signature_raw"` // Raw signature of the constructor
Arguments []Argument // List of arguments in the constructor
UnpackedArguments []interface{} `json:"unpacked_arguments"` // List of unpacked arguments in the constructor
}
Constructor represents a contract constructor. It includes the ABI of the constructor, the raw signature, and the arguments.
func DecodeConstructorFromAbi ¶
func DecodeConstructorFromAbi(bytecode []byte, constructorAbi string) (*Constructor, error)
DecodeConstructorFromAbi decodes the constructor from the provided ABI and bytecode. It returns a Constructor object and an error if any occurred during the decoding process.
The function first checks if the bytecode is empty or does not start with '['. If so, it prepends '[' to the constructorAbi. Then it attempts to parse the ABI using the abi.JSON function from the go-ethereum library. If the ABI parsing is successful, it unpacks the values from the bytecode using the UnpackValues function. It then checks if the number of unpacked values matches the number of inputs in the constructor. If they match, it creates an Argument object for each input and adds it to the arguments slice. Finally, it returns a Constructor object containing the ABI, raw signature, and arguments.
func (*Constructor) Pack ¶
func (c *Constructor) Pack() ([]byte, error)
Pack packs the arguments in the constructor into a byte slice for future use and verification.
type Metadata ¶
type Metadata struct {
Ipfs []byte `cbor:"ipfs"` // The IPFS hash of the metadata, if present
Bzzr1 []byte `cbor:"bzzr1"` // The Swarm hash of the metadata, if present (version 1)
Bzzr0 []byte `cbor:"bzzr0"` // The Swarm hash of the metadata, if present (version 0)
Experimental []byte `cbor:"experimental"` // Experimental metadata, if present
Solc []byte `cbor:"solc"` // The version of the Solidity compiler used
// contains filtered or unexported fields
}
Metadata represents the metadata contained in Ethereum contract creation bytecode. The structure and encoding of the metadata is defined by the Solidity compiler. More information can be found at https://docs.soliditylang.org/en/v0.8.20/metadata.html#encoding-of-the-metadata-hash-in-the-bytecode
func DecodeContractMetadata ¶
DecodeContractMetadata decodes the metadata from Ethereum contract creation bytecode. It returns a Metadata object and an error, if any occurred during decoding.
func (*Metadata) AuxFound ¶
AuxFound returns whether the CBOR metadata bytes are contained in the provided byte slice. This is used to verify if contract extracted cbor metadata can be found in the deployed/execution contract bytecode.
func (*Metadata) GetAuxBytecode ¶
GetAuxBytecode returns the raw CBOR metadata of the contract.
func (*Metadata) GetBzzr0 ¶
GetBzzr0 returns the Swarm (version 0) hash of the contract's metadata, if present.
func (*Metadata) GetBzzr1 ¶
GetBzzr1 returns the Swarm (version 1) hash of the contract's metadata, if present.
func (*Metadata) GetCborLength ¶
GetCborLength returns the length of the CBOR metadata.
func (*Metadata) GetCompilerVersion ¶
GetCompilerVersion returns the version of the Solidity compiler used to compile the contract.
func (*Metadata) GetExecutionBytecode ¶
GetExecutionBytecode returns the execution bytecode of the contract.
func (*Metadata) GetExperimental ¶
GetExperimental returns whether the contract includes experimental metadata.
func (*Metadata) ToProto ¶
func (m *Metadata) ToProto() *metadata_pb.BytecodeMetadata