fix eip2718 bug

- fixes bug in rlp decoder of Receipt
- fixes bug in rlp decoder of Transaction
- refactor rlpEncode for AccessListTx in eth/common/transaction.nim
This commit is contained in:
jangko 2021-05-15 14:26:51 +07:00
parent b6b6f3dec7
commit 343d4f25e1
No known key found for this signature in database
GPG Key ID: 31702AE10541E6B9
2 changed files with 17 additions and 9 deletions

View File

@ -369,7 +369,10 @@ proc read*(rlp: var Rlp, T: type Transaction): T =
else:
let bytes = rlp.read(Blob)
var rr = rlpFromBytes(bytes)
assert(rr.read(int) == 1)
let txType = rr.read(int)
if txType != 1:
raise newException(UnsupportedRlpError,
"TxType expect 1 got " & $txType)
result = Transaction(
txType: AccessListTxType,
accessListTx: rr.read(AccessListTx)
@ -427,7 +430,10 @@ proc read*(rlp: var Rlp, T: type Receipt): T =
else:
let bytes = rlp.read(Blob)
var rr = rlpFromBytes(bytes)
assert(rr.read(int) == 1)
let recType = rr.read(int)
if recType != 1:
raise newException(UnsupportedRlpError,
"TxType expect 1 got " & $recType)
result = Receipt(
receiptType: AccessListReceiptType,
accessListReceipt: rr.read(AccessListReceipt)

View File

@ -87,11 +87,7 @@ func rlpEncodeEIP155*(tx: LegacyTx): auto =
S: 0.u256
))
func txHashNoSignature*(tx: LegacyTx): Hash256 =
# Hash transaction without signature
return keccak256.digest(if tx.V >= EIP155_CHAIN_ID_OFFSET: tx.rlpEncodeEIP155 else: tx.rlpEncode)
func txHashNoSignature*(tx: AccessListTx): Hash256 =
func rlpEncode*(tx: AccessListTx): auto =
let unsignedTx = AccessListUnsignedTx(
chainId: tx.chainId,
nonce: tx.nonce,
@ -106,8 +102,14 @@ func txHashNoSignature*(tx: AccessListTx): Hash256 =
var rw = initRlpWriter()
rw.append(1)
rw.append(unsignedTx)
let rlpBytes = rlp.encode(rw.finish())
return keccak256.digest(rlpBytes)
rlp.encode(rw.finish())
func txHashNoSignature*(tx: LegacyTx): Hash256 =
# Hash transaction without signature
keccak256.digest(if tx.V >= EIP155_CHAIN_ID_OFFSET: tx.rlpEncodeEIP155 else: tx.rlpEncode)
func txHashNoSignature*(tx: AccessListTx): Hash256 =
keccak256.digest(tx.rlpEncode)
func txHashNoSignature*(tx: Transaction): Hash256 =
if tx.txType == LegacyTxType: