Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

RPC encoding regression in 2.6.1 #467

Closed
hkalodner opened this issue Aug 16, 2019 · 2 comments · Fixed by #470
Closed

RPC encoding regression in 2.6.1 #467

hkalodner opened this issue Aug 16, 2019 · 2 comments · Fixed by #470

Comments

@hkalodner
Copy link

Version 2.6.1 upgraded the dependency on web3-provider-engine from version 14.1.0 to version 14.2.0. This version upgrade contains a regression (also reported in MetaMask/web3-provider-engine#317).

The regression is a deviation from the rpc hex encoding specification described in https://github.com/ethereum/wiki/wiki/JSON-RPC#hex-value-encoding. 0 values are now encoded as "0x" when they should be "0x0". This causes errors in rpc client libraries that expect strict correctness like go-ethereum.

Expected Behavior

Calls to rpc methods which contain results including 0 values should correctly encode them as "0x0"

Current Behavior

Calls to rpc methods which contain results including 0 values encode them as "0x"

Possible Solution

This could be solved by either downgrading the web3-provider-engine dependency back to 14.1.0 or getting an upstream fix into web3-provider-engine and upgrading. If there are no other reasons why 14.2.0 is required, downgrading seems like the easiest immediate fix.

Steps to Reproduce (for bugs)

The following code will print the difficulty returned by ganache-core as 0x when running with 2.6.1 and 0x0 when running 2.6.0.

const ganache = require("ganache-core");
const WebSocket = require('ws');

ganache.server({blockTime: 1}).listen(7545);
var client = new WebSocket("ws://localhost:7545/");
client.onopen = function(e){
   this.send('{"id":1337,"jsonrpc":"2.0","method":"eth_subscribe","params":["newHeads", {}]}');
}
client.onmessage = function(response,flags,number)  {
   try {
       console.log(JSON.parse(response.data).params.result.difficulty);
   } catch(e) {}
}

Context

This came up trying to use ganache along with go-ethereum which forces strict adherence to the hex encoding in
https://github.com/ethereum/go-ethereum/blob/dbb03fe9893dd19f6b1de1ee3b768317f22fd135/common/hexutil/json.go#L358.

Specifically calls to SubscribeNewHead result in a JSON unmarshalling error due to this problem.

Your Environment

@kumavis
Copy link
Contributor

kumavis commented Aug 20, 2019

patched in web3-provider-engine@14.2.1

@hkalodner
Copy link
Author

Thanks @kumavis! It'd be great to get this dependency upgraded in this package. No wiggle room on the version pinning so it'll require an upgrade.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants