Skip to content
This repository was archived by the owner on Mar 5, 2025. It is now read-only.

The r and s returned by signTransaction to does not always consist of 64 characters #6207

Closed
pustovalov opened this issue Jun 16, 2023 · 0 comments · Fixed by #6216
Closed
Assignees
Labels
4.x 4.0 related Bug Addressing a bug

Comments

@pustovalov
Copy link

Expected behavior

Signature length should for r, s should be 66 bytes

Actual behavior

In some cases signature length for r, s can be 65 bytes

Steps to reproduce the behavior

import { Web3 } from 'web3'

(async () => {
  const url = 'https://testnet.aurora.dev'
  const web3Lib = new Web3(url)
  const wallet = '0x059f9dfBb8E8Ef58082354484991C46686F5F8B2'

  const transactionCount = await web3Lib.eth.getTransactionCount(
    wallet,
    'latest',
  )

  const tx = {
    to: wallet,
    value: web3Lib.utils.toWei('1', 'wei'),
    gas: 41000,
    nonce: web3Lib.utils.toHex(transactionCount)
  }

  const signedTx = await web3Lib.eth.accounts.signTransaction(
    tx,
    `0x${process.env.PRIVATE_KEY}`,
  )
  console.log('signedTx', signedTx)

  const transaction = await web3Lib.eth.sendSignedTransaction(signedTx.rawTransaction)
  const transactionByHash = await web3Lib.eth.getTransaction(transaction.transactionHash)

  console.log('transactionByHash', transactionByHash)
})()

Logs

signedTx {
  messageHash: '0x7b29f620af6ce4677b4d8a73e0c3107704c7521ec053a8850570f69a4f71cd3b',
  v: '0x9c8a82c9',
  r: '0x3ded0b10cedf23352ff65cee83e0f491c3ebe79346e74aef490a507dc411fa6',
  s: '0x284b6b6c77be9aaac2483c8f08ae27874067ae2c62f0b4feed2fba937ae9212a',
  rawTransaction: '0xf8658202c98082a02894059f9dfbb8e8ef58082354484991c46686f5f8b20180849c8a82c9a003ded0b10cedf23352ff65cee83e0f491c3ebe79346e74aef490a507dc411fa6a0284b6b6c77be9aaac2483c8f08ae27874067ae2c62f0b4feed2fba937ae9212a',
  transactionHash: '0x2a47755b3113a35615273906f3ff2b19c27c19380677503ca81d47a9c32cbb76'
}

transactionByHash {
  blockHash: '0xfc39219d5b96233844a8d822e92cf3b0e388275362f1cff1595ad3196bb2d73c',
  blockNumber: 129264354n,
  from: '0x059f9dfbb8e8ef58082354484991c46686f5f8b2',
  gas: 41000n,
  gasPrice: 0n,
  hash: '0x2a47755b3113a35615273906f3ff2b19c27c19380677503ca81d47a9c32cbb76',
  input: '0x',
  nonce: 713n,
  v: 2626323145n,
  r: '0x03ded0b10cedf23352ff65cee83e0f491c3ebe79346e74aef490a507dc411fa6',
  s: '0x284b6b6c77be9aaac2483c8f08ae27874067ae2c62f0b4feed2fba937ae9212a',
  to: '0x059f9dfbb8e8ef58082354484991c46686f5f8b2',
  type: 0n,
  transactionIndex: 0n,
  value: 1n,
  data: '0x'
}

In this case we have this signature generated by web3.js

r: 0x3ded0b10cedf23352ff65cee83e0f491c3ebe79346e74aef490a507dc411fa6

And result from the RPC is:

r: 0x03ded0b10cedf23352ff65cee83e0f491c3ebe79346e74aef490a507dc411fa6

And if decode this tx by ethers.js the result will be:

{
  "type": 0,
  "to": "0x059f9dfBb8E8Ef58082354484991C46686F5F8B2",
  "data": "0x",
  "nonce": 713,
  "gasLimit": "41000",
  "gasPrice": "0",
  "maxPriorityFeePerGas": null,
  "maxFeePerGas": null,
  "value": "1",
  "chainId": "1313161555",
  "sig": {
    "_type": "signature",
    "networkV": "2626323145",
    "r": "0x03ded0b10cedf23352ff65cee83e0f491c3ebe79346e74aef490a507dc411fa6",
    "s": "0x284b6b6c77be9aaac2483c8f08ae27874067ae2c62f0b4feed2fba937ae9212a",
    "v": 27
  },
  "accessList": null
}

with:

r: 0x03ded0b10cedf23352ff65cee83e0f491c3ebe79346e74aef490a507dc411fa6

Environment

Node: v18.16.0
web3.js: 4.0.1

@mconnelly8 mconnelly8 added Bug Addressing a bug 4.x 4.0 related labels Jun 20, 2023
@Muhammad-Altabba Muhammad-Altabba self-assigned this Jun 21, 2023
@Muhammad-Altabba Muhammad-Altabba linked a pull request Jun 21, 2023 that will close this issue
17 tasks
@Muhammad-Altabba Muhammad-Altabba changed the title Signature length is incorrect The r and s returned by signTransaction to does not always consist of 64 characters Jun 21, 2023
@jdevcs jdevcs mentioned this issue Jun 26, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
4.x 4.0 related Bug Addressing a bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants