10000 imp(core/vm): custom opcodes definition (backport #2837) by mergify[bot] · Pull Request #2844 · evmos/evmos · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

imp(core/vm): custom opcodes definition (backport #2837) #2844

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ Ref: https://keepachangelog.com/en/1.0.0/

### Improvements

- (evm) [#2837](https://github.com/evmos/evmos/pull/2837) Update `Interpreter` interface and public functions to support custom Opcodes.
- (inflation) [#2813](https://github.com/evmos/evmos/pull/2813) Fix communityPool is nil.
- (evm) [#2683](https://github.com/evmos/evmos/pull/2683) Remove duplicate definitions of precompile addresses.
- (evm) [#2709](https://github.com/evmos/evmos/pull/2709) Minor improvements in precompiles related code.
Expand Down Expand Up @@ -1087,5 +1088,3 @@ Ref: https://keepachangelog.com/en/1.0.0/

- (cli) [#26](https://github.com/evmos/evmos/pull/26) Use config on genesis accounts.
- (deps) [#28](https://github.com/evmos/evmos/pull/28) Bump Ethermint version to `v0.7.0`.


6 changes: 6 additions & 0 deletions x/evm/core/vm/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ import (
"github.com/holiman/uint256"
)

// CalcMemSize64 calculates the required memory size, and returns
// the size and whether the result overflowed uint64
func CalcMemSize64(off, l *uint256.Int) (uint64, bool) {
return calcMemSize64(off, l)
}

// calcMemSize64 calculates the required memory size, and returns
// the size and whether the result overflowed uint64
func calcMemSize64(off, l *uint256.Int) (uint64, bool) {
Expand Down
10 changes: 10 additions & 0 deletions x/evm/core/vm/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,16 @@ type CallContext interface {
// The Interpreter will run the byte code VM based on the passed
// configuration.
type Interpreter interface {
// EVM returns the EVM instance
EVM() *EVM
// Config returns the configuration of the interpreter
Config() Config
// ReadOnly returns whether the interpreter is in read-only mode
ReadOnly() bool
// ReturnData gets the last CALL's return data for subsequent reuse
ReturnData() []byte
// SetReturnData sets the last CALL's return data
SetReturnData([]byte)
// Run loops and evaluates the contract's code with the given input data and returns
// the return byte-slice and an error if one occurred.
Run(contract *Contract, input []byte, static bool) ([]byte, error)
Expand Down
25 changes: 25 additions & 0 deletions x/evm/core/vm/interpreter.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,31 @@ func NewEVMInterpreter(evm *EVM, cfg Config) *EVMInterpreter {
}
}

// EVM returns the EVM instance
func (in *EVMInterpreter) EVM() *EVM {
return in.evm
}

// Config returns the configuration of the interpreter
func (in EVMInterpreter) Config() Config {
return in.cfg
}

// ReadOnly returns whether the interpreter is in read-only mode
func (in EVMInterpreter) ReadOnly() bool {
return in.readOnly
}

// ReturnData gets the last CALL's return data for subsequent reuse
func (in *EVMInterpreter) ReturnData() []byte {
return in.returnData
}

// SetReturnData sets the last CALL's return data
func (in *EVMInterpreter) SetReturnData(data []byte) {
in.returnData = data
}

// Run loops and evaluates the contract's code with the given input data and returns
// the return byte-slice and an error if one occurred.
//
Expand Down
6 changes: 6 additions & 0 deletions x/evm/core/vm/memory.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,9 @@ func (m *Memory) Len() int {
func (m *Memory) Data() []byte {
return m.store
}

// GasCost calculates the quadratic gas for memory expansion. It does so
// only for the memory region that is expanded, not the total memory.
func (m *Memory) GasCost(newMemSize uint64) (uint64, error) {
return memoryGasCost(m, newMemSize)
}
Loading
0