Skip to content

Commit

Permalink
Prevent Signer.checkTransaction from creating conflicting from proper…
Browse files Browse the repository at this point in the history
…ties.
  • Loading branch information
ricmoo committed Feb 1, 2020
1 parent ba29618 commit 1decb13
Showing 1 changed file with 33 additions and 3 deletions.
36 changes: 33 additions & 3 deletions packages/abstract-signer/src.ts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,22 @@ export abstract class Signer {
}

const tx = shallowCopy(transaction);
if (tx.from == null) { tx.from = this.getAddress(); }

if (tx.from == null) {
tx.from = this.getAddress();
} else {
// Make sure any provided address matches this signer
tx.from = Promise.all([
Promise.resolve(tx.from),
this.getAddress()
]).then((result) => {
if (result[0] !== result[1]) {
logger.throwArgumentError("from address mismatch", "transaction", transaction);
}
return result[0];
});
}

return tx;
}

Expand All @@ -152,7 +167,8 @@ export abstract class Signer {
if (tx.gasPrice == null) { tx.gasPrice = this.getGasPrice(); }
if (tx.nonce == null) { tx.nonce = this.getTransactionCount("pending"); }

// Make sure any provided address matches this signer
/*
// checkTransaction does this...
if (tx.from == null) {
tx.from = this.getAddress();
} else {
Expand All @@ -166,6 +182,7 @@ export abstract class Signer {
return results[0];
});
}
*/

if (tx.gasLimit == null) {
tx.gasLimit = this.estimateGas(tx).catch((error) => {
Expand All @@ -174,7 +191,20 @@ export abstract class Signer {
});
});
}
if (tx.chainId == null) { tx.chainId = this.getChainId(); }

if (tx.chainId == null) {
tx.chainId = this.getChainId();
} else {
tx.chainId = Promise.all([
Promise.resolve(tx.chainId),
this.getChainId()
]).then((results) => {
if (results[1] !== 0 && results[0] !== results[1]) {
logger.throwArgumentError("chainId address mismatch", "transaction", transaction);
}
return results[0];
});
}

return await resolveProperties(tx);
}
Expand Down

0 comments on commit 1decb13

Please sign in to comment.