Skip to content

Commit

Permalink
Prevent unconfigured ENS names from making an init tx (#1290).
Browse files Browse the repository at this point in the history
  • Loading branch information
ricmoo committed Feb 12, 2021
1 parent 3a76d69 commit 243beff
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
11 changes: 10 additions & 1 deletion packages/abstract-signer/src.ts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,16 @@ export abstract class Signer {

const tx: Deferrable<TransactionRequest> = await resolveProperties(this.checkTransaction(transaction))

if (tx.to != null) { tx.to = Promise.resolve(tx.to).then((to) => this.resolveName(to)); }
if (tx.to != null) {
tx.to = Promise.resolve(tx.to).then(async (to) => {
if (to == null) { return null; }
const address = await this.resolveName(to);
if (address == null) {
logger.throwArgumentError("provided ENS name resolves to null", "tx.to", to);
}
return address;
});
}
if (tx.gasPrice == null) { tx.gasPrice = this.getGasPrice(); }
if (tx.nonce == null) { tx.nonce = this.getTransactionCount("pending"); }

Expand Down
31 changes: 31 additions & 0 deletions packages/tests/src.ts/test-providers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1113,3 +1113,34 @@ describe("Test Events", function() {
await testBlockEvent(provider);
});
});

describe("Bad ENS resolution", function() {
const provider = providerFunctions[0].create("ropsten");

it("signer has a bad ENS name", async function() {
this.timeout(300000);

const wallet = new ethers.Wallet(ethers.utils.id("random-wallet"), provider);

// If "to" is specified as an ENS name, it cannot resolve to null
try {
const tx = await wallet.sendTransaction({ to: "junk", value: 1 });
console.log("TX", tx);
} catch (error) {
assert.ok(error.argument === "tx.to" && error.value === "junk");
}

// But promises that resolve to null are ok
const tos = [ null, Promise.resolve(null) ];
for (let i = 0; i < tos.length; i++) {
const to = tos[i];
try {
const tx = await wallet.sendTransaction({ to, value: 1 });
console.log("TX", tx);
} catch (error) {
assert.ok(error.code === "INSUFFICIENT_FUNDS");
}
}
});

});

0 comments on commit 243beff

Please sign in to comment.