-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat!: use full EVM execution stack and simplify interception of byte…
…code, config, `StateDB`, etc. (#35) * feat!: use `core.ApplyMessage()` and full `state.StateDB` for `Run()` (messy!) * doc: comment all `runopts.Captured` functionality (and move it to a separate file) * refactor: default `Code.Run()` to error on revert "Make it hard to misuse an API". The majority of tests were using `runopts.ErrorOnRevert()` and one even forgot it, so the option is inverted to `NoErrorOnRevert()`. * doc: comment all `runopts.Option`s * chore: nolint errcheck for reading from Keccak state * doc: default `Contract.Address` and guarantees/reqs about `vm.StateDB` * doc: README updates * fix: add contract address to `StateDB` access list * test: `ExampleCaptured` also demonstrates testing `SSTORE`
- Loading branch information
Showing
18 changed files
with
709 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
load("@rules_go//go:def.bzl", "go_library") | ||
|
||
go_library( | ||
name = "revert", | ||
srcs = ["revert.go"], | ||
importpath = "github.com/solidifylabs/specops/revert", | ||
visibility = ["//visibility:public"], | ||
deps = ["@com_github_ethereum_go_ethereum//core"], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// Package revert provides errors and error handling for EVM smart contracts | ||
// that revert. | ||
package revert | ||
|
||
import ( | ||
"errors" | ||
|
||
"github.com/ethereum/go-ethereum/core" | ||
) | ||
|
||
// An Error is an error signalling that code reverted. | ||
type Error struct { | ||
Data []byte // [core.ExecutionResult.Revert()] | ||
Err error // [core.ExecutionResult.Err] | ||
} | ||
|
||
// Data returns the revert data from the error if it is an [Error]. The returned | ||
// boolean indicates whether the possibly zero-length data was found; similar to | ||
// the second return value from a map. | ||
func Data(err error) (_ []byte, ok bool) { | ||
e := new(Error) | ||
if !errors.As(err, &e) { | ||
return nil, false | ||
} | ||
return e.Data, true | ||
} | ||
|
||
// ErrFrom converts a [core.ExecutionResult] into an error, or nil if the | ||
// execution completely successfully. The returned error is non-nil i.f.f. | ||
// r.Failed() is true. | ||
func ErrFrom(r *core.ExecutionResult) error { | ||
if !r.Failed() { | ||
return nil | ||
} | ||
return &Error{ | ||
Data: r.Revert(), | ||
Err: r.Err, | ||
} | ||
} | ||
|
||
var _ error = (*Error)(nil) | ||
|
||
// Error returns the error string from the [core.ExecutionResult.Err]. | ||
func (e *Error) Error() string { | ||
return e.Err.Error() | ||
} | ||
|
||
// Unwrap returns the wrapped [core.ExecutionResult.Err] value. | ||
func (e *Error) Unwrap() error { | ||
return e.Err | ||
} |
Oops, something went wrong.