Merge branch 'jangko-simplify_calldataload' into devel
This commit is contained in:
commit
6414436403
|
@ -253,26 +253,19 @@ op callValue, inline = true:
|
||||||
|
|
||||||
op callDataLoad, inline = false, startPos:
|
op callDataLoad, inline = false, startPos:
|
||||||
## 0x35, Get input data of current environment
|
## 0x35, Get input data of current environment
|
||||||
let dataPos = startPos.cleanMemRef
|
let start = startPos.cleanMemRef
|
||||||
if dataPos >= computation.msg.data.len:
|
if start >= computation.msg.data.len:
|
||||||
push: 0
|
push: 0
|
||||||
return
|
return
|
||||||
|
|
||||||
let dataEndPosition = dataPos + 31
|
# If the data does not take 32 bytes, pad with zeros
|
||||||
|
let endRange = min(computation.msg.data.len - 1, start + 31)
|
||||||
|
let presentBytes = endRange - start
|
||||||
|
# We rely on value being initialized with 0 by default
|
||||||
|
var value: array[32, byte]
|
||||||
|
value[0 .. presentBytes] = computation.msg.data.toOpenArray(start, endRange)
|
||||||
|
|
||||||
if dataEndPosition < computation.msg.data.len:
|
push: value
|
||||||
computation.stack.push(computation.msg.data[dataPos .. dataEndPosition])
|
|
||||||
else:
|
|
||||||
var bytes: array[32, byte]
|
|
||||||
var presentBytes = min(computation.msg.data.len - dataPos, 32)
|
|
||||||
|
|
||||||
if presentBytes > 0:
|
|
||||||
copyMem(addr bytes[0], addr computation.msg.data[dataPos], presentBytes)
|
|
||||||
else:
|
|
||||||
presentBytes = 0
|
|
||||||
|
|
||||||
for i in presentBytes ..< 32: bytes[i] = 0
|
|
||||||
computation.stack.push(bytes)
|
|
||||||
|
|
||||||
op callDataSize, inline = true:
|
op callDataSize, inline = true:
|
||||||
## 0x36, Get size of input data in current environment.
|
## 0x36, Get size of input data in current environment.
|
||||||
|
|
|
@ -21,5 +21,6 @@ import ./test_code_stream,
|
||||||
./test_op_env,
|
./test_op_env,
|
||||||
./test_op_memory,
|
./test_op_memory,
|
||||||
./test_op_misc,
|
./test_op_misc,
|
||||||
|
./test_op_custom,
|
||||||
./test_state_db
|
./test_state_db
|
||||||
|
|
||||||
|
|
|
@ -6,16 +6,6 @@ import
|
||||||
suite "Custom Opcodes Test":
|
suite "Custom Opcodes Test":
|
||||||
let (blockNumber, chainDB) = initDatabase()
|
let (blockNumber, chainDB) = initDatabase()
|
||||||
|
|
||||||
var acc: EthAddress
|
|
||||||
hexToByteArray("0xc669eaad75042be84daaf9b461b0e868b9ac1871", acc)
|
|
||||||
var
|
|
||||||
parent = chainDB.getBlockHeader(blockNumber - 1)
|
|
||||||
stateDB = newAccountStateDB(chainDB.db, parent.stateRoot, false)
|
|
||||||
|
|
||||||
stateDB.setBalance(acc, 1000.u256)
|
|
||||||
parent.stateRoot = stateDB.rootHash
|
|
||||||
chainDB.setHead(parent, true)
|
|
||||||
|
|
||||||
assembler: # CALLDATASIZE OP
|
assembler: # CALLDATASIZE OP
|
||||||
title: "CALLDATASIZE_1"
|
title: "CALLDATASIZE_1"
|
||||||
data:
|
data:
|
||||||
|
@ -81,6 +71,15 @@ suite "Custom Opcodes Test":
|
||||||
CallDataLoad
|
CallDataLoad
|
||||||
success: false
|
success: false
|
||||||
|
|
||||||
|
assembler: # CALLDATALOAD OP
|
||||||
|
title: "CALLDATALOAD_7"
|
||||||
|
data:
|
||||||
|
"0x00000000000000000000000000000000000000000000000000000000000000A1"
|
||||||
|
"0x00000000000000000000000000000000000000000000000000000000000000B1"
|
||||||
|
code:
|
||||||
|
Push1 "0x40"
|
||||||
|
CallDataLoad
|
||||||
|
stack: "0x00"
|
||||||
|
|
||||||
assembler: # CALLDATACOPY OP
|
assembler: # CALLDATACOPY OP
|
||||||
title: "CALLDATACOPY_1"
|
title: "CALLDATACOPY_1"
|
||||||
|
@ -185,7 +184,7 @@ suite "Custom Opcodes Test":
|
||||||
code:
|
code:
|
||||||
Address
|
Address
|
||||||
Balance
|
Balance
|
||||||
stack: "0x00000000000000000000000000000000000000000000000000000000000003E8"
|
stack: "0x000000000000000000000000000000000000000000000000cff56a1b273a8000"
|
||||||
|
|
||||||
assembler: # ORIGIN OP
|
assembler: # ORIGIN OP
|
||||||
title: "ORIGIN_1"
|
title: "ORIGIN_1"
|
||||||
|
@ -241,42 +240,40 @@ suite "Custom Opcodes Test":
|
||||||
stack: "0x02"
|
stack: "0x02"
|
||||||
memory: "0x0000000000000000000000000000000000000000000000000000000000000201"
|
memory: "0x0000000000000000000000000000000000000000000000000000000000000201"
|
||||||
|
|
||||||
#[
|
|
||||||
assembler: # BLOCKHASH OP
|
assembler: # BLOCKHASH OP
|
||||||
title: "BLOCKHASH_1"
|
title: "BLOCKHASH_1"
|
||||||
code:
|
code:
|
||||||
Push1 "0x01"
|
Push2 "0xb864" # 47204, parent header number
|
||||||
Blockhash
|
Blockhash
|
||||||
stack: "0xC89EFDAA54C0F20C7ADF612882DF0950F5A951637E0307CDCB4C672F298B8BC6"
|
stack: "0xa85842a20755232169db76c5bd4ad4672c1551fca4b07d0bd139cd0e6fef684d"
|
||||||
]#
|
|
||||||
|
|
||||||
# current coinbase or parent coinbase?
|
# current block coinbase/miner
|
||||||
assembler: # COINBASE OP
|
assembler: # COINBASE OP
|
||||||
title: "COINBASE_1"
|
title: "COINBASE_1"
|
||||||
code:
|
code:
|
||||||
Coinbase
|
Coinbase
|
||||||
stack: "0x000000000000000000000000c0ede9a639d107851462c15f2fb729c7c61bbf62"
|
stack: "0x000000000000000000000000bb7b8287f3f0a933474a79eae42cbca977791171"
|
||||||
|
|
||||||
# current timestamp or parent timestamp?
|
# current block timestamp
|
||||||
assembler: # TIMESTAMP OP
|
assembler: # TIMESTAMP OP
|
||||||
title: "TIMESTAMP_1"
|
title: "TIMESTAMP_1"
|
||||||
code:
|
code:
|
||||||
TimeStamp
|
TimeStamp
|
||||||
stack: "0x0000000000000000000000000000000000000000000000000000000055c46bb3"
|
stack: "0x0000000000000000000000000000000000000000000000000000000055c46bba"
|
||||||
|
|
||||||
# it should be current block number
|
# current block number
|
||||||
assembler: # NUMBER OP
|
assembler: # NUMBER OP
|
||||||
title: "NUMBER_1"
|
title: "NUMBER_1"
|
||||||
code:
|
code:
|
||||||
Number
|
Number
|
||||||
stack: "0x000000000000000000000000000000000000000000000000000000000000b865"
|
stack: "0x000000000000000000000000000000000000000000000000000000000000b865"
|
||||||
|
|
||||||
# current difficulty or parent dificulty?
|
# current difficulty
|
||||||
assembler: # DIFFICULTY OP
|
assembler: # DIFFICULTY OP
|
||||||
title: "DIFFICULTY_1"
|
title: "DIFFICULTY_1"
|
||||||
code:
|
code:
|
||||||
Difficulty
|
Difficulty
|
||||||
stack: "0x0000000000000000000000000000000000000000000000000000015451e94505"
|
stack: "0x000000000000000000000000000000000000000000000000000001547c73822d"
|
||||||
|
|
||||||
# ??
|
# ??
|
||||||
assembler: # GASPRICE OP
|
assembler: # GASPRICE OP
|
||||||
|
@ -297,7 +294,7 @@ suite "Custom Opcodes Test":
|
||||||
title: "GASLIMIT_1"
|
title: "GASLIMIT_1"
|
||||||
code:
|
code:
|
||||||
GasLimit
|
GasLimit
|
||||||
stack: "0x000000000000000000000000000000000000000000000000000000000000a271"
|
stack: "0x000000000000000000000000000000000000000000000000000000000000a298"
|
||||||
|
|
||||||
assembler: # INVALID OP
|
assembler: # INVALID OP
|
||||||
title: "INVALID_1"
|
title: "INVALID_1"
|
||||||
|
|
Loading…
Reference in New Issue