Documentation
¶
Overview ¶
Package validation provides utilities for verifying Ethereum based smart contracts.
Index ¶
- type Verifier
- func (v *Verifier) Compile(ctx context.Context, config *solc.CompilerConfig) (*solc.CompilerResults, error)
- func (v *Verifier) GetCompiler() *solc.Solc
- func (v *Verifier) GetContext() context.Context
- func (v *Verifier) GetSources() *solgo.Sources
- func (v *Verifier) Verify(ctx context.Context, bytecode []byte, config *solc.CompilerConfig) (*VerifyResult, error)
- func (v *Verifier) VerifyFromResults(bytecode []byte, results *solc.CompilerResults) (*VerifyResult, error)
- type VerifyResult
- func (vr *VerifyResult) GetCompilerResult() *solc.CompilerResult
- func (vr *VerifyResult) GetDiffPretty() string
- func (vr *VerifyResult) GetDiffs() []diffmatchpatch.Diff
- func (vr *VerifyResult) GetExpectedBytecode() string
- func (vr *VerifyResult) GetLevenshteinDistance() int
- func (vr *VerifyResult) IsVerified() bool
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Verifier ¶
type Verifier struct {
// contains filtered or unexported fields
}
Verifier is a utility that facilitates the verification of Ethereum smart contracts. It uses the solc compiler to compile the provided sources and then verifies the bytecode.
func NewVerifier ¶
func NewVerifier(ctx context.Context, compiler *solc.Solc, sources *solgo.Sources) (*Verifier, error)
NewVerifier creates a new instance of Verifier. It initializes the solc compiler with the provided configuration and sources. If the sources are not prepared, it prepares them before initializing the compiler. Returns an error if there's any issue in preparing the sources or initializing the compiler.
func (*Verifier) GetCompiler ¶
func (v *Verifier) GetCompiler() *solc.Solc
GetCompiler returns the solc compiler instance associated with the verifier.
func (*Verifier) GetContext ¶
GetContext returns the context associated with the verifier.
func (*Verifier) GetSources ¶
GetSources returns the sources of the Ethereum smart contracts associated with the verifier.
func (*Verifier) Verify ¶
func (v *Verifier) Verify(ctx context.Context, bytecode []byte, config *solc.CompilerConfig) (*VerifyResult, error)
Verify compiles the sources using the solc compiler and then verifies the bytecode. If the bytecode does not match the compiled result, it returns a diff of the two. Returns true if the bytecode matches, otherwise returns false. Also returns an error if there's any issue in the compilation or verification process.
func (*Verifier) VerifyFromResults ¶
func (v *Verifier) VerifyFromResults(bytecode []byte, results *solc.CompilerResults) (*VerifyResult, error)
VerifyFromResults compiles the sources using the solc compiler and then verifies the bytecode. If the bytecode does not match the compiled result, it returns a diff of the two. Returns true if the bytecode matches, otherwise returns false. Also returns an error if there's any issue in the compilation or verification process.
type VerifyResult ¶
type VerifyResult struct { Verified bool `json:"verified"` // Whether the verification was successful or not. CompilerResult *solc.CompilerResult `json:"compiler_results"` // The results from the solc compiler. ExpectedBytecode string `json:"expected_bytecode"` // The expected bytecode. Diffs []diffmatchpatch.Diff `json:"diffs"` // The diffs between the provided bytecode and the compiled bytecode. DiffPretty string `json:"diffs_pretty"` // The pretty printed diff between the provided bytecode and the compiled bytecode. LevenshteinDistance int `json:"levenshtein_distance"` // The levenshtein distance between the provided bytecode and the compiled bytecode. }
VerifyResult represents the result of the verification process.
func (*VerifyResult) GetCompilerResult ¶
func (vr *VerifyResult) GetCompilerResult() *solc.CompilerResult
GetCompilerResults returns the results from the solc compiler.
func (*VerifyResult) GetDiffPretty ¶
func (vr *VerifyResult) GetDiffPretty() string
GetDiffPretty returns the pretty printed diff between the provided bytecode and the compiled bytecode.
func (*VerifyResult) GetDiffs ¶
func (vr *VerifyResult) GetDiffs() []diffmatchpatch.Diff
GetDiffs returns the diffs between the provided bytecode and the compiled bytecode.
func (*VerifyResult) GetExpectedBytecode ¶
func (vr *VerifyResult) GetExpectedBytecode() string
GetExpectedBytecode returns the expected bytecode.
func (*VerifyResult) GetLevenshteinDistance ¶
func (vr *VerifyResult) GetLevenshteinDistance() int
GetLevenshteinDistance returns the levenshtein distance between the provided bytecode and the compiled bytecode.
func (*VerifyResult) IsVerified ¶
func (vr *VerifyResult) IsVerified() bool
IsVerified returns whether the verification was successful or not.