oxen-io / oxen-core

Oxen core repository, containing oxend and oxen cli wallets
https://oxen.io
Other
317 stars 120 forks source link

Use checksum formatting for eth addresses #1739

Closed jagerman closed 4 weeks ago

jagerman commented 1 month ago

This changes the format for eth::address values to use checksum formatting, both when formatting via fmt (such as in log statements) and when writing them as values in an RPC response.

Sample log line:

[2024-10-11 20:29:04] [+0.021s] [service_nodes:info|cryptonote_core/service_node_list.cpp:1695] New service node exit (op: 0xb82Cd271CE0E498e4203AC4db801698Bd720f6AF; key: decaf035871aa9d8e7da429f39711c349f380840ac4a305530b5a19c18793681; returned: 120000000000) tx (8a2dcbfd5484a59814017600a7865b6049fae28a45d447678e6803ebb06eee3c) from ethereum: decaf035871aa9d8e7da429f39711c349f380840ac4a305530b5a19c18793681 @ height: 38269; awaiting confirmations

and excerpt from the get_service_nodes rpc endpoint:

{
        "contributors": [
          {
            "address": "0xb82Cd271CE0E498e4203AC4db801698Bd720f6AF",
            "amount": 120000000000,
            "locked_contributions": []
          }
        ],
        "operator_address": "0xb82Cd271CE0E498e4203AC4db801698Bd720f6AF"
}
jagerman commented 1 month ago

(The checksum algorithm is rather stupid: first you must convert to lower-case hex because longer is better or something, then you get a 256-bit hash of the hex value, then you proceed to use only 40 of those bits to decide whether to flip a-f characters to A-F (if found), and you completely ignore the other 216 bits because let's just do pointless hex conversions and oversize hashes yay. But it's not even 40 sequential bits, but rather bit 8, 4, 16, 12, 24, 20, ..., 160, 156.)

jagerman commented 1 month ago

Heads up @Doy-lee - this also starts including the 0x prefix in RPC response for eth addresses, which wasn't there before and might need fixes in the block observer or staking backend.