-
Notifications
You must be signed in to change notification settings - Fork 46
Audit fixes 1-4 and BLSWalletWrapper changes #350
Conversation
// eslint-disable-next-line camelcase | ||
VerificationGateway__factory, | ||
} from "../typechain"; | ||
} from "../../typechain"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is reaching out to contracts/typechain
which is incorrect. contracts/clients
needs to be self-contained so that it can be published on npm. contracts/clients/typechain
in the repo is a symlink to contracts/typechain
. (Replacing the symlink dir with the actual content occurs during build.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed in #351
const walletContract = BLSWallet__factory.connect( | ||
contractAddress, | ||
provider, | ||
await blsWalletWrapper.syncWallet(verificationGateway); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the syncWallet
here is redundant since the latest address information is gathered above during await BlsWalletWrapper.BLSWallet(privateKey, verificationGateway)
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is currently only being used in the should recover before bls key update
contracts test when recovering to a different key, so this still may be needed during the recovery workflow to keep non-async properties of BlsWalletWrapper
up to date with their on-chain values.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Confirmed, removing that syncWallet
call fails the test Error: VM Exception while processing transaction: reverted with reason string 'VG: Sig not verified'
@@ -25,6 +25,8 @@ export default (domain: Uint8Array, chainId: number) => | |||
BigNumber.from(n2).toHexString(), | |||
BigNumber.from(n3).toHexString(), | |||
]), | |||
bundle.operations.map(encodeMessageForSigning(chainId)), | |||
bundle.operations.map((op, i) => |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick: Unused variable i
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed
for (uint256 i=0; i<32; i++) { | ||
if (i<4) { | ||
selectorId |= bytes4(encodedFunction[i]) >> i*8; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you sure this is the correct shift direction? Usually you'd shift left in this situation (to move a byte into the more significant location, since <<
, >>
follows big endian convention, even on modern architectures that are usually little endian).
I can see how it might be inverted for bytes4
... curious.
It might be better to use uint32
for the arithmetic and then cast to bytes4
after?
contracts/shared/helpers/Fixture.ts
Outdated
bundleFrom( | ||
async bundleFrom( | ||
wallet: BlsWalletWrapper, | ||
contract: Contract, | ||
method: string, | ||
params: any[], | ||
nonce: BigNumberish, | ||
ethValue: BigNumberish = 0, | ||
): Bundle { | ||
): Promise<Bundle> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unnecessary async conversion here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed
contracts/shared/helpers/Fixture.ts
Outdated
@@ -187,7 +189,14 @@ export default class Fixture { | |||
) { | |||
await ( | |||
await this.verificationGateway.processBundle( | |||
this.bundleFrom(wallet, contract, method, params, nonce, ethValue), | |||
await this.bundleFrom( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After fixing bundleFrom
, you shouldn't need await
here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed
contracts/shared/helpers/Fixture.ts
Outdated
@@ -201,7 +210,7 @@ export default class Fixture { | |||
ethValue: BigNumberish = 0, | |||
) { | |||
return await this.verificationGateway.callStatic.processBundle( | |||
this.bundleFrom(wallet, contract, method, params, nonce, ethValue), | |||
await this.bundleFrom(wallet, contract, method, params, nonce, ethValue), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As above.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few things, mostly minor.
I don't see any new tests covering the critical changes that have been made:
Not that we're strict about always automating these things, but they should be manually tested. Have you manually tested them? (In particular, my question about the shift direction could be resolved by a manual test.) |
Two ways I can see us finishing this up:
I am fine with either. |
Update aggregator BundleService to work with new signature payload which includes wallet address.
@@ -1,6 +1,6 @@ | |||
{ | |||
"name": "bls-wallet-clients", | |||
"version": "0.7.3", | |||
"version": "0.8.0", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@voltrevo Given contract changes, especially signed payload format w/ wallet address I bumped the minor to indicate a breaking change.
Remaining Tasks
Manual Testing
Automated testing (contracts)
|
@jacque006 Was there a decision made on how to move forward with this PR? Asking because I'll need the BLSWalletWrapper changes in order to get wallet recovery working end to end. Also, if there's anywhere I can help out with this let me know. I'm happy to jump in anywhere if I can. |
@blakecduncan Yes, it was decided to merge into If you need the wrapper changes now, you can use Would love your help testing the extension when we move to testing before |
@@ -248,4 +285,52 @@ describe("Recovery", async function () { | |||
.recoverWallet(addressSignature, hashAttacker, salt, wallet1Key), | |||
).to.be.rejectedWith("VG: Signature not verified for wallet address"); | |||
}); | |||
|
|||
it("should NOT allow a bundle to be executed on a wallet with the same BLS pubkey but different address (replay attack)", async function () { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this covers A bundle signed for a different address cannot be replayed onto a wallet with the same bls key
test case that was needed, but it is difficult to tell as this key switch via recovery will de-register the first wallet with that pubkey.
Add getOperationResults to bls-wallet-clients to allow consumers to more easily get at operation errors. Change existing test case to use getOperationResults. Add message to require used to prevent ownership changes to proxy admin.
#366 will be pulled in to replace latest commit after merge to |
After discussion with @jzaki , decided to merge early to |
What is this PR doing?
Fixes audit points 1-4, and the latest commit has updates to BLSWalletWrapper to handle changing addresses referred to by a key.
How can these changes be manually tested?
yarn hardhat test
insidecontracts
Does this PR resolve or contribute to any issues?
Related to PR #340
closes #287
Checklist
Guidelines
resolve conversation
button is for reviewers, not authors