foundry

package
v1.10.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 19, 2024 License: MIT Imports: 20 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrLinkingUnsupported = errors.New("cannot load bytecode with linking placeholders")

Functions

This section is empty.

Types

type Artifact

type Artifact struct {
	ABI abi.ABI

	StorageLayout    solc.StorageLayout
	DeployedBytecode DeployedBytecode
	Bytecode         Bytecode
	Metadata         Metadata
	// contains filtered or unexported fields
}

Artifact represents a foundry compilation artifact. JSON marshaling logic is implemented to maintain the ability to roundtrip serialize an artifact

func ReadArtifact

func ReadArtifact(path string) (*Artifact, error)

ReadArtifact will read an artifact from disk given a path.

func (Artifact) MarshalJSON

func (a Artifact) MarshalJSON() ([]byte, error)

func (*Artifact) UnmarshalJSON

func (a *Artifact) UnmarshalJSON(data []byte) error

type ArtifactsFS added in v1.9.1

type ArtifactsFS struct {
	FS StatDirFs
}

ArtifactsFS wraps a filesystem (read-only access) of a forge-artifacts bundle. The root contains directories for every artifact, each containing one or more entries (one per solidity compiler version) for a solidity contract. See OpenArtifactsDir for reading from a local directory. Alternative FS systems, like a tarball, may be used too.

func OpenArtifactsDir added in v1.9.1

func OpenArtifactsDir(dirPath string) *ArtifactsFS

func (*ArtifactsFS) ListArtifacts added in v1.9.1

func (af *ArtifactsFS) ListArtifacts() ([]string, error)

ListArtifacts lists the artifacts. Each artifact matches a source-file name. This name includes the extension, e.g. ".sol" (no other artifact-types are supported at this time).

func (*ArtifactsFS) ListContracts added in v1.9.1

func (af *ArtifactsFS) ListContracts(name string) ([]string, error)

ListContracts lists the contracts of the named artifact, including the file extension. E.g. "Owned.sol" might list "Owned.0.8.15", "Owned.0.8.25", and "Owned".

func (*ArtifactsFS) ReadArtifact added in v1.9.1

func (af *ArtifactsFS) ReadArtifact(name string, contract string) (*Artifact, error)

ReadArtifact reads a specific JSON contract artifact from the FS. The contract name may be suffixed by a solidity compiler version, e.g. "Owned.0.8.25". The contract name does not include ".json", this is a detail internal to the artifacts. The name of the artifact is the source-file name, this must include the suffix such as ".sol".

type Bytecode

type Bytecode struct {
	SourceMap string `json:"sourceMap"`
	// not purely hex, can contain __$aaaaaaa$__ style linking placeholders
	Object              LinkableBytecode `json:"object"`
	LinkReferences      json.RawMessage  `json:"linkReferences"`
	ImmutableReferences json.RawMessage  `json:"immutableReferences,omitempty"`
}

Bytecode represents the bytecode section of the solc compiler output.

type ContractSource added in v1.9.1

type ContractSource struct {
	Keccak256 common.Hash `json:"keccak256"`
	URLs      []string    `json:"urls"`
	License   string      `json:"license"`
}

ContractSource represents a JSON value in the "sources" map of a contract metadata dump. This uniquely identifies the source code of the contract.

type DeployedBytecode

type DeployedBytecode struct {
	SourceMap           string           `json:"sourceMap"`
	Object              LinkableBytecode `json:"object"`
	LinkReferences      json.RawMessage  `json:"linkReferences"`
	ImmutableReferences json.RawMessage  `json:"immutableReferences,omitempty"`
}

DeployedBytecode represents the deployed bytecode section of the solc compiler output.

type ForgeAllocs added in v1.8.0

type ForgeAllocs struct {
	Accounts types.GenesisAlloc
}

func LoadForgeAllocs added in v1.8.0

func LoadForgeAllocs(allocsPath string) (*ForgeAllocs, error)

func (*ForgeAllocs) Copy added in v1.8.0

func (d *ForgeAllocs) Copy() *ForgeAllocs

func (*ForgeAllocs) FromState added in v1.9.1

func (f *ForgeAllocs) FromState(stateDB StateDB)

FromState takes a geth StateDB, and dumps the accounts into the ForgeAllocs. Any previous allocs contents are removed. Warning: the state must be committed first, trie-key preimages must be present for iteration, and a fresh state around the committed state-root must be presented, for the latest state-contents to be dumped.

func (ForgeAllocs) MarshalJSON added in v1.9.3

func (d ForgeAllocs) MarshalJSON() ([]byte, error)

func (*ForgeAllocs) UnmarshalJSON added in v1.8.0

func (d *ForgeAllocs) UnmarshalJSON(b []byte) error

type ForgeBuild added in v1.9.1

type ForgeBuild struct {
	ID             string                     `json:"id"`                // ID of the build itself
	SourceIDToPath map[srcmap.SourceID]string `json:"source_id_to_path"` // srcmap ID to source filepath
}

ForgeBuild represents the JSON content of a forge-build entry in the `artifacts/build-info` output.

type ForgeBuildCache added in v1.9.1

type ForgeBuildCache struct {
	Paths struct {
		BuildInfos string `json:"build_infos"`
	} `json:"paths"`
	Files map[string]ForgeBuildInfo `json:"files"`
}

ForgeBuildCache rep

type ForgeBuildEntry added in v1.9.1

type ForgeBuildEntry struct {
	Path    string `json:"path"`
	BuildID string `json:"build_id"`
}

ForgeBuildEntry represents a JSON entry that links the build job of a contract source file.

type ForgeBuildInfo added in v1.9.1

type ForgeBuildInfo struct {
	// contract name -> solidity version -> build entry
	Artifacts map[string]map[string]ForgeBuildEntry `json:"artifacts"`
}

ForgeBuildInfo represents a JSON entry that enumerates the latest builds per contract per compiler version.

type LinkableBytecode added in v1.9.1

type LinkableBytecode []byte

LinkableBytecode is not purely hex, it returns an ErrLinkingUnsupported error when input contains __$aaaaaaa$__ style linking placeholders. See https://docs.soliditylang.org/en/latest/using-the-compiler.html#library-linking In practice this is only used by test contracts to link in large test libraries.

func (LinkableBytecode) MarshalText added in v1.9.1

func (lb LinkableBytecode) MarshalText() ([]byte, error)

func (*LinkableBytecode) UnmarshalJSON added in v1.9.1

func (lb *LinkableBytecode) UnmarshalJSON(data []byte) error

type Metadata added in v1.9.1

type Metadata struct {
	Compiler struct {
		Version string `json:"version"`
	} `json:"compiler"`

	Language string `json:"language"`

	Output json.RawMessage `json:"output"`

	Settings struct {
		// Remappings of the contract imports
		Remappings json.RawMessage `json:"remappings"`
		// Optimizer settings affect the compiler output, but can be arbitrary.
		// We load them opaquely, to include it in the hash of what we run.
		Optimizer json.RawMessage `json:"optimizer"`
		// Metadata is loaded opaquely, similar to the Optimizer, to include in hashing.
		// E.g. the bytecode-hash contract suffix as setting is enabled/disabled in here.
		Metadata json.RawMessage `json:"metadata"`
		// Map of full contract path to compiled contract name.
		CompilationTarget map[string]string `json:"compilationTarget"`
		// EVM version affects output, and hence included.
		EVMVersion string `json:"evmVersion"`
		// Libraries data
		Libraries json.RawMessage `json:"libraries"`
	} `json:"settings"`

	Sources map[string]ContractSource `json:"sources"`

	Version int `json:"version"`
}

Metadata is the subset of metadata in a foundry contract artifact that we use in OP-Stack tooling.

type SourceMapFS added in v1.9.1

type SourceMapFS struct {
	// contains filtered or unexported fields
}

SourceMapFS wraps an FS to provide source-maps. This FS relies on the following file path assumptions: - `/artifacts/build-info/X.json` (build-info path is read from the below file): build files, of foundry incremental builds. - `/cache/solidity-files-cache.json`: a JSON file enumerating all files, and when the build last changed. - `/` a root dir, relative to where the source files are located (as per the compilationTarget metadata in an artifact).

func NewSourceMapFS added in v1.9.1

func NewSourceMapFS(fs fs.FS) *SourceMapFS

NewSourceMapFS creates a new SourceMapFS. The source-map FS loads identifiers for srcmap.ParseSourceMap and provides a util to retrieve a source-map for an Artifact. The solidity source-files are lazy-loaded when using the produced sourcemap.

func (*SourceMapFS) ReadSourceIDs added in v1.9.1

func (s *SourceMapFS) ReadSourceIDs(path string, contract string, compilerVersion string) (map[srcmap.SourceID]string, error)

ReadSourceIDs reads the source-identifier to source file-path mapping that is needed to translate a source-map of the given contract, the given compiler version, and within the given source file path.

func (*SourceMapFS) SourceMap added in v1.9.1

func (s *SourceMapFS) SourceMap(artifact *Artifact, contract string) (*srcmap.SourceMap, error)

SourceMap retrieves a source-map for a given contract of a foundry Artifact.

type StatDirFs added in v1.9.3

type StatDirFs interface {
	fs.StatFS
	fs.ReadDirFS
}

type StateDB added in v1.9.1

type StateDB interface {
	DumpToCollector(c state.DumpCollector, conf *state.DumpConfig) (nextKey []byte)
}

StateDB is a minimal interface to support dumping of Geth EVM state to ForgeAllocs.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL