Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sign Message: allow v1 accs to sign anything if OG mode is activated #1334

Open
wants to merge 5 commits into
base: v2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/controllers/main/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -802,7 +802,7 @@ export class MainController extends EventEmitter {
return this.emitError({ level: 'major', message, error })
}

await this.signMessage.sign()
await this.signMessage.sign(this.invite.isOG)

const signedMessage = this.signMessage.signedMessage
// Error handling on the prev step will notify the user, it's fine to return here
Expand Down
12 changes: 7 additions & 5 deletions src/controllers/signMessage/signMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ export class SignMessageController extends EventEmitter {
this.emitUpdate()
}

async #sign() {
async #sign(isOG = false) {
if (!this.isInitialized) {
return SignMessageController.#throwNotInitialized()
}
Expand Down Expand Up @@ -171,7 +171,8 @@ export class SignMessageController extends EventEmitter {
network,
account,
accountState,
this.#signer
this.#signer,
isOG
)
}

Expand All @@ -187,7 +188,8 @@ export class SignMessageController extends EventEmitter {
account,
accountState,
this.#signer,
network
network,
isOG
)
}
} catch (error: any) {
Expand Down Expand Up @@ -261,8 +263,8 @@ export class SignMessageController extends EventEmitter {
}
}

async sign() {
await this.withStatus('sign', async () => this.#sign())
async sign(isOG = false) {
await this.withStatus('sign', async () => this.#sign(isOG))
}

removeAccountData(address: Account['addr']) {
Expand Down
41 changes: 28 additions & 13 deletions src/libs/signMessage/signMessage.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -292,23 +292,38 @@ describe('Sign Message, Keystore with key dedicatedToOneSA: true ', () => {
}
})

test('Signing [V1 SA]: plain text, should throw an error as it disallowed to sign message with contains address in it on unsupported chain', async () => {
const accountStates = await getAccountsInfo([v1Account])
test('Signing [V1 SA]: disallowed plain text, but with OG mode', async () => {
const signer = await keystore.getSigner(v1siger.keyPublicAddress, 'internal')
const accountStates = await getAccountsInfo([v1Account])

await expect(
getPlainTextSignature(
`test with address in the message on unsupported chain: ${v1Account.addr}`,
unsupportedNetwork,
v1Account,
accountStates[v1Account.addr][ethereumNetwork.id],
signer
)
).rejects.toThrow(
`Signing messages is disallowed for v1 accounts on ${unsupportedNetwork.name}`
const accountState = accountStates[v1Account.addr][ethereumNetwork.id]

const plaintextSigNoAddrInMessage = await getPlainTextSignature(
'test',
ethereumNetwork,
v1Account,
accountState,
signer,
true
)
})

const typedData = getTypedData(
ethereumNetwork.chainId,
v1siger.keyPublicAddress, // this is the difference
hashMessage('test')
)
const typedSigNoAddrInMessage = await getEIP712Signature(
typedData,
v1Account,
accountState,
signer,
polygonNetwork,
true
)

expect(plaintextSigNoAddrInMessage).toBeTruthy()
expect(typedSigNoAddrInMessage).toBeTruthy()
})
test('Signing [EOA]: eip-712', async () => {
const accountStates = await getAccountsInfo([eoaAccount])
const accountState = accountStates[eoaAccount.addr][ethereumNetwork.id]
Expand Down
45 changes: 22 additions & 23 deletions src/libs/signMessage/signMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,8 @@ export async function getPlainTextSignature(
network: Network,
account: Account,
accountState: AccountOnchainState,
signer: KeystoreSigner
signer: KeystoreSigner,
isOG = false
): Promise<string> {
const dedicatedToOneSA = signer.key.dedicatedToOneSA

Expand Down Expand Up @@ -426,23 +427,17 @@ export async function getPlainTextSignature(
)

if (
!network.predefined &&
!relayerAdditionalNetworks.find((net) => net.chainId === network.chainId)
!isOG &&
!isAsciiAddressInMessage &&
!isLowercaseHexAddressInMessage &&
!isChecksummedHexAddressInMessage
) {
throw new Error(`Signing messages is disallowed for v1 accounts on ${network.name}`)
}

if (
isAsciiAddressInMessage ||
isLowercaseHexAddressInMessage ||
isChecksummedHexAddressInMessage
) {
return wrapUnprotected(await signer.signMessage(messageHex))
throw new Error(
'Signing messages is disallowed for v1 accounts. Please contact support to proceed'
)
}

throw new Error(
'Signing messages is disallowed for v1 accounts. Please contact support to proceed'
)
return wrapUnprotected(await signer.signMessage(messageHex))
}

// if it's safe, we proceed
Expand All @@ -465,7 +460,8 @@ export async function getEIP712Signature(
account: Account,
accountState: AccountOnchainState,
signer: KeystoreSigner,
network: Network
network: Network,
isOG = false
): Promise<string> {
if (!message.types.EIP712Domain) {
throw new Error(
Expand All @@ -486,21 +482,24 @@ export async function getEIP712Signature(
if (!accountState.isV2) {
const asString = JSON.stringify(message).toLowerCase()
if (
asString.indexOf(account.addr.toLowerCase()) !== -1 ||
(message.domain.name === 'Permit2' &&
!isOG &&
!asString.includes(account.addr.toLowerCase()) &&
!(
message.domain.name === 'Permit2' &&
message.domain.verifyingContract &&
getAddress(message.domain.verifyingContract) === PERMIT_2_ADDRESS &&
message.message &&
message.message.spender &&
UNISWAP_UNIVERSAL_ROUTERS[Number(network.chainId)] &&
UNISWAP_UNIVERSAL_ROUTERS[Number(network.chainId)] === getAddress(message.message.spender))
UNISWAP_UNIVERSAL_ROUTERS[Number(network.chainId)] === getAddress(message.message.spender)
)
) {
return wrapUnprotected(await signer.signTypedData(message))
throw new Error(
'Signing this eip-712 message is disallowed for v1 accounts as it does not contain the smart account address and therefore deemed unsafe'
)
}

throw new Error(
'Signing this eip-712 message is disallowed for v1 accounts as it does not contain the smart account address and therefore deemed unsafe'
)
return wrapUnprotected(await signer.signTypedData(message))
}

// we do not allow signers who are not dedicated to one account to sign eip-712
Expand Down