aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMeng-Ying Yang <garfield@dexon.org>2019-04-18 14:58:57 +0800
committerJhih-Ming Huang <jm.huang@cobinhood.com>2019-05-06 10:44:05 +0800
commitab89e16a223a4e8d1a67b01fae163dd647cc28cc (patch)
tree053c159d99c530d5d0e3a225cfd611f009b97f16
parent3089040675fd0bccf2f2ef6f0a14d33a362ba27b (diff)
downloaddexon-ab89e16a223a4e8d1a67b01fae163dd647cc28cc.tar.gz
dexon-ab89e16a223a4e8d1a67b01fae163dd647cc28cc.tar.zst
dexon-ab89e16a223a4e8d1a67b01fae163dd647cc28cc.zip
core: vm: sqlvm: change function id from bytes to uint16
-rw-r--r--core/vm/sqlvm/runtime/functions.go22
-rw-r--r--core/vm/sqlvm/runtime/instructions.go25
2 files changed, 26 insertions, 21 deletions
diff --git a/core/vm/sqlvm/runtime/functions.go b/core/vm/sqlvm/runtime/functions.go
index d9c0f94f4..7aed05b19 100644
--- a/core/vm/sqlvm/runtime/functions.go
+++ b/core/vm/sqlvm/runtime/functions.go
@@ -16,22 +16,22 @@ import (
// function identifier
const (
- BLOCKHASH = "BLOCK_HASH"
- BLOCKNUMBER = "BLOCK_NUMBER"
- BLOCKTIMESTAMP = "BLOCK_TIMESTAMP"
- BLOCKCOINBASE = "BLOCK_COINBASE"
- BLOCKGASLIMIT = "BLOCK_GAS_LIMIT"
- MSGSENDER = "MSG_SENDER"
- MSGDATA = "MSG_DATA"
- TXORIGIN = "TX_ORIGIN"
- NOW = "NOW"
- RAND = "RAND"
+ BLOCKHASH uint16 = iota
+ BLOCKNUMBER
+ BLOCKTIMESTAMP
+ BLOCKCOINBASE
+ BLOCKGASLIMIT
+ MSGSENDER
+ MSGDATA
+ TXORIGIN
+ NOW
+ RAND
)
type fn func(*common.Context, []*Operand, uint64) (*Operand, error)
var (
- fnTable = map[string]fn{
+ fnTable = []fn{
BLOCKHASH: fnBlockHash,
BLOCKNUMBER: fnBlockNumber,
BLOCKTIMESTAMP: fnBlockTimestamp,
diff --git a/core/vm/sqlvm/runtime/instructions.go b/core/vm/sqlvm/runtime/instructions.go
index 013c700f8..8c303c160 100644
--- a/core/vm/sqlvm/runtime/instructions.go
+++ b/core/vm/sqlvm/runtime/instructions.go
@@ -1849,23 +1849,28 @@ func opFunc(ctx *common.Context, ops, registers []*Operand, output uint) (err er
}
var (
- op, funcID = ops[0], ops[1]
- op2 *Operand
- length uint64
+ opLength, opFuncID = ops[0], ops[1]
+ result *Operand
+ length uint64
)
- if op.IsImmediate {
- length, err = ast.DecimalToUint64(op.Data[0][0].Value)
+ if opLength.IsImmediate {
+ length, err = ast.DecimalToUint64(opLength.Data[0][0].Value)
if err != nil {
return
}
} else {
- length = uint64(len(op.Data))
+ length = uint64(len(opLength.Data))
}
- fn, ok := fnTable[string(funcID.Data[0][0].Bytes)]
- if !ok {
- err = se.ErrorCodeNoSuchFunction
+ funcID, err := ast.DecimalToUint64(opFuncID.Data[0][0].Value)
+ if err != nil {
+ return
+ }
+
+ id := uint16(funcID)
+ if uint64(id) != funcID {
+ err = se.ErrorCodeIndexOutOfRange
return
}
@@ -1874,6 +1879,6 @@ func opFunc(ctx *common.Context, ops, registers []*Operand, output uint) (err er
return
}
- registers[output] = op2
+ registers[output] = result
return
}