Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Event log decode fails #3684

Closed
viswanathkgp12 opened this issue Aug 12, 2020 · 9 comments
Closed

Event log decode fails #3684

viswanathkgp12 opened this issue Aug 12, 2020 · 9 comments
Assignees
Labels
1.x 1.0 related issues Investigate On Ice Important but no longer pursued for the near future P2 Medium severity bugs Stale Has not received enough activity

Comments

@viswanathkgp12
Copy link
Contributor

viswanathkgp12 commented Aug 12, 2020

I've tried decoding OracleRequest event logs from this tx using web3.eth.abi.decodeLog

Expected behavior

Decodes correctly to:

Result {                                                                                                                                                                                                                                                                                                        
  requester: '0x9745936F56296f557B089F77ccb55d582A1a37ee',                                                                                                              
  requestId: '0xd0b9a398aae63b33fad8b98f42ddf483f6626c647e90bef4fe94a9425db8a29e',                                                                                      
  payment: '100000000000000000',                                                                                                                                        
  callbackAddr: '0x9745936F56296f557B089F77ccb55d582A1a37ee',                                                                                                           
  callbackFunctionId: '0x7f78fc7a',                                                                                                                                     
  cancelExpiration: '1597179626',                                                                                                                                       
  dataVersion: '1',                                                                                                                                                     
  data: '0x63676574782b68747470733a2f2f626c6f636b636861696e2e696e666f2f7469636b65723f63757272656e63793d5553446470617468685553442e6c6173746574696d65731b0de0b6b3a7640000'
,                                                                                                                                                                       
  specId: '0x6632393166383539376431373466346161313938336230653237616531363066'                                                                                          
}                                                                                                                                                                       

Actual behavior

Event log decode fails. Logs attached below.

From the logs, it looked like the abi decoder expects event data to be a multiple of 32 bytes or 64 hex characters. When I padded extra zeroes at the end to satisfy this condition, it decoded correctly. I think the library should handle this automatically.

Steps to reproduce the behavior

const Web3 = require("web3");
const web3 = new Web3("https://cloudflare-eth.com");

// This can be cross-verified from the below link
// https://etherscan.io/address/0x89f70fa9f439dbd0a1bc22a09befc56ada04d9b4#code
const oracleRequestEventLogInputsABI = [
  {
    name: "requester",
    type: "address",
  },
  {
    name: "requestId",
    type: "bytes32",
  },
  {
    name: "payment",
    type: "uint256",
  },
  {
    name: "callbackAddr",
    type: "address",
  },
  {
    name: "callbackFunctionId",
    type: "bytes4",
  },
  {
    name: "cancelExpiration",
    type: "uint256",
  },
  {
    name: "dataVersion",
    type: "uint256",
  },
  {
    name: "data",
    type: "bytes",
  },
  {
    indexed: true,
    name: "specId",
    type: "bytes32",
  },
];

async function testEventLogDecode() {
  const { logs } = await web3.eth.getTransactionReceipt(
    "0x2e2aec5cbd5bff2c720dd1387a692c1f2ec691f996e6edb8518c7125d1bab2e5"
  );

  // OracleRequest Event log is at index 7 - HARDCODED
  const oracleRequestEventLogData = logs[7].data;
  const oracleRequestEventLogTopics = logs[7].topics;

  // This data can be cross-checked from etherscan
  // https://etherscan.io/tx/0x2e2aec5cbd5bff2c720dd1387a692c1f2ec691f996e6edb8518c7125d1bab2e5#eventlog
  console.log("Oracle Request eventLogData: ", oracleRequestEventLogData);
  console.log("Oracle Request topics: ", oracleRequestEventLogTopics);

  // Remove topic[0]
  // https://web3js.readthedocs.io/en/v1.2.11/web3-eth-abi.html#decodelog
  oracleRequestEventLogTopics.shift();

  const result = web3.eth.abi.decodeLog(
    oracleRequestEventLogInputsABI,
    oracleRequestEventLogData,
    oracleRequestEventLogTopics
  );

  console.log("Decoded data: ", result);
}

testEventLogDecode();

Logs

(node:2280) UnhandledPromiseRejectionWarning: Error: data out-of-bounds (length=127, offset=128, code=BUFFER_OVERRUN, version=abi/5.0.0-beta.153)
    at Logger.makeError (C:\Users\dell\Desktop\matic-security-hackathon\node_modules\@ethersproject\logger\lib\index.js:179:21)
    at Logger.throwError (C:\Users\dell\Desktop\matic-security-hackathon\node_modules\@ethersproject\logger\lib\index.js:188:20)
    at Reader._peekBytes (C:\Users\dell\Desktop\matic-security-hackathon\node_modules\@ethersproject\abi\lib\coders\abstract-coder.js:135:20)
    at Reader.readBytes (C:\Users\dell\Desktop\matic-security-hackathon\node_modules\@ethersproject\abi\lib\coders\abstract-coder.js:146:26)
    at BytesCoder.DynamicBytesCoder.decode (C:\Users\dell\Desktop\matic-security-hackathon\node_modules\@ethersproject\abi\lib\coders\bytes.js:30:23)
    at BytesCoder.decode (C:\Users\dell\Desktop\matic-security-hackathon\node_modules\@ethersproject\abi\lib\coders\bytes.js:41:81)
    at C:\Users\dell\Desktop\matic-security-hackathon\node_modules\@ethersproject\abi\lib\coders\array.js:77:31
    at Array.forEach (<anonymous>)
    at Object.unpack (C:\Users\dell\Desktop\matic-security-hackathon\node_modules\@ethersproject\abi\lib\coders\array.js:71:12)
    at TupleCoder.decode (C:\Users\dell\Desktop\matic-security-hackathon\node_modules\@ethersproject\abi\lib\coders\tuple.js:39:49)
    at AbiCoder.decode (C:\Users\dell\Desktop\matic-security-hackathon\node_modules\@ethersproject\abi\lib\abi-coder.js:93:22)
    at ABICoder.decodeParameters (C:\Users\dell\Desktop\matic-security-hackathon\node_modules\web3-eth-abi\src\index.js:341:30)
    at ABICoder.decodeLog (C:\Users\dell\Desktop\matic-security-hackathon\node_modules\web3-eth-abi\src\index.js:395:52)
    at testEventLogDecode (C:\Users\dell\Desktop\matic-security-hackathon\test.js:64:31)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)

Environment

Tested on web3js v1.2.9 and v1.2.11

@ryanio
Copy link
Collaborator

ryanio commented Aug 12, 2020

Please see related issue: #3544

from ethers-io/ethers.js#992 (comment):

There is a known Solidity v4.x bug that events emitted from an external (public is fine) function in Solidity that dynamic objects are encoded incorrectly.
This is a compiler bug which makes it very hard to work around. :(
The work around for it can break correctly functioning contracts, which is the problem.

@viswanathkgp12
Copy link
Contributor Author

Okay. I didn't see that. Since there is another issue open reg. the same, should I close this?

@GregTheGreek
Copy link
Contributor

@viswanathkgp12 We'll keep it open for now, its a good reference point.

@GregTheGreek GregTheGreek added 1.x 1.0 related issues On Ice Important but no longer pursued for the near future labels Aug 13, 2020
@ricmoo
Copy link
Contributor

ricmoo commented Sep 8, 2020

I've added support in ethers 5.0.12 for supporting legacy Solidity 0.4 external event data. I believe web3 depends on the abi package directly, in which case web3 should upgrade to @ethersproject/abi version 5.0.4.

For more details, please see ethers-io/ethers.js#891.

@github-actions
Copy link

github-actions bot commented Nov 8, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions. If you believe this was a mistake, please comment.

@github-actions github-actions bot added the Stale Has not received enough activity label Nov 8, 2020
@GregTheGreek
Copy link
Contributor

@koraykoska Can you double check this :)

@GregTheGreek GregTheGreek removed the Stale Has not received enough activity label Nov 11, 2020
@github-actions
Copy link

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions. If you believe this was a mistake, please comment.

@github-actions github-actions bot added the Stale Has not received enough activity label Jan 11, 2021
@GregTheGreek GregTheGreek removed the Stale Has not received enough activity label Jan 11, 2021
@spacesailor24 spacesailor24 added Investigate P2 Medium severity bugs labels Mar 5, 2021
@koraykoska koraykoska self-assigned this Mar 24, 2021
@koraykoska koraykoska added this to the Maintenance milestone Mar 24, 2021
@koraykoska
Copy link

@ethersproject/abi is on 5.0.7 and this issue shouldn't exist any more.

@Polycarpik Polycarpik removed this from the Maintenance milestone May 12, 2021
@github-actions
Copy link

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions. If you believe this was a mistake, please comment.

@github-actions github-actions bot added the Stale Has not received enough activity label Jul 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
1.x 1.0 related issues Investigate On Ice Important but no longer pursued for the near future P2 Medium severity bugs Stale Has not received enough activity
Projects
None yet
Development

No branches or pull requests

7 participants