aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJhih-Ming Huang <jm.huang@cobinhood.com>2019-04-01 15:05:56 +0800
committerJhih-Ming Huang <jm.huang@cobinhood.com>2019-05-06 10:44:04 +0800
commit90295637bc9e7fe47d3001266efcf53252fe699a (patch)
tree4b94bb88f4b4d1852664422c9261667134ce0c03
parentc6f123b6f7e343d6cf32521b6aa2a9543a6948dd (diff)
downloaddexon-90295637bc9e7fe47d3001266efcf53252fe699a.tar.gz
dexon-90295637bc9e7fe47d3001266efcf53252fe699a.tar.zst
dexon-90295637bc9e7fe47d3001266efcf53252fe699a.zip
core: vm: sqlvm: runtime: opLoad load fixed bytes and address in bytes
To satisfy the latest spec, the data of type of address and fixed bytes will be stored in bytes instead of decimal value.
-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,
+}