Author SHA1 Message Date
sneak 9a5bd8d39c fix: estimate a request even when the site sends its gas limit (closes #554)
check / check (push) Waiting to run
e2e / e2e-chrome (push) Waiting to run
e2e / e2e-firefox (push) Waiting to run
ethers asks the node for a gas estimate only when the request has no gas
limit, and that estimate is the wallet's only check that a transaction
does not revert. Since a site's `gas` became the gas limit, a reverting
request carrying one opened the approval window and could be signed and
mined to fail. Such a request is now estimated first, with the site's
limit and under the same timeout; a failure goes back to the site with no
window, and the site's gas limit is still the one shown and signed. A
limit too low for the call now fails the same way.

Model: opus-5-5
2026-10-14 11:57:47 +00:00
clawbot 2442441830 fix: use the gas limit a site sends as gas (closes #207)
check / check (push) Waiting to run
e2e / e2e-chrome (push) Waiting to run
e2e / e2e-firefox (push) Waiting to run
Sites send the gas limit under its JSON-RPC name, `gas`. ethers only
reads `gasLimit`, so the field was dropped and the node's estimate was
shown and signed instead. The page's request now takes `gas` as the gas
limit, and the existing ceiling, display and comparison with the signed
transaction cover it as they already did `gasLimit`. A request that
gives both with different values is refused.

Model: opus-5-5
2026-10-14 13:48:52 +02:00
clawbot f1a13a50a6 fix: the defective xprv wallet notice names the keys that still reach its addresses (closes #255)
check / check (push) Waiting to run
e2e / e2e-chrome (push) Waiting to run
e2e / e2e-firefox (push) Waiting to run
The notice told the user that these addresses are reachable by software
that repeats the same derivation, while the same wallet blocks Export
Private Key, so there was no way to take that route from here. The
second paragraph now names private key export among the disabled
controls and says the addresses can be reached outside this wallet with
the extended private key the user imported, if they kept a copy of it,
or with the master extended private key or recovery phrase it came
from. No behaviour changes. A test checks the new wording.

Model: opus-5-5
2026-10-14 11:48:46 +02:00
6 changed files with 146 additions and 23 deletions
+5 -1
View File
@@ -2075,7 +2075,11 @@ view would leave a wallet one click from deletion.
artifact can be compared with it field for field. A nonce the site supplies is artifact can be compared with it field for field. A nonce the site supplies is
ignored: the nonce is always the account's next nonce from the node, so a site ignored: the nonce is always the account's next nonce from the node, so a site
cannot replace one of the user's pending transactions or leave this one stuck cannot replace one of the user's pending transactions or leave this one stuck
behind a gap. A request that cannot be populated — unreachable node, reverting behind a gap. A gas limit the site supplies, as `gas` or `gasLimit`, is the
one shown and signed in place of the node's estimate, but the node still
estimates the transaction with that limit, as the check that it neither
reverts nor runs out of gas; a request that gives both with different values
is refused. A request that cannot be populated — unreachable node, reverting
gas estimate — opens no window and is failed back to the site. Only one gas estimate — opens no window and is failed back to the site. Only one
transaction approval exists at a time: populating fixes the nonce, so a second transaction approval exists at a time: populating fixes the nonce, so a second
`eth_sendTransaction` arriving while one is unanswered is refused with `eth_sendTransaction` arriving while one is unanswered is refused with
+53 -15
View File
@@ -1,13 +1,14 @@
// Preparation of the transaction an approval screen displays. // Preparation of the transaction an approval screen displays.
// //
// A dApp's eth_sendTransaction normally fixes only `to`, `value` and `data`. // A dApp's eth_sendTransaction normally fixes `to`, `value` and `data`, and
// The nonce, the gas limit and the fees have to be filled in from the network // sometimes the gas limit. The nonce, the fees, and the gas limit when the
// before anything can be signed, and whoever fills them in decides what the // site gives none have to be filled in from the network before anything can
// user is shown. That work used to happen in the popup, after the user had // be signed, and whoever fills them in decides what the user is shown. That
// already approved: the numbers on the approval screen came from the popup and // work used to happen in the popup, after the user had already approved: the
// were compared against nothing, so a compromised popup could display one fee // numbers on the approval screen came from the popup and were compared against
// and sign another, and the ceilings in approvalVerify.js were all that stood // nothing, so a compromised popup could display one fee and sign another, and
// between the user and a fee that hands the validator the balance. // the ceilings in approvalVerify.js were all that stood between the user and a
// fee that hands the validator the balance.
// //
// So it happens here instead, in the background, before the approval window is // So it happens here instead, in the background, before the approval window is
// opened. The background populates the transaction, shows that object, and // opened. The background populates the transaction, shows that object, and
@@ -31,6 +32,7 @@ const {
VoidSigner, VoidSigner,
accessListify, accessListify,
getAddress, getAddress,
getBigInt,
getBytes, getBytes,
hexlify, hexlify,
toQuantity, toQuantity,
@@ -47,10 +49,11 @@ const {
// minutes long, which is not a wait anyone will sit through. // minutes long, which is not a wait anyone will sit through.
const POPULATE_TIMEOUT_MS = 20000; const POPULATE_TIMEOUT_MS = 20000;
// The request fields taken from the page. Anything else is dropped rather than // The request fields taken from the page, plus `gas`, which requestFrom()
// passed to ethers: the object is page-controlled, and a future ethers that // takes as the gas limit. Anything else is dropped rather than passed to
// learns to carry a new transaction field must not start picking one up out of // ethers: the object is page-controlled, and a future ethers that learns to
// it without this module knowing. // carry a new transaction field must not start picking one up out of it
// without this module knowing.
// //
// The nonce is not taken from the page; it is always the account's next nonce // The nonce is not taken from the page; it is always the account's next nonce
// from the network. A page that chose it could replace one of the user's // from the network. A page that chose it could replace one of the user's
@@ -84,6 +87,16 @@ function present(v) {
return v !== null && v !== undefined && v !== ""; return v !== null && v !== undefined && v !== "";
} }
// Whether two quantities from the page are the same number. One that is not a
// number matches nothing.
function sameQuantity(a, b) {
try {
return getBigInt(a) === getBigInt(b);
} catch {
return false;
}
}
// These strings reach the user through the requesting page, so they are full // These strings reach the user through the requesting page, so they are full
// sentences even when the tail of one came from ethers or from the node. // sentences even when the tail of one came from ethers or from the node.
function sentence(text) { function sentence(text) {
@@ -111,6 +124,20 @@ function requestFrom(txParams, from) {
for (const key of REQUEST_FIELDS) { for (const key of REQUEST_FIELDS) {
if (present(txParams[key])) request[key] = txParams[key]; if (present(txParams[key])) request[key] = txParams[key];
} }
// JSON-RPC calls the gas limit `gas`, and that is the name sites send.
// ethers only reads `gasLimit`: left as `gas` it would be dropped and an
// estimate signed in its place.
if (present(txParams.gas)) {
if (
present(request.gasLimit) &&
!sameQuantity(request.gasLimit, txParams.gas)
) {
throw fail(
"The site asked for two different gas limits for this transaction.",
);
}
request.gasLimit = txParams.gas;
}
if ( if (
present(request.type) && present(request.type) &&
!ALLOWED_TX_TYPES.includes(Number(request.type)) !ALLOWED_TX_TYPES.includes(Number(request.type))
@@ -174,6 +201,7 @@ async function prepareApprovalTx(provider, from, txParams) {
throw fail("There is no active address to send this transaction from."); throw fail("There is no active address to send this transaction from.");
} }
const request = requestFrom(txParams || {}, from); const request = requestFrom(txParams || {}, from);
const signer = new VoidSigner(getAddress(from), provider);
let populated; let populated;
try { try {
@@ -181,10 +209,20 @@ async function prepareApprovalTx(provider, from, txParams) {
// nonce, gas, fee and chain id are populated exactly as they were when // nonce, gas, fee and chain id are populated exactly as they were when
// the popup did this. VoidSigner cannot sign, which is the point: the // the popup did this. VoidSigner cannot sign, which is the point: the
// background prepares, the popup signs. // background prepares, the popup signs.
//
// ethers asks the node for a gas estimate only when the request has
// no gas limit, and that estimate is the only check that the
// transaction does not revert. So a request carrying the site's gas
// limit is estimated first, with that limit: one that reverts, or
// needs more gas than the site gave it, fails here as well. The
// site's gas limit is still the one populated.
populated = await withTimeout( populated = await withTimeout(
new VoidSigner(getAddress(from), provider).populateTransaction( (async () => {
request, if (present(request.gasLimit)) {
), await signer.estimateGas(request);
}
return signer.populateTransaction(request);
})(),
POPULATE_TIMEOUT_MS, POPULATE_TIMEOUT_MS,
"The transaction could not be prepared: the network did not answer in time.", "The transaction could not be prepared: the network did not answer in time.",
); );
+7 -5
View File
@@ -36,11 +36,13 @@ const DEFECTS = {
"derivation path beneath that key instead of from a master " + "derivation path beneath that key instead of from a master " +
"key, so the addresses listed here are not the ones that key " + "key, so the addresses listed here are not the ones that key " +
"produces under the standard path.", "produces under the standard path.",
"Signing and sending are disabled for this wallet. The addresses " + "Signing, sending and private key export are disabled for this " +
"do descend from the extended private key you imported, so " + "wallet. Anything these addresses hold can be reached outside " +
"anything they hold is still reachable by software that " + "this wallet with the extended private key you imported, if " +
"repeats the same non-standard derivation. Check them in a " + "you kept a copy of it, or with the master extended private " +
"block explorer before deciding what to do.", "key or recovery phrase it came from, in software that " +
"repeats the same non-standard derivation. Check the " +
"addresses in a block explorer before deciding what to do.",
"To see the addresses this key produces under the standard path, " + "To see the addresses this key produces under the standard path, " +
"import the master extended private key, or the recovery " + "import the master extended private key, or the recovery " +
"phrase it came from, as a new wallet. Nothing here has been " + "phrase it came from, as a new wallet. Nothing here has been " +
+69 -1
View File
@@ -9,7 +9,7 @@
// requesting page or the RPC node can say turns it into an approval that // requesting page or the RPC node can say turns it into an approval that
// should never have been raised. // should never have been raised.
const { Network, Wallet } = require("ethers"); const { Network, Transaction, Wallet, toQuantity } = require("ethers");
const { const {
prepareApprovalTx, prepareApprovalTx,
serializeApprovedTx, serializeApprovedTx,
@@ -138,6 +138,49 @@ describe("prepareApprovalTx", () => {
expect(approved.maxFeePerGas).toBe("0x12a05f200"); expect(approved.maxFeePerGas).toBe("0x12a05f200");
}); });
// `gas` is the JSON-RPC name for the gas limit and the one sites send.
// The node is still asked for its estimate, with the site's gas limit,
// because the estimate is the check that the transaction does not revert.
// It estimates 21000; the site's 200000 is what is shown and what is
// signed.
test("uses the gas limit a site sends as gas", async () => {
const estimateGas = jest.fn(async () => 21000n);
const approved = await prepareApprovalTx(
providerWith({ estimateGas }),
signer.address,
{ ...TX_PARAMS, gas: "0x30d40" },
);
expect(estimateGas).toHaveBeenCalledWith(
expect.objectContaining({ gasLimit: 200000n }),
);
expect(approved.gasLimit).toBe("0x30d40");
const signed = Transaction.from(
await signer.signTransaction({ ...approved }),
);
expect(signed.gasLimit).toBe(200000n);
});
test("accepts gas and gasLimit that name the same number", async () => {
const approved = await prepareApprovalTx(
providerWith(),
signer.address,
{ ...TX_PARAMS, gas: "0x30d40", gasLimit: 200000 },
);
expect(approved.gasLimit).toBe("0x30d40");
});
test("refuses gas and gasLimit that disagree", async () => {
await expect(
prepareApprovalTx(providerWith(), signer.address, {
...TX_PARAMS,
gas: "0x30d40",
gasLimit: "0x5208",
}),
).rejects.toThrow(
"The site asked for two different gas limits for this transaction.",
);
});
test("carries an access list the request asked for", async () => { test("carries an access list the request asked for", async () => {
const approved = await prepareApprovalTx( const approved = await prepareApprovalTx(
providerWith(), providerWith(),
@@ -212,6 +255,15 @@ describe("prepareApprovalTx", () => {
).rejects.toThrow(/gas limit no network this wallet supports/); ).rejects.toThrow(/gas limit no network this wallet supports/);
}); });
test("refuses a gas limit the site sent above the ceiling", async () => {
await expect(
prepareApprovalTx(providerWith(), signer.address, {
...TX_PARAMS,
gas: toQuantity(MAX_GAS_LIMIT + 1n),
}),
).rejects.toThrow(/gas limit no network this wallet supports/);
});
// The combined bound at population: a gas limit and a fee that are each // The combined bound at population: a gas limit and a fee that are each
// under their own ceiling but multiply to thousands of ETH is refused // under their own ceiling but multiply to thousands of ETH is refused
// before the approval window opens, so the user is never shown a // before the approval window opens, so the user is never shown a
@@ -251,6 +303,22 @@ describe("prepareApprovalTx", () => {
expect(thrown.message).toMatch(/^[A-Z].*\.$/); expect(thrown.message).toMatch(/^[A-Z].*\.$/);
}); });
test("fails back a reverting request that sends its own gas limit", async () => {
const reverting = providerWith({
estimateGas: async () => {
throw new Error("execution reverted: ERC20: transfer amount");
},
});
await expect(
prepareApprovalTx(reverting, signer.address, {
...TX_PARAMS,
gas: "0x30d40",
}),
).rejects.toThrow(
/^The transaction could not be prepared: execution reverted/,
);
});
// Without a bound, an unreachable node leaves the page's promise pending // Without a bound, an unreachable node leaves the page's promise pending
// with nothing on screen to explain it. // with nothing on screen to explain it.
test("gives up on a node that never answers", async () => { test("gives up on a node that never answers", async () => {
-1
View File
@@ -58,7 +58,6 @@ const TX_PARAMS = {
to: RECIPIENT, to: RECIPIENT,
value: "0x2386f26fc10000", value: "0x2386f26fc10000",
data: "0xdeadbeef", data: "0xdeadbeef",
gas: "0x5208",
}; };
// The values populateTransaction() fills in when the dApp fixed none of them. // The values populateTransaction() fills in when the dApp fixed none of them.
+12
View File
@@ -153,6 +153,18 @@ describe("the explanatory copy", () => {
expect(all).not.toMatch(/\blost\b|\bstolen\b|\bgone\b/i); expect(all).not.toMatch(/\blost\b|\bstolen\b|\bgone\b/i);
}); });
// The wallet holds the imported key but will not export it, so the copy
// must name every key the user may hold that reaches the addresses
// outside it.
test("it names the keys that reach the addresses outside this wallet", () => {
const body = defect.paragraphs.join(" ");
expect(body).toMatch(/private key export are disabled/);
expect(body).toMatch(
/with the extended private key you imported, if you kept a copy of it, or with the master extended private key or recovery phrase it came from, in software that repeats the same non-standard derivation/,
);
});
test("it says the wallet is not deleted and what the user can do", () => { test("it says the wallet is not deleted and what the user can do", () => {
const body = defect.paragraphs.join(" "); const body = defect.paragraphs.join(" ");