Incorrectly decodes logs [2.x]
krzkaczor opened this issue · 7 comments
For mainnet tx 0x43b9b2006a00f867dcd2df9b9f7f33ac895f935154fe5acb74d51272885cd21e
log values are incorectly decoded.
Code sample:
web3.eth.getTransactionReceipt(
"0x43b9b2006a00f867dcd2df9b9f7f33ac895f935154fe5acb74d51272885cd21e",
function(e, receipt) {
const decodedLogs = abiDecoder.decodeLogs(receipt.logs);
console.log(JSON.stringify(decodedLogs));
},
);
Prints out for pollId
330000000000000000000000000000000000000000000000000000000000000022
where it should be 34
https://etherscan.io/tx/0x43b9b2006a00f867dcd2df9b9f7f33ac895f935154fe5acb74d51272885cd21e#eventlog
Hi @krzkaczor !
22 is actually 34 in hex. Not sure where that 33 is coming from but the number seems correct? in etherscan is also displayed as 22
@denisgranha thanks for the quick response! Yeah sorry, I meant 34 DEC
anyway, the response that I am getting from the lib is totally different.
I pinned point the issue to BN.JS - the version that I have in my project incorrectly parses hex strings starting with 0x
.
Are you able to confirm that it works for you?
I am gonna push the whole repository with repro in a sec.
Its ready here: https://github.com/krzkaczor/abi-decoder-bug-repro
Hi @krzkaczor I was able to reproduce the bug, thank you for the report.
Will fix it soon
My dummy fix would be to use this function to create BN instances rather than doing it directly:
function createBN(number) {
// ensure to remove leading 0x for hex numbers
if (typeof number === 'string' && number.startsWith("0x")) {
number = number.slice(2);
}
return new BN(number);
}
Thanks for quick fix! @denisgranha
Note: there are other calls to BN
constuctor, do you think they are fine?
Turns out that it still doesnt work correctly. My PR fixes it.
Stranger, if you're looking for a fix just use my fork.