aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--core/vm/sqlvm/ast/types.go9
-rw-r--r--core/vm/sqlvm/ast/types_test.go9
-rw-r--r--core/vm/sqlvm/runtime/instructions.go6
-rw-r--r--core/vm/sqlvm/runtime/instructions_test.go9
-rw-r--r--core/vm/sqlvm/runtime/jumptable.go5
5 files changed, 15 insertions, 23 deletions
diff --git a/core/vm/sqlvm/ast/types.go b/core/vm/sqlvm/ast/types.go
index 975fd81ba..7d29a5c49 100644
--- a/core/vm/sqlvm/ast/types.go
+++ b/core/vm/sqlvm/ast/types.go
@@ -358,11 +358,8 @@ func DecimalEncode(dt DataType, d decimal.Decimal) ([]byte, error) {
major, minor := DecomposeDataType(dt)
switch major {
case DataTypeMajorInt,
- DataTypeMajorUint,
- DataTypeMajorFixedBytes:
+ DataTypeMajorUint:
return decimalEncode(int(minor)+1, d), nil
- case DataTypeMajorAddress:
- return decimalEncode(common.AddressLength, d), nil
}
switch {
case major.IsFixedRange():
@@ -384,9 +381,7 @@ func DecimalDecode(dt DataType, b []byte) (decimal.Decimal, error) {
switch major {
case DataTypeMajorInt:
return decimalDecode(true, b), nil
- case DataTypeMajorUint,
- DataTypeMajorFixedBytes,
- DataTypeMajorAddress:
+ case DataTypeMajorUint:
return decimalDecode(false, b), nil
}
switch {
diff --git a/core/vm/sqlvm/ast/types_test.go b/core/vm/sqlvm/ast/types_test.go
index 0973ba92a..02a51895c 100644
--- a/core/vm/sqlvm/ast/types_test.go
+++ b/core/vm/sqlvm/ast/types_test.go
@@ -120,15 +120,6 @@ func (s *TypesTestSuite) TestEncodeAndDecodeDecimal() {
zero,
3)
- s.requireEncodeAndDecodeDecimalNoError(
- ComposeDataType(DataTypeMajorAddress, 0),
- pos,
- 20)
- s.requireEncodeAndDecodeDecimalNoError(
- ComposeDataType(DataTypeMajorAddress, 0),
- zero,
- 20)
-
pos = decimal.New(15, -2)
neg = decimal.New(-15, -2)
diff --git a/core/vm/sqlvm/runtime/instructions.go b/core/vm/sqlvm/runtime/instructions.go
index a1c992988..d1bfa8a17 100644
--- a/core/vm/sqlvm/runtime/instructions.go
+++ b/core/vm/sqlvm/runtime/instructions.go
@@ -146,9 +146,9 @@ func decode(ctx *common.Context, dt ast.DataType, slot dexCommon.Hash, bytes []b
switch major {
case ast.DataTypeMajorDynamicBytes:
rVal.Bytes = ctx.Storage.DecodeDByteBySlot(ctx.Contract.Address(), slot)
- case ast.DataTypeMajorFixedBytes, ast.DataTypeMajorBool,
- ast.DataTypeMajorAddress, ast.DataTypeMajorInt,
- ast.DataTypeMajorUint:
+ case ast.DataTypeMajorFixedBytes, ast.DataTypeMajorAddress:
+ rVal.Bytes = bytes
+ case ast.DataTypeMajorBool, ast.DataTypeMajorInt, ast.DataTypeMajorUint:
d, err := ast.DecimalDecode(dt, bytes)
if err != nil {
return nil, err
diff --git a/core/vm/sqlvm/runtime/instructions_test.go b/core/vm/sqlvm/runtime/instructions_test.go
index 2601fcce3..7c6bb2c5b 100644
--- a/core/vm/sqlvm/runtime/instructions_test.go
+++ b/core/vm/sqlvm/runtime/instructions_test.go
@@ -76,7 +76,6 @@ func setSlotDataInStateDB(head dexCommon.Hash, addr dexCommon.Address,
"0000000000000000000000000000000000000000000000000000000000000041",
"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
}
- fByte20Dt := ast.ComposeDataType(ast.DataTypeMajorFixedBytes, ast.DataTypeMinor(9))
uInt256Dt := ast.ComposeDataType(ast.DataTypeMajorUint, ast.DataTypeMinor(31))
raws := []*raw{
@@ -111,8 +110,7 @@ func setSlotDataInStateDB(head dexCommon.Hash, addr dexCommon.Address,
},
{
Raw: Raw{
- Value: hexToDec(slotHash[2][:20], fByte20Dt),
- Bytes: nil,
+ Bytes: hexToBytes(slotHash[2][:20]),
},
slotShift: 2,
byteShift: 0,
@@ -177,6 +175,11 @@ func hexToDec(s string, dt ast.DataType) decimal.Decimal {
return d
}
+func hexToBytes(s string) []byte {
+ b, _ := hex.DecodeString(s)
+ return b
+}
+
type decodeTestCase struct {
dt ast.DataType
expectData *Raw
diff --git a/core/vm/sqlvm/runtime/jumptable.go b/core/vm/sqlvm/runtime/jumptable.go
index 13ffef361..5ce6d9a8a 100644
--- a/core/vm/sqlvm/runtime/jumptable.go
+++ b/core/vm/sqlvm/runtime/jumptable.go
@@ -1,3 +1,6 @@
package runtime
-var jumpTable = map[OpCode]OpFunction{}
+var jumpTable = [256]OpFunction{
+ // 0x60
+ LOAD: opLoad,
+}