Skip to content

About

Alpha. Stage a transaction on one machine, read it on a second device, match the hash on the hardware wallet.

Resources

Stars

1 star

Watchers

0 watching

Forks

Latest commit

 

History

41 Commits

Folders and files

Repository files navigation

Countersign

Alpha. Use it alongside your normal checks, not instead of them.

Stage a transaction on one machine, read what it does on a second device, and match the hash on the hardware wallet.

A hardware wallet that cannot decode a call shows only a hash. A hash proves nothing unless the expected value reaches you by a path that does not run through the machine asking for the signature. Countersign gives you that path.

How it works

  1. Stage (csign stage, on the computer). Builds the transaction with every field fixed: nonce, gas limit, fees. Simulates it. Signs nothing.
  2. Show (csign show). Displays the raw transaction as an animated QR code. Only the transaction fields cross; a bundle carrying any other field is refused by the verifier, so no label or description from the computer can reach it.
  3. Verify (the page in web/dist/verify/index.html, on a phone). Recomputes the hash with its own code, decodes the call and any batch inside it, shows every address in full, and remembers which addresses this phone has checked before.
  4. Sign (csign sign). One flow: shows the QR while the Ledger waits with exactly the staged bytes; once approved on the device, keeps the result only if it equals the staged transaction field by field, and publishes it.

It handles plain transactions, Safe owner signatures, and Safe executions (an execution is a plain transaction to the Safe; the verifier unpacks the Safe transaction inside it, recovers who signed, and shows both hashes).

The QR format is small and open: any program can show it and any program can read it. It is written down in PROTOCOL.md, so a wallet manager or a Safe front end can emit it and use the same verifier, and other verifiers can be written.

Security model

The threat. The computer that prepares the transaction is wrong or compromised: an agent that built the wrong call, a swapped address, malware that changes the transaction before it reaches the wallet.

What you trust.

  • The hardware wallet: its key, and what its own screen shows.
  • The phone and the verifier page on it. The page computes the hash with code that shares nothing with the computer's.
  • Your own eyes on two screens.

What you do not need to trust. The computer, the agent, csign itself, or anything they print. Only the raw transaction fields cross to the phone; a bundle carrying any description or label is refused.

Why it holds. The wallet signs exactly the bytes whose hash it displays. The phone shows what those bytes do and what their hash is. If the two hashes match, what you read on the phone is what gets signed, whatever the computer did. To cheat, an attacker has to control the computer and the phone at once.

Where it does not hold.

  • The wallet shows no hash. A Ledger shows none for a transaction it cannot decode unless the hash display setting is on. Then the device confirms only the sender and the fee.
  • The key lives on the computer or in a cloud service. There is no second screen, so the phone is a reading aid against mistakes and nothing more.
  • You do not actually compare, or you approve a transaction you do not understand. The phone decodes the call; it does not judge whether it is a good idea, and it does not simulate what the contract will do.
  • The verifier page itself is malicious. It pins itself on the phone and warns on change (see below), but the first load on a phone trusts the server.
  • A wrong ABI from a lookup service can mislabel arguments. It cannot change the hash, and every decode says where its names came from.

Setup

  1. Install Node 20 or later and Foundry (cast).
  2. npm install -g csign. This gives you the csign command.
  3. On your phone, open the verifier page, add it to the home screen, and from then on open it from that icon only. Address: https://countersign.genlayer.foundation/verify/ (built by Cloudflare Pages from this repository's main branch; npm run build prints the hash of the file it should be serving).
  4. On a Ledger: open the Ethereum app, go to Settings, and turn on the option to always show the transaction hash. Without it the device shows no hash for a transaction it cannot decode, and there is nothing to match. Use Ethereum app 1.24.0 or later: earlier versions left the hash out of token transfers and approvals.

Use

npm install && npm run build          # builds web/dist: verify/index.html (the verifier, one self-contained file) and the landing page
csign stage tx --chain base --from 0x… --to 0x… --path "m/44'/60'/1'/0/0" --sig 'transfer(address,uint256)' -- 0x… 1000000000000000000
csign stage tx --chain base --from 0x… --path "m/44'/60'/1'/0/0" --create --code-file out/Hook.sol/Hook.json --sig 'constructor(address,uint256)' -- 0x… 5   # deploy a contract
csign stage safe-exec --chain eth --from 0x… --path "…" <safeTxHash>
csign stage safe-sign --signer 0x… --path "…" request-payload.json
csign sign <id>      # QR and Ledger together, then publish. `csign show <id>` shows only the QR.
csign send --chain base --from 0x… --to 0x… --path "…" --sig 'transfer(address,uint256)' -- 0x… 1000000000000000000   # stage and sign in one, when you type the command yourself

The phone needs the page over HTTPS for the camera to work. Without a camera, csign show <id> --frames prints the frames as text for the page's paste box.

The page saves itself on the phone

The verifier page is the one piece everyone loads from one place, so it protects itself as far as a web page can:

  • On first use it saves a copy on the phone and from then on runs only that copy, with or without a network. The copy is saved only if it matches the hash it was published with.
  • When the server has a different version, the saved copy notices, shows both hashes, and keeps running until you accept the new one. The notice links to web/page-hash.txt in this repository, which holds the hash of the page built from that commit; npm run build reproduces it.
  • If the saved copy is replaced without your accepting it while the page is open, the page says so. A server set on replacing it can still do so (it can serve a worker that takes over and reloads the page), so treat this as protection against quiet or accidental changes. What stops a swapped page from getting a bad transaction signed is the other half of the pair: it cannot change the bytes the wallet signs without the computer's help.
  • The hash of the running copy is always at the bottom of the page.
  • The verifier has its own version number (web/src/VERSION), raised only when its source changes. A new release of the csign command does not change the page, its hash or its IPFS address.
  • The verifier lives under /verify/ and its hash covers that one file. The landing page at the top of the site is separate, runs no scripts and can change without changing the verifier.

Add the page to the home screen and open it only from that icon. On an iPhone the home-screen copy has its own storage, is not cleared after a week without use, and holds your address names; a link someone sends you opens a different, empty copy where every address shows as new.

What this does not cover: the very first load on a phone, and a phone whose browser data was wiped. Both start from trust in the server.

The same page on IPFS

Each build also works out the IPFS address of the verifier folder (web/ipfs-address.txt), and the release job pins that folder. An IPFS address is a hash of the contents, so it can only ever show that exact page: nobody who takes over the site, the domain or this repository can change what it serves. Open https://<address>.ipfs.dweb.link/ on the phone and add it to the home screen. The gateway's own script fetches the pieces and checks them against the address in the browser.

What changes there: the page keeps no saved copy of its own (the footer says it was opened from IPFS), a new verifier version is a new address you move to yourself, and the list of addresses the phone has checked starts empty at each new address. What you rely on instead of this site is the gateway that serves the checking script.

Updating the verifier

The copy on this site updates in place: it shows both hashes and waits for you to accept.

A copy opened from IPFS never changes. When a newer verifier exists it says so (it reads web/verifier.json from this repository, only while lookups from the phone are switched on) and sends you here. To move to it:

  1. Read the new version, page hash and IPFS address in web/verifier.json. They are written by the build; npm run build on a checkout reproduces them.
  2. On the phone open https://<ipfs address>.ipfs.dweb.link/ and add it to the home screen. Its name carries the version, for example "Countersign 4", so old and new can sit side by side.
  3. In the old copy open "Address list" and copy it; in the new copy paste it and bring it in.
  4. Delete the old icon.

Signers

Signing other than on a Ledger goes through Foundry's cast, so any wallet it drives works: --ledger (default) or --trezor with --path, --account/--keystore, --aws, --gcp, --turnkey, --interactive. Raw keys and seed phrases on the command line are refused.

With a Ledger, transactions do not go through cast: csign talks to the device's Ethereum app over USB itself (cli/ledger.mjs, using node-hid). For a transfer or approval of a token on Ledger's list it first gives the device Ledger's signed description of that token, so the device shows the token, the amount and the recipient on its own screen. The device checks that description against Ledger's key; the computer cannot make one up. A token Ledger does not list (GEN, as of 30 Nov 2026) is signed as before, and the thing to match is the hash, which the Ethereum app shows for token calls only from version 1.24.0. csign ledger lists the connected devices with app version and address, and picks nothing: at signing, the device is chosen by the sender address. --via-cast signs through cast as before. Safe owner signatures still go through cast, which takes the first Ledger it finds: plug in only the one that holds the owner key (the tool checks this before signing). Close Ledger Live first: only one program can hold the device.

The hash match needs a signer with its own screen. With a hardware wallet the QR and the device prompt appear together. With a key held by the computer or a cloud service there is nothing to compare against, so the tool shows the QR, waits for Enter, then signs.

What is tested, and what is not

npm test (needs Foundry's cast for reads):

  • For real transactions on Ethereum and Base, the signing hash computed by the verifier recovers the real sender from the real signature.
  • For real Safe executions, the Safe transaction hash computed from the calldata equals the executed one, and the recovered signers are the Safe's owners.
  • Frames reassemble in any order; a changed frame and a bundle with extra fields are refused.

COUNTERSIGN_HOME=… node test/e2e.mjs: every staged bundle goes to QR pixels, is read back with the page's QR reader, and the verifier must reach the same hash and code as the CLI, which uses different software.

Tested once by hand (27 Nov 2026): phone camera scan, signing on a Ledger Stax and publishing, for an ERC-20 approve on Ethereum. The Stax showed no hash for that transaction, only the sender and the maximum fee (Ethereum app before 1.24.0 left the hash out of token calls).

Tested once by hand (30 Nov 2026): a USDT transfer signed over the direct Ledger path on a Stax with Ethereum app 1.24.0, not published. The device showed the recipient, the amount and the transaction hash, and the hash equalled the one on the phone; the signed result equalled the staged transaction. A transfer of GEN, which Ledger does not list, was signed the same way with blind signing off: the device showed no token or amount, and a transaction hash equal to the phone's.

The verifier page has been used from an iPhone home-screen icon for several days of scanning (Nov 2026) and kept working. Not checked on purpose there: the notice for a changed page, and what happens after the browser data is wiped.

Tested once by hand (1 Dec 2026), Stax, Ethereum app 1.24.0: a Safe deployment (a factory call the device cannot decode) signed over the direct path and published on the GenLayer chain; and a Safe owner signature, signed as a typed message through cast, where the device showed a domain hash and a message hash equal to the phone's, and the tool kept the signature only after checking it came from the owner. A signature from the wrong Ledger was refused.

Signer support: Ledger by hand, keystore file by a scripted run; Trezor, cloud keys and --interactive are passed through to cast and have not been run.

Not yet tested: csign publish for Safe signatures; csign stage safe-exec on a chain Safe's service does not cover.

Limits

  • The verifier's function names come from a small built-in list, the contract's verified source on Sourcify, or a public signature database. Each decode says which. A wrong name cannot change the hash.
  • For token transfers and approvals the phone reads the token's symbol and decimals from the token contract, so the amount shows in whole tokens. That name is the contract's own claim. Separately the page says where the address stands: known to the page (a short built-in list: USDT, USDC, wrapped native coin and GEN, checked against the chain by the tests), on CoinGecko's public token list for that chain (fetched by the phone, kept a day), the same symbol listed at a different address (shown in red with that address), or not listed. A listing says the address is the token people usually mean by that symbol; it says nothing about the transaction.
  • EIP-1559 transactions only.
  • Not reviewed by anyone outside. A verifier with a bug gives false confidence.

Reporting a problem

If you find a way to make the phone show something other than what gets signed, or any other security problem, report it privately: on this repository's Security tab, choose "Report a vulnerability". Please do not open a public issue for it.

Licence

MIT. See LICENSE.

About

Alpha. Stage a transaction on one machine, read it on a second device, match the hash on the hardware wallet.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages