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

AllowanceHolder Use top-level calldata for authentication and avoid Permit2 ecrecover and nonce cancellation PRO-73 #25

Merged
merged 121 commits into from
Jan 3, 2024

Conversation

duncancmt
Copy link
Collaborator

@duncancmt duncancmt commented Aug 23, 2023

This PR also cleans up some assembly that wasn't safe for 0.8

closes #11

@duncancmt duncancmt self-assigned this Aug 23, 2023
@linear
Copy link

linear bot commented Aug 23, 2023

PRO-73 Exploit EIP-1153 transient storage for gas efficiency in taker-submitted OTC

Presently, due to the gas overhead of having to redeem 2 Permit2 coupons, OTC through 0xV5 is not as gas efficient as the latest 4th-generation AMMs. We only have ~30k gas to work with, which is quite challenging.

Using EIP-1153 transient storage and re-using the transaction signature (the 21k inherent gas) for authentication would help us achieve that. In essence, we'd make a version of Permit2 that uses msg.sender for authentication instead of a coupon.

@duncancmt duncancmt changed the title Use top-level calldata for authentication and avoid Permit2 ecrecover and nonce cancellation PRO-73 [WIP] Use top-level calldata for authentication and avoid Permit2 ecrecover and nonce cancellation PRO-73 Aug 23, 2023
@duncancmt duncancmt changed the base branch from master to permit2_unification September 6, 2023 15:46
Base automatically changed from permit2_unification to master September 7, 2023 15:06
duncancmt and others added 27 commits November 30, 2023 12:23
…e key with validation in holderTransferFrom (#51)

Rather than assume `tx.origin` is the owner during `holderTransferFrom`,
we can validate the `holderTransferFrom` params by using `hash(operator,
owner,token)` as the key for the ephemeral allowance.

`tx.origin` is completely removed, which removes the need for
`moveExecute` as contracts can use this function.
`operator` is included in the ephemeral key and the storage of this
value is removed.

In the case of malicious usage, ephemeral allowance key existence is the
protection and a key miss results in a revert.
* swapping out `owner` would result in a ephemeral allowance miss
(different owner)
* attacking from a different malicious contract would result in a
ephemeral allowance miss (different operator)
* swapping out `token` would result in a ephemeral allowance miss (same
as before)

Replaces #50
…e `AllowanceHolder` gas snapshotting (#49)

Rather than assume `tx.origin` is the owner during `holderTransferFrom`,
we can validate the `holderTransferFrom` params by using `hash(operator,
owner,token)` as the key for the ephemeral allowance.

`tx.origin` is completely removed, which removes the need for
`moveExecute` as contracts can use this function.
`operator` is included in the ephemeral key and the storage of this
value is removed.

In the case of malicious usage, ephemeral allowance key existence is the
protection and a key miss results in a revert.
* swapping out `owner` would result in a ephemeral allowance miss
(different owner)
* attacking from a different malicious contract would result in a
ephemeral allowance miss (different operator)
* swapping out `token` would result in a ephemeral allowance miss (same
as before)

Replaces #50 


I wonder is the reason that `AllowanceHolder` is less than 5k gas
cheaper than `Permit2` is due to the overhead in decoding calldata
arrays? We know that `Permit2` adds an extra ~4k gas when batch is used.
@dekz dekz marked this pull request as ready for review January 3, 2024 22:56
@dekz dekz merged commit 1273617 into gas Jan 3, 2024
4 checks passed
@dekz dekz deleted the eip1153_vip branch January 3, 2024 22:58
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.

msg.sender-authenticated VIP for OTC PRO-73
2 participants