nitfixes: to get over the finish line (#16)
* Remove broken gas metering attempt * Add newline to fix lint * hardcode return value of eth_estimateGas to gas limit * evm: fix log message * state manager: safer calling * rpc: leave comment to help future debugging Co-authored-by: Karl Floersch <karl@karlfloersch.com> Co-authored-by: Kevin Ho <kevinjho1996@gmail.com>
This commit is contained in:
parent
1efe552752
commit
47da34c139
@ -49,16 +49,12 @@ func run(evm *EVM, contract *Contract, input []byte, readOnly bool) ([]byte, err
|
|||||||
// Intercept the StateManager calls
|
// Intercept the StateManager calls
|
||||||
if contract.Address() == StateManagerAddress {
|
if contract.Address() == StateManagerAddress {
|
||||||
log.Debug("Calling State Manager contract.", "StateManagerAddress", hex.EncodeToString(StateManagerAddress.Bytes()))
|
log.Debug("Calling State Manager contract.", "StateManagerAddress", hex.EncodeToString(StateManagerAddress.Bytes()))
|
||||||
gas := stateManagerRequiredGas(input)
|
|
||||||
if contract.UseGas(gas) {
|
|
||||||
ret, err := callStateManager(input, evm, contract)
|
ret, err := callStateManager(input, evm, contract)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("State manager error!", "Error", err)
|
log.Error("State manager error!", "error", err)
|
||||||
}
|
}
|
||||||
return ret, err
|
return ret, err
|
||||||
}
|
}
|
||||||
return nil, ErrOutOfGas
|
|
||||||
}
|
|
||||||
|
|
||||||
if contract.CodeAddr != nil {
|
if contract.CodeAddr != nil {
|
||||||
precompiles := PrecompiledContractsHomestead
|
precompiles := PrecompiledContractsHomestead
|
||||||
|
@ -5,61 +5,30 @@ import (
|
|||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"errors"
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/common"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
"github.com/ethereum/go-ethereum/crypto"
|
"github.com/ethereum/go-ethereum/crypto"
|
||||||
"github.com/ethereum/go-ethereum/log"
|
"github.com/ethereum/go-ethereum/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
type stateManagerFunctionAndGasCost struct {
|
|
||||||
smFunction stateManagerFunction
|
|
||||||
smGasCost uint64
|
|
||||||
}
|
|
||||||
type stateManagerFunction func(*EVM, *Contract, []byte) ([]byte, error)
|
type stateManagerFunction func(*EVM, *Contract, []byte) ([]byte, error)
|
||||||
|
|
||||||
var funcs = map[string]stateManagerFunctionAndGasCost{
|
var funcs = map[string]stateManagerFunction{
|
||||||
"getStorage(address,bytes32)": {
|
"getStorage(address,bytes32)": getStorage,
|
||||||
smFunction: getStorage,
|
"setStorage(address,bytes32,bytes32)": setStorage,
|
||||||
smGasCost: 20000,
|
"getOvmContractNonce(address)": getOvmContractNonce,
|
||||||
},
|
"incrementOvmContractNonce(address)": incrementOvmContractNonce,
|
||||||
"setStorage(address,bytes32,bytes32)": {
|
"getCodeContractBytecode(address)": getCodeContractBytecode,
|
||||||
smFunction: setStorage,
|
"getCodeContractHash(address)": getCodeContractHash,
|
||||||
smGasCost: 20000,
|
"getCodeContractAddressFromOvmAddress(address)": getCodeContractAddress,
|
||||||
},
|
"associateCodeContract(address,address)": associateCodeContract,
|
||||||
"getOvmContractNonce(address)": {
|
"registerCreatedContract(address)": registerCreatedContract,
|
||||||
smFunction: getOvmContractNonce,
|
|
||||||
smGasCost: 20000,
|
|
||||||
},
|
|
||||||
"incrementOvmContractNonce(address)": {
|
|
||||||
smFunction: incrementOvmContractNonce,
|
|
||||||
smGasCost: 20000,
|
|
||||||
},
|
|
||||||
"getCodeContractBytecode(address)": {
|
|
||||||
smFunction: getCodeContractBytecode,
|
|
||||||
smGasCost: 20000,
|
|
||||||
},
|
|
||||||
"getCodeContractHash(address)": {
|
|
||||||
smFunction: getCodeContractHash,
|
|
||||||
smGasCost: 20000,
|
|
||||||
},
|
|
||||||
"getCodeContractAddressFromOvmAddress(address)": {
|
|
||||||
smFunction: getCodeContractAddress,
|
|
||||||
smGasCost: 20000,
|
|
||||||
},
|
|
||||||
"associateCodeContract(address,address)": {
|
|
||||||
smFunction: associateCodeContract,
|
|
||||||
smGasCost: 20000,
|
|
||||||
},
|
|
||||||
"registerCreatedContract(address)": {
|
|
||||||
smFunction: registerCreatedContract,
|
|
||||||
smGasCost: 20000,
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
var methodIds map[[4]byte]stateManagerFunction
|
||||||
var methodIds map[[4]byte]stateManagerFunctionAndGasCost
|
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
methodIds = make(map[[4]byte]stateManagerFunctionAndGasCost, len(funcs))
|
methodIds = make(map[[4]byte]stateManagerFunction, len(funcs))
|
||||||
for methodSignature, f := range funcs {
|
for methodSignature, f := range funcs {
|
||||||
methodIds[methodSignatureToMethodID(methodSignature)] = f
|
methodIds[methodSignatureToMethodID(methodSignature)] = f
|
||||||
}
|
}
|
||||||
@ -71,23 +40,20 @@ func methodSignatureToMethodID(methodSignature string) [4]byte {
|
|||||||
return methodID
|
return methodID
|
||||||
}
|
}
|
||||||
|
|
||||||
func stateManagerRequiredGas(input []byte) (gas uint64) {
|
|
||||||
var methodID [4]byte
|
|
||||||
copy(methodID[:], input[:4])
|
|
||||||
gas = methodIds[methodID].smGasCost
|
|
||||||
return gas
|
|
||||||
}
|
|
||||||
|
|
||||||
func callStateManager(input []byte, evm *EVM, contract *Contract) (ret []byte, err error) {
|
func callStateManager(input []byte, evm *EVM, contract *Contract) (ret []byte, err error) {
|
||||||
var methodID [4]byte
|
var methodID [4]byte
|
||||||
|
if len(input) == 0 {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
copy(methodID[:], input[:4])
|
copy(methodID[:], input[:4])
|
||||||
ret, err = methodIds[methodID].smFunction(evm, contract, input)
|
|
||||||
return ret, err
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
if method, ok := methodIds[methodID]; ok {
|
||||||
* StateManager functions
|
return method(evm, contract, input)
|
||||||
*/
|
}
|
||||||
|
|
||||||
|
ret, err = methodIds[methodID](evm, contract, input)
|
||||||
|
return nil, fmt.Errorf("state manager call not found: %s", methodID)
|
||||||
|
}
|
||||||
|
|
||||||
func setStorage(evm *EVM, contract *Contract, input []byte) (ret []byte, err error) {
|
func setStorage(evm *EVM, contract *Contract, input []byte) (ret []byte, err error) {
|
||||||
address := common.BytesToAddress(input[4:36])
|
address := common.BytesToAddress(input[4:36])
|
||||||
|
@ -366,7 +366,14 @@ func (h *handler) handleSubscribe(cp *callProc, msg *jsonrpcMessage) *jsonrpcMes
|
|||||||
|
|
||||||
// runMethod runs the Go callback for an RPC method.
|
// runMethod runs the Go callback for an RPC method.
|
||||||
func (h *handler) runMethod(ctx context.Context, msg *jsonrpcMessage, callb *callback, args []reflect.Value) *jsonrpcMessage {
|
func (h *handler) runMethod(ctx context.Context, msg *jsonrpcMessage, callb *callback, args []reflect.Value) *jsonrpcMessage {
|
||||||
result, err := callb.call(ctx, msg.Method, args)
|
var result interface{}
|
||||||
|
var err error
|
||||||
|
// TODO: think about long term maintainability of altered RPC methods
|
||||||
|
if msg.Method == "eth_estimateGas" {
|
||||||
|
result = 0xffffffff //Gas Limit
|
||||||
|
} else {
|
||||||
|
result, err = callb.call(ctx, msg.Method, args)
|
||||||
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return msg.errorResponse(err)
|
return msg.errorResponse(err)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user