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

Commit

Permalink
JSON-RPC: transaction: Represent R and S as RpcQuantityHex (#166)
Browse files Browse the repository at this point in the history
Problem: Go-ethereum client cannot unmarshall json it receives from Ganache's
response to 'eth_getBlockByHash' request.

Best Known Cause: Go-etherum client interprets R and S as quantities, not data
( as evidenced by big.Int type )
(https://github.com/ethereum/go-ethereum/blob/master/core/types/transaction.go#L54)

Temporary solution: Encode R and S as RPC quantity, not data.

Justification: At the moment, it is easier to customize Ganache than to propose
changes to Go-etherum client. Moreover, it appears strange for the Ethereum
JSON RPC Specification to treat R and S as data, not quantities: after all, R
and S and integer-like objects in the context of the elliptic curve
cryptography, i.e. they admit operations such as addition, subtraction,
modulus, etc.

Proposal for long-term solution: From remarks above, it appears most natural to
change the Ethereum JSON RPC Specification to treat R and S as quantities and
change Ganache accordingly.
  • Loading branch information
icherkashin committed Apr 17, 2019
1 parent 698f007 commit cb376ee
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/utils/to.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ module.exports = {

_rpcQuantityHexString: function(val) {
val = this.hex(val);
// remove all zeroes leading zeros, `0+`, from the hex-encoded value
// remove all leading zeros, `0+`, from the hex-encoded value
// This doesn't remove the last 0 which would be captured by `(.+?)`
val = val.replace(/^(?:0x)(?:0+(.+?))?$/, "0x$1");
return val;
Expand Down
4 changes: 2 additions & 2 deletions lib/utils/transaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -300,8 +300,8 @@ module.exports = class Transaction extends EthereumJsTransaction {
gasPrice: to.rpcQuantityHexString(this.gasPrice),
input: to.rpcDataHexString(this.data),
v: to.nullableRpcQuantityHexString(this.v),
r: to.nullableRpcDataHexString(this.r),
s: to.nullableRpcDataHexString(this.s)
r: to.nullableRpcQuantityHexString(this.r),
s: to.nullableRpcQuantityHexString(this.s)
};

return resultJSON;
Expand Down

0 comments on commit cb376ee

Please sign in to comment.