Skip to content

Commit 727c0bf

Browse files
authored
Merge pull request #442 from subsquid/fix-calculateSigRecovery
Fix calculate sig recovery
2 parents 584eb50 + 06f289b commit 727c0bf

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

evm/evm-rpc/src/verification.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -377,8 +377,9 @@ function serializeTransaction(tx: Transaction): Uint8Array | undefined {
377377
decodeHex(tx.input),
378378
]
379379

380-
if (tx.chainId) {
381-
fields.push(BigInt(tx.chainId), 0n, 0n)
380+
let v = tx.v ? qty2Int(tx.v) : undefined
381+
if (v != null && v !== 27 && v !== 28) {
382+
fields.push(BigInt(assertNotNull(tx.chainId, 'tx.chainId is missing')), 0n, 0n)
382383
}
383384

384385
return RLP.encode(fields)
@@ -468,10 +469,11 @@ function calculateSigRecovery(tx: Transaction) {
468469
return qty2Int(tx.v)
469470
} else {
470471
let v = assertNotNull(tx.v, 'tx.v is missing')
471-
if (tx.chainId == null) {
472-
return qty2Int(v) - 27
472+
let vInt = qty2Int(v)
473+
if (vInt === 27 || vInt === 28) {
474+
return vInt - 27
473475
} else {
474-
return qty2Int(v) - (qty2Int(tx.chainId) * 2 + 35)
476+
return vInt - (qty2Int(assertNotNull(tx.chainId, 'tx.chainId is missing')) * 2 + 35)
475477
}
476478
}
477479
}

0 commit comments

Comments
 (0)