Skip to content

Fail transact for large chain id? #336

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

Open
airled opened this issue May 29, 2025 · 0 comments
Open

Fail transact for large chain id? #336

airled opened this issue May 29, 2025 · 0 comments

Comments

@airled
Copy link

airled commented May 29, 2025

Hi there. I have issues for this blockchain:
Basecamp (testnet). Chain id: 123420001114

When I try to call a contract function, I get this error:
Invalid v 2026866392 value for chain ID 123420001114. Invalid chain ID? (Eth::Chain::ReplayProtectionError)

Here is a snippet of my code. I use it with my contract but you can take another one, if you want, it doesn't really matter.

abi = [{
  "name": "claimCustom",
  "type": "function",
  "inputs": [
    {"name": "accountAddress", "type": "address", "internalType": "address"},
    {"name": "amount", "type": "uint256", "internalType": "uint256"}
  ],
  "outputs": [],
  "stateMutability": "nonpayable"
}]
contract = Eth::Contract.from_abi(
  name: 'Dummy',
  address: '0x38feA0959656FF4009a8d807aDaa5247dbFEB590',
  abi: JSON.parse(abi.to_json)
)
args = [
  contract,
  'claimCustom',
  '0x0000000000000000000000000000000000000000',
  1,
]
kwargs = {sender_key: Eth::Key.new, gas_limit: 100000}
client = Eth::Client.create('https://rpc.basecamp.t.raas.gelato.cloud')
client.transact(*args, **kwargs)

It raises Invalid v 2026866391 value for chain ID 123420001114. Invalid chain ID? (Eth::Chain::ReplayProtectionError)

My thoughts on the issue.
As far as I understand, this error appears because of the large chain id.
When we call to_v here

v = Chain.to_v recovery_id, chain_id

v is 246840002263
And then the lib tries to [v].pack("N") here
[v].pack("N").unpack("C*").each do |byte|

where N is the uint32 (max value is 4294967296). But v is larger than max uint32, so pack trims the bytes, rendering invalid signature.
When I replace [v].pack("N") with [v].pack("Q").reverse (N - is uint32 big endian, Q - is uint64 native endian, so I reverse the bytes order. Q> also should work for ruby > 1.9.4), the transaction broadcasts successfully.
Well, what are your thoughts on this? Seems like this is the solution but I dont really know if Q is safe to use here.

@airled airled changed the title Fail transactions for Basecamp testnet Fail transact for large chain id? May 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant