Merge branch 'jangko-simplify_calldataload' into devel

This commit is contained in:
Ștefan Talpalaru 2019-08-26 16:21:31 +02:00
commit 6414436403
No known key found for this signature in database
GPG Key ID: CBF7934204F1B6F9
3 changed files with 30 additions and 39 deletions

View File

@ -253,26 +253,19 @@ op callValue, inline = true:
op callDataLoad, inline = false, startPos:
## 0x35, Get input data of current environment
let dataPos = startPos.cleanMemRef
if dataPos >= computation.msg.data.len:
let start = startPos.cleanMemRef
if start >= computation.msg.data.len:
push: 0
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:
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)
push: value
op callDataSize, inline = true:
## 0x36, Get size of input data in current environment.

View File

@ -21,5 +21,6 @@ import ./test_code_stream,
./test_op_env,
./test_op_memory,
./test_op_misc,
./test_op_custom,
./test_state_db

View File

@ -6,16 +6,6 @@ import
suite "Custom Opcodes Test":
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
title: "CALLDATASIZE_1"
data:
@ -81,6 +71,15 @@ suite "Custom Opcodes Test":
CallDataLoad
success: false
assembler: # CALLDATALOAD OP
title: "CALLDATALOAD_7"
data:
"0x00000000000000000000000000000000000000000000000000000000000000A1"
"0x00000000000000000000000000000000000000000000000000000000000000B1"
code:
Push1 "0x40"
CallDataLoad
stack: "0x00"
assembler: # CALLDATACOPY OP
title: "CALLDATACOPY_1"
@ -185,7 +184,7 @@ suite "Custom Opcodes Test":
code:
Address
Balance
stack: "0x00000000000000000000000000000000000000000000000000000000000003E8"
stack: "0x000000000000000000000000000000000000000000000000cff56a1b273a8000"
assembler: # ORIGIN OP
title: "ORIGIN_1"
@ -241,42 +240,40 @@ suite "Custom Opcodes Test":
stack: "0x02"
memory: "0x0000000000000000000000000000000000000000000000000000000000000201"
#[
assembler: # BLOCKHASH OP
title: "BLOCKHASH_1"
code:
Push1 "0x01"
Push2 "0xb864" # 47204, parent header number
Blockhash
stack: "0xC89EFDAA54C0F20C7ADF612882DF0950F5A951637E0307CDCB4C672F298B8BC6"
]#
stack: "0xa85842a20755232169db76c5bd4ad4672c1551fca4b07d0bd139cd0e6fef684d"
# current coinbase or parent coinbase?
# current block coinbase/miner
assembler: # COINBASE OP
title: "COINBASE_1"
code:
Coinbase
stack: "0x000000000000000000000000c0ede9a639d107851462c15f2fb729c7c61bbf62"
stack: "0x000000000000000000000000bb7b8287f3f0a933474a79eae42cbca977791171"
# current timestamp or parent timestamp?
# current block timestamp
assembler: # TIMESTAMP OP
title: "TIMESTAMP_1"
code:
TimeStamp
stack: "0x0000000000000000000000000000000000000000000000000000000055c46bb3"
stack: "0x0000000000000000000000000000000000000000000000000000000055c46bba"
# it should be current block number
# current block number
assembler: # NUMBER OP
title: "NUMBER_1"
code:
Number
stack: "0x000000000000000000000000000000000000000000000000000000000000b865"
# current difficulty or parent dificulty?
# current difficulty
assembler: # DIFFICULTY OP
title: "DIFFICULTY_1"
code:
Difficulty
stack: "0x0000000000000000000000000000000000000000000000000000015451e94505"
stack: "0x000000000000000000000000000000000000000000000000000001547c73822d"
# ??
assembler: # GASPRICE OP
@ -297,7 +294,7 @@ suite "Custom Opcodes Test":
title: "GASLIMIT_1"
code:
GasLimit
stack: "0x000000000000000000000000000000000000000000000000000000000000a271"
stack: "0x000000000000000000000000000000000000000000000000000000000000a298"
assembler: # INVALID OP
title: "INVALID_1"