mirror of https://github.com/status-im/nim-eth.git
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:
parent
b6b6f3dec7
commit
343d4f25e1
|
@ -369,7 +369,10 @@ proc read*(rlp: var Rlp, T: type Transaction): T =
|
||||||
else:
|
else:
|
||||||
let bytes = rlp.read(Blob)
|
let bytes = rlp.read(Blob)
|
||||||
var rr = rlpFromBytes(bytes)
|
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(
|
result = Transaction(
|
||||||
txType: AccessListTxType,
|
txType: AccessListTxType,
|
||||||
accessListTx: rr.read(AccessListTx)
|
accessListTx: rr.read(AccessListTx)
|
||||||
|
@ -427,7 +430,10 @@ proc read*(rlp: var Rlp, T: type Receipt): T =
|
||||||
else:
|
else:
|
||||||
let bytes = rlp.read(Blob)
|
let bytes = rlp.read(Blob)
|
||||||
var rr = rlpFromBytes(bytes)
|
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(
|
result = Receipt(
|
||||||
receiptType: AccessListReceiptType,
|
receiptType: AccessListReceiptType,
|
||||||
accessListReceipt: rr.read(AccessListReceipt)
|
accessListReceipt: rr.read(AccessListReceipt)
|
||||||
|
|
|
@ -87,11 +87,7 @@ func rlpEncodeEIP155*(tx: LegacyTx): auto =
|
||||||
S: 0.u256
|
S: 0.u256
|
||||||
))
|
))
|
||||||
|
|
||||||
func txHashNoSignature*(tx: LegacyTx): Hash256 =
|
func rlpEncode*(tx: AccessListTx): auto =
|
||||||
# Hash transaction without signature
|
|
||||||
return keccak256.digest(if tx.V >= EIP155_CHAIN_ID_OFFSET: tx.rlpEncodeEIP155 else: tx.rlpEncode)
|
|
||||||
|
|
||||||
func txHashNoSignature*(tx: AccessListTx): Hash256 =
|
|
||||||
let unsignedTx = AccessListUnsignedTx(
|
let unsignedTx = AccessListUnsignedTx(
|
||||||
chainId: tx.chainId,
|
chainId: tx.chainId,
|
||||||
nonce: tx.nonce,
|
nonce: tx.nonce,
|
||||||
|
@ -106,8 +102,14 @@ func txHashNoSignature*(tx: AccessListTx): Hash256 =
|
||||||
var rw = initRlpWriter()
|
var rw = initRlpWriter()
|
||||||
rw.append(1)
|
rw.append(1)
|
||||||
rw.append(unsignedTx)
|
rw.append(unsignedTx)
|
||||||
let rlpBytes = rlp.encode(rw.finish())
|
rlp.encode(rw.finish())
|
||||||
return keccak256.digest(rlpBytes)
|
|
||||||
|
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 =
|
func txHashNoSignature*(tx: Transaction): Hash256 =
|
||||||
if tx.txType == LegacyTxType:
|
if tx.txType == LegacyTxType:
|
||||||
|
|
Loading…
Reference in New Issue