aboutsummaryrefslogtreecommitdiffstats
path: root/core/vm/sqlvm/runtime
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 /core/vm/sqlvm/runtime
parentc6f123b6f7e343d6cf32521b6aa2a9543a6948dd (diff)
downloaddexon-90295637bc9e7fe47d3001266efcf53252fe699a.tar
dexon-90295637bc9e7fe47d3001266efcf53252fe699a.tar.gz
dexon-90295637bc9e7fe47d3001266efcf53252fe699a.tar.bz2
dexon-90295637bc9e7fe47d3001266efcf53252fe699a.tar.lz
dexon-90295637bc9e7fe47d3001266efcf53252fe699a.tar.xz
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.
Diffstat (limited to 'core/vm/sqlvm/runtime')
-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
3 files changed, 13 insertions, 7 deletions
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,
+}