Skip to content

Commit e727efc

Browse files
committed
Added support for networks with slightly incorrect EIP-658 implementations (#952, #1251).
1 parent 4af2c19 commit e727efc

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

packages/providers/src.ts/formatter.ts

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,8 @@ export class Formatter {
101101
from: Formatter.allowNull(this.address, null),
102102
contractAddress: Formatter.allowNull(address, null),
103103
transactionIndex: number,
104-
root: Formatter.allowNull(hash),
104+
// should be allowNull(hash), but broken-EIP-658 support is handled in receipt
105+
root: Formatter.allowNull(hex),
105106
gasUsed: bigNumber,
106107
logsBloom: Formatter.allowNull(data),// @TODO: should this be data?
107108
blockHash: hash,
@@ -383,7 +384,28 @@ export class Formatter {
383384
receipt(value: any): TransactionReceipt {
384385
const result: TransactionReceipt = Formatter.check(this.formats.receipt, value);
385386

386-
if (value.status != null) {
387+
// RSK incorrectly implemented EIP-658, so we munge things a bit here for it
388+
if (result.root != null) {
389+
if (result.root.length <= 4) {
390+
// Could be 0x00, 0x0, 0x01 or 0x1
391+
const value = BigNumber.from(result.root).toNumber();
392+
if (value === 0 || value === 1) {
393+
// Make sure if both are specified, they match
394+
if (result.status != null && (result.status !== value)) {
395+
logger.throwArgumentError("alt-root-status/status mismatch", "value", { root: result.root, status: result.status });
396+
}
397+
result.status = value;
398+
delete result.root;
399+
} else {
400+
logger.throwArgumentError("invalid alt-root-status", "value.root", result.root);
401+
}
402+
} else if (result.root.length !== 66) {
403+
// Must be a valid bytes32
404+
logger.throwArgumentError("invalid root hash", "value.root", result.root);
405+
}
406+
}
407+
408+
if (result.status != null) {
387409
result.byzantium = true;
388410
}
389411

0 commit comments

Comments
 (0)