-
Notifications
You must be signed in to change notification settings - Fork 222
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #21 from ava-labs/stateful-precompiles
[AV-1297] Add framework for stateful precompiles
- Loading branch information
Showing
4 changed files
with
83 additions
and
52 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
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,33 @@ | ||
// (c) 2019-2020, Ava Labs, Inc. All rights reserved. | ||
// See the file LICENSE for licensing terms. | ||
|
||
package vm | ||
|
||
import ( | ||
"github.com/ethereum/go-ethereum/common" | ||
) | ||
|
||
// StatefulPrecompiledContract is the interface for executing a precompiled contract | ||
// This wraps the PrecompiledContracts native to Ethereum and allows adding in stateful | ||
// precompiled contracts to support native Avalanche asset transfers. | ||
type StatefulPrecompiledContract interface { | ||
// Run executes a precompiled contract in the current state | ||
// assumes that it has already been verified that [caller] can | ||
// transfer [value]. | ||
Run(evm *EVM, caller ContractRef, addr common.Address, input []byte, suppliedGas uint64, readOnly bool) (ret []byte, remainingGas uint64, err error) | ||
} | ||
|
||
// wrappedPrecompiledContract implements StatefulPrecompiledContract by wrapping stateless native precompiled contracts | ||
// in Ethereum. | ||
type wrappedPrecompiledContract struct { | ||
p PrecompiledContract | ||
} | ||
|
||
func newWrappedPrecompiledContract(p PrecompiledContract) StatefulPrecompiledContract { | ||
return &wrappedPrecompiledContract{p: p} | ||
} | ||
|
||
// Run implements the StatefulPrecompiledContract interface | ||
func (w *wrappedPrecompiledContract) Run(evm *EVM, caller ContractRef, addr common.Address, input []byte, suppliedGas uint64, readOnly bool) (ret []byte, remainingGas uint64, err error) { | ||
return RunPrecompiledContract(w.p, input, suppliedGas) | ||
} |
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