validation

package
v0.3.4 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2024 License: Apache-2.0 Imports: 10 Imported by: 1

Documentation

Overview

Package validation provides utilities for verifying Ethereum based smart contracts.

Index

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) Compile

func (v *Verifier) Compile(ctx context.Context, config *solc.CompilerConfig) (*solc.CompilerResults, error)

func (*Verifier) GetCompiler

func (v *Verifier) GetCompiler() *solc.Solc

GetCompiler returns the solc compiler instance associated with the verifier.

func (*Verifier) GetContext

func (v *Verifier) GetContext() context.Context

GetContext returns the context associated with the verifier.

func (*Verifier) GetSources

func (v *Verifier) GetSources() *solgo.Sources

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.

Jump to

Keyboard shortcuts

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