Skip to content

Commit 47da34c

Browse files
tyneskarlfloerschK-Ho
authored
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 <[email protected]> Co-authored-by: Kevin Ho <[email protected]>
1 parent 1efe552 commit 47da34c

File tree

3 files changed

+35
-66
lines changed

3 files changed

+35
-66
lines changed

core/vm/evm.go

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,11 @@ func run(evm *EVM, contract *Contract, input []byte, readOnly bool) ([]byte, err
4949
// Intercept the StateManager calls
5050
if contract.Address() == StateManagerAddress {
5151
log.Debug("Calling State Manager contract.", "StateManagerAddress", hex.EncodeToString(StateManagerAddress.Bytes()))
52-
gas := stateManagerRequiredGas(input)
53-
if contract.UseGas(gas) {
54-
ret, err := callStateManager(input, evm, contract)
55-
if err != nil {
56-
log.Error("State manager error!", "Error", err)
57-
}
58-
return ret, err
52+
ret, err := callStateManager(input, evm, contract)
53+
if err != nil {
54+
log.Error("State manager error!", "error", err)
5955
}
60-
return nil, ErrOutOfGas
56+
return ret, err
6157
}
6258

6359
if contract.CodeAddr != nil {

core/vm/state_manager.go

Lines changed: 23 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -5,61 +5,30 @@ import (
55
"encoding/binary"
66
"encoding/hex"
77
"errors"
8+
"fmt"
89

910
"github.com/ethereum/go-ethereum/common"
1011
"github.com/ethereum/go-ethereum/crypto"
1112
"github.com/ethereum/go-ethereum/log"
1213
)
1314

14-
type stateManagerFunctionAndGasCost struct {
15-
smFunction stateManagerFunction
16-
smGasCost uint64
17-
}
1815
type stateManagerFunction func(*EVM, *Contract, []byte) ([]byte, error)
1916

20-
var funcs = map[string]stateManagerFunctionAndGasCost{
21-
"getStorage(address,bytes32)": {
22-
smFunction: getStorage,
23-
smGasCost: 20000,
24-
},
25-
"setStorage(address,bytes32,bytes32)": {
26-
smFunction: setStorage,
27-
smGasCost: 20000,
28-
},
29-
"getOvmContractNonce(address)": {
30-
smFunction: getOvmContractNonce,
31-
smGasCost: 20000,
32-
},
33-
"incrementOvmContractNonce(address)": {
34-
smFunction: incrementOvmContractNonce,
35-
smGasCost: 20000,
36-
},
37-
"getCodeContractBytecode(address)": {
38-
smFunction: getCodeContractBytecode,
39-
smGasCost: 20000,
40-
},
41-
"getCodeContractHash(address)": {
42-
smFunction: getCodeContractHash,
43-
smGasCost: 20000,
44-
},
45-
"getCodeContractAddressFromOvmAddress(address)": {
46-
smFunction: getCodeContractAddress,
47-
smGasCost: 20000,
48-
},
49-
"associateCodeContract(address,address)": {
50-
smFunction: associateCodeContract,
51-
smGasCost: 20000,
52-
},
53-
"registerCreatedContract(address)": {
54-
smFunction: registerCreatedContract,
55-
smGasCost: 20000,
56-
},
17+
var funcs = map[string]stateManagerFunction{
18+
"getStorage(address,bytes32)": getStorage,
19+
"setStorage(address,bytes32,bytes32)": setStorage,
20+
"getOvmContractNonce(address)": getOvmContractNonce,
21+
"incrementOvmContractNonce(address)": incrementOvmContractNonce,
22+
"getCodeContractBytecode(address)": getCodeContractBytecode,
23+
"getCodeContractHash(address)": getCodeContractHash,
24+
"getCodeContractAddressFromOvmAddress(address)": getCodeContractAddress,
25+
"associateCodeContract(address,address)": associateCodeContract,
26+
"registerCreatedContract(address)": registerCreatedContract,
5727
}
58-
59-
var methodIds map[[4]byte]stateManagerFunctionAndGasCost
28+
var methodIds map[[4]byte]stateManagerFunction
6029

6130
func init() {
62-
methodIds = make(map[[4]byte]stateManagerFunctionAndGasCost, len(funcs))
31+
methodIds = make(map[[4]byte]stateManagerFunction, len(funcs))
6332
for methodSignature, f := range funcs {
6433
methodIds[methodSignatureToMethodID(methodSignature)] = f
6534
}
@@ -71,23 +40,20 @@ func methodSignatureToMethodID(methodSignature string) [4]byte {
7140
return methodID
7241
}
7342

74-
func stateManagerRequiredGas(input []byte) (gas uint64) {
75-
var methodID [4]byte
76-
copy(methodID[:], input[:4])
77-
gas = methodIds[methodID].smGasCost
78-
return gas
79-
}
80-
8143
func callStateManager(input []byte, evm *EVM, contract *Contract) (ret []byte, err error) {
8244
var methodID [4]byte
45+
if len(input) == 0 {
46+
return nil, nil
47+
}
8348
copy(methodID[:], input[:4])
84-
ret, err = methodIds[methodID].smFunction(evm, contract, input)
85-
return ret, err
86-
}
8749

88-
/*
89-
* StateManager functions
90-
*/
50+
if method, ok := methodIds[methodID]; ok {
51+
return method(evm, contract, input)
52+
}
53+
54+
ret, err = methodIds[methodID](evm, contract, input)
55+
return nil, fmt.Errorf("state manager call not found: %s", methodID)
56+
}
9157

9258
func setStorage(evm *EVM, contract *Contract, input []byte) (ret []byte, err error) {
9359
address := common.BytesToAddress(input[4:36])

rpc/handler.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,14 @@ func (h *handler) handleSubscribe(cp *callProc, msg *jsonrpcMessage) *jsonrpcMes
366366

367367
// runMethod runs the Go callback for an RPC method.
368368
func (h *handler) runMethod(ctx context.Context, msg *jsonrpcMessage, callb *callback, args []reflect.Value) *jsonrpcMessage {
369-
result, err := callb.call(ctx, msg.Method, args)
369+
var result interface{}
370+
var err error
371+
// TODO: think about long term maintainability of altered RPC methods
372+
if msg.Method == "eth_estimateGas" {
373+
result = 0xffffffff //Gas Limit
374+
} else {
375+
result, err = callb.call(ctx, msg.Method, args)
376+
}
370377
if err != nil {
371378
return msg.errorResponse(err)
372379
}

0 commit comments

Comments
 (0)