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

Add Batch Sig Algorithm #175

Closed
wants to merge 1 commit into from
Closed

Add Batch Sig Algorithm #175

wants to merge 1 commit into from

Conversation

hayesgm
Copy link
Contributor

@hayesgm hayesgm commented Mar 4, 2024

This patch adds a batch signature algorithm, by allowing a signer to pass in a pre-pad and post-pad. When those exist, we verify keccak(prepad • eip712_keccak • postpad). We posit that this allows us to sign two EIP-712 signatures with a single digital signature. Specifically, the user will sign keccak(eip712_keccak_0, eip712_keccak_1). Then when we want to verify the first one, we pass in the quark operation with a prepad="" postpad=eip712_keccak_1. To verify the second signature, we pass in the second quark operation with prepad=eip712_keccak_0 and postpad="". We posit that this is safe and effective.

As a note: we do not run the double keccak if prepad="" postpad="" to allow standard EIP-712 signatures to be normal.

This patch adds a batch signature algorithm, by allowing a signer to pass in a pre-pad and post-pad. When those exist, we verify `keccak(prepad • eip712_keccak • postpad)`. We posit that this allows us to sign two EIP-712 signatures with a single digital signature. Specifically, the user will sign `keccak(eip712_keccak_0, eip712_keccak_1)`. Then when we want to verify the first one, we pass in the quark operation with a prepad="" postpad=eip712_keccak_1. To verify the second signature, we pass in the second quark operation with prepad=eip712_keccak_0 and postpad="". We posit that this is safe and effective.

As a note: we do not run the double keccak if prepad="" postpad="" to allow standard EIP-712 signatures to be normal.
Copy link
Contributor

@cwang25 cwang25 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some solidity lint seems failing. But lgtm.

I'm still wrapping my head around the scenarios. 😄
So user can sign one signatures, and be executed multiple times based on how many "real" signature is embedded in the signaure and iterating based on pre-pad post-pad 🤔

@kevincheng96
Copy link
Collaborator

Cool idea and your postulates seem correct. Nice to see that this would work even for two transactions on different chains.

In terms of improvements, I think we can extend this to batch more than 2 transactions by taking a list of EIP712_keccaks and an index. It will be slightly more work to track the indices, but I think that design is more flexible and intuitive than "prepad/postpad".

Copy link
Collaborator

@fluffywaffles fluffywaffles left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I promote ⛑️ 's suggestions, it would be good to see a healthy discussion about the ux of this approach and whether it can be better. (while keeping it to a reasonable added cost)

However, I will consider that non-blocking. Overall LGTM on CI fixes, which look like they should be easy.

kevincheng96 added a commit that referenced this pull request Mar 22, 2024
A different flavor of Batch sigs (#175).

`MultiQuarkOperation`s allows a signer to sign a single digest to execute multiple Quark Operations on any number of wallets owned by the signer on any number of chains. The most practical application of this is cross-chain operations, such as "Bridge USDC from mainnet to Base -> Supply USDC to a lending protocol on Base". 

`MultiQuarkOperation` signatures conform to EIP-712. This means that it has its own typehash and domain separator. The domain separator is special in that it does not include `chainId` and `verifyingContract`. This is to enable a single `MultiQuarkOperation` to support operations spanning different wallets and chains. This is safe because each `opsDigest` in the `MultiQuarkOperation` is already scoped to a specific `chainId` and `verifyingContract`, since each of these are a EIP-712 digest for a `QuarkOperation`.
@kevincheng96
Copy link
Collaborator

Closing in favor of #186

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants