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

Update branch with main commits #25

Merged
merged 55 commits into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
c78f4a0
Update README.md
0age Oct 31, 2024
9980d5b
Update EIP712Types.sol
0age Oct 31, 2024
894012a
improve inheritance graph
0age Oct 31, 2024
bbea6e4
Merge pull request #12 from Uniswap/shuffle-city
0age Oct 31, 2024
2d80f4a
add inheritance graph
0age Oct 31, 2024
7d954ee
Merge pull request #13 from Uniswap/inheritance-graph
0age Oct 31, 2024
3be76c3
simplify inheritance graph by using RegistrationLib
0age Nov 1, 2024
feea25f
Merge pull request #14 from Uniswap/more-cleanup
0age Nov 1, 2024
580a4e8
add natspec to core interface; small tweaks to metadata renderer and …
0age Nov 1, 2024
57b825f
add top-level natspec description to ITheCompactClaims
0age Nov 1, 2024
d3642c0
add more top-level natspec
0age Nov 1, 2024
4663588
Merge pull request #15 from Uniswap/natspec
0age Nov 1, 2024
591a1b3
start adding comments + natspec to functions and add ClaimProcessorLib
0age Nov 2, 2024
2713e22
Merge pull request #16 from Uniswap/more-natspec
0age Nov 2, 2024
515d1bc
natspec on a few more contracts
0age Nov 2, 2024
22d01da
do DepositLogic
0age Nov 2, 2024
1e2ecfd
add natspec to SharedLogic
0age Nov 2, 2024
533dd45
add natspec to WithdrawalLogic
0age Nov 2, 2024
fc21aca
add more natspec
0age Nov 2, 2024
772eb15
add natspec to TransferLogic
0age Nov 2, 2024
8672fe9
add natspec to IdLib and add a safety fix
0age Nov 3, 2024
40d0a7a
natspec to EfficiencyLib
0age Nov 3, 2024
e53f623
Merge pull request #17 from Uniswap/even-more-natspec
0age Nov 3, 2024
5f27e85
continue on hashlib cleanup
0age Nov 3, 2024
d306d74
complete generification of hashlib message hash functionality
0age Nov 3, 2024
973c13f
prep to break up lib
0age Nov 3, 2024
9731877
complete ClaimHashLib refactor
0age Nov 3, 2024
da60e21
Merge pull request #18 from Uniswap/cleanup-hashlib
0age Nov 3, 2024
37725c5
pass in domain separator as an arg
0age Nov 3, 2024
d9b1326
create EventLib for some events
0age Nov 3, 2024
1d7f917
pull logic from ClaimProcessorLogic into ClaimProcessorLib
0age Nov 3, 2024
2a6e883
clean up claim processor and claim lib
0age Nov 3, 2024
2b18148
Merge pull request #19 from Uniswap/clean-up-claim-processor
0age Nov 3, 2024
841b156
create DomainLib
0age Nov 3, 2024
ecefadc
refactor some component-based logic
0age Nov 3, 2024
d14408c
minor tweaks to HashLib
0age Nov 3, 2024
4689e81
Merge pull request #20 from Uniswap/more-libs
0age Nov 3, 2024
e125435
comment pass to HashLib
0age Nov 3, 2024
3e147d4
so many failed attempts lost like tears in the rain
0age Nov 3, 2024
bcb2df4
Merge pull request #21 from Uniswap/unused-function-casts
0age Nov 3, 2024
f26ed94
begin natspec for function casts
0age Nov 4, 2024
f363d90
start breaking up function casts
0age Nov 4, 2024
430864c
put HashLib function cast in and rename
0age Nov 4, 2024
e4a386d
finish breaking up function casts and adding natspec
0age Nov 4, 2024
cdb07f3
Merge pull request #22 from Uniswap/yet-more-natspec
0age Nov 4, 2024
4e1d696
run fmt
0age Nov 4, 2024
180e443
actually _check_ the reentrant value
0age Nov 5, 2024
4e8ec08
Merge pull request #23 from Uniswap/reentrancy-fix
0age Nov 5, 2024
0578a1b
add natspec and comments to DirectDepositLogic
0age Nov 5, 2024
d351578
create DepositViaPermit2Lib
0age Nov 5, 2024
494bfc7
natspec on DepositViaPermit2Lib.sol
0age Nov 5, 2024
c7673d0
natspec on DepositViaPermit2Logic
0age Nov 5, 2024
45257dc
Merge pull request #24 from Uniswap/deposit-natspec
0age Nov 5, 2024
fc50d50
update README
0age Nov 5, 2024
9ba2259
flesh out README a little further
0age Nov 5, 2024
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
25 changes: 22 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
## Summary
The Compact is an ownerless ERC6909 contract that facilitates the voluntary formation (and, if necessary, eventual dissolution) of reusable resource locks.

Resource locks are entered into by ERC20 or native token holders, called the _**sponsor**_. Once a resource lock has been established, sponsors can create a compact, or a commitment allowing interested parties to claim their tokens through an _**arbiter**_ indicated by the sponsor that attests to the specified conditions of the compact having been met.
Resource locks are entered into by ERC20 or native token holders, called the _**depositor**_. Once a resource lock has been established, the owner of the ERC6909 token representing a resource lock can act as a _**sponsor**_ and create a _**compact**_. A compact is a commitment allowing interested parties to claim their tokens through the sponsor's indicated _**arbiter**_. The arbiter is then responsible for processing the claim once it has attested to the specified conditions of the compact having been met.

Each resource lock is mediated by an _**allocator**_, tasked with attesting to the availability of the underlying token balances and preserving the balances required for the commitments they have attested to; in other words, an allocator ensures that sponsors do not "double-spend," transfer, or withdraw any token balances that are already committed to a specific compact.

Expand All @@ -22,7 +22,7 @@ The Compact effectively "activates" any deposited tokens to be instantly spent o

Sponsors have recourse from potential censorship in the form of a "forced withdrawal." When depositing tokens into a resource lock, the sponsor provides a "reset period" as a parameter. Then, the sponsor can initiate a forced withdrawal at any point; after the reset period has elapsed, the full token balance can be withdrawn regardless of any pending claims on their balance. In the case of cross-chain swaps, reset periods only need to be long enough for the claim to finalize (generally some multiple of the slowest blockchain involved in the swap).

Claimants must bear varying degrees of trust assumptions with regards to allocators, with the potential design space including reputation-based systems, trusted execution environments, smart-contract-based systems, or even dedicated rollups. The Compact takes a neutral stance on implementations of both allocators and arbiters, and instead treats them both as a "black box" but each with a simple and consistent interface.
Claimants must bear varying degrees of trust assumptions with regards to allocators, with the potential design space including reputation-based systems, trusted execution environments, smart-contract-based systems, or even dedicated rollups. The Compact takes a neutral stance on implementations of both allocators and arbiters, enabling support for a wide variety of potential applications while ensuring adherence to a consistent interface when integrating with the system as a whole.

## Setup
```
Expand Down Expand Up @@ -655,7 +655,7 @@ interface ICompactMultichainClaims {
### 4d) Multiple Resource Lock Claim on Multiple Chains
Finally, there are thirty-two claim endpoints to cover cases where the sponsor is utilizing multiple resource locks against multiple chains where one or more chains contain more than one resource lock; these also utilize a `MultichainCompact` EIP-712 payload, but the `Allocation` structs can contain `idsAndAmounts` arrays of arbitrary length.

```
```solidity
struct BatchMultichainClaim {
bytes allocatorSignature; // Authorization from the allocator.
bytes sponsorSignature; // Authorization from the sponsor.
Expand Down Expand Up @@ -713,3 +713,22 @@ In addition to standard ERC6909 view functions, The Compact includes the followi
- `check` determines if a given nonce has been consumed for a given allocator (note that nonces are scoped to allocators, not sponsors).
- `DOMAIN_SEPARATOR` returns the hash of the EIP-712 domain data for the chain in question.
- `name` returns the name of the contract.


## Contract Layout
The Compact is primarily represented by a single deployed contract, with the exception of a metadata renderer that it calls to retrieve information on ERC6909 tokenURI metadata for resource locks. The deployed contract is comprised of multiple inherited logic contracts which in turn make extensive use of various library contracts. A shared set of struct and enum types are utilized throughout the codebase and as a component in many function interfaces.

![TheCompact Inheritance Graph](images/TheCompact-Inheritance-Graph.png)

The core interface is divided into two parts: one designed to be called by depositors, allocators, and other general-purpose entities, and one designed to be called by arbiters as part of processing claims.

## The Path to V1
The Compact is currently in _**Version 0**_ — this version is meant to serve as a fully-featured proof-of-concept so that development of contracts and infrastructure related to arbiters and allocators can commence in earnest.

> Important reminder: Version 0 lacks rigorous testing, review, or audits. Exercise caution and prudence when interacting with it until it has reached a more mature state. Version 1 will incorporate various bugfixes and improvements informed by integration with additional actors in the system and by more extensive scrutiny of its security.

Candidate features for Version 1 to consider when reviewing or integrating with Version 0 include:
- Revising the interface between The Compact and allocators — currently, allocators authorize claims via direct calls (i.e. arbiter == allocator), ECDSA signatures, or EIP-1271 `isValidSignature(bytes32 domainHash, bytes signature) external view` calls. This may prove overly restrictive for many use-cases, including fully onchain varieties of allocator (especially when the allocator and the arbiter are not the same entity). Alternatives to consider include a stateful callback and/or the use of transient storage to register key details concerning the claim so that allocators and other actors can access them when needed.
- Revisiting function dispatch and reentrancy guard mechanics — in Version 0, function dispatch and standard solidity function ABI decoding consumes a significant amount of total gas expenditure and available contract size due to the sheer number of external functions supported. Furthermore, reentrancy guards are set and cleared on an as-needed basis, and not at the initial entrypoint to the contract. One alternative is to include a top-level fallback function with a global reentrancy lock and custom dispatch for processing claims or other external calls based on detected properties of the call.
- Reworking metadata — Version 0 implements relatively rudimentary metadata rendering. Version 1 should improve on this metadata, particularly as it relates to images and other rich metadata, without compromising on the core autonomy and reproducibility present in Version 0.
- General optimization: Version 0 already contains a significant amount of low-level code in order to succintly represent the necessary logic. Version 1 could improve on overall efficiency by implementing further optimizations and by bringing the codesize down further to allow for dialing up compiler optimization.
2 changes: 1 addition & 1 deletion foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ extra_output_files = ["irOptimized"]
# TODO: use default with everything but FunctionSpecializer (F)

[fmt]
line_length = 200
line_length = 210
tab_width = 4
bracket_spacing = true
Binary file added images/TheCompact-Inheritance-Graph.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
78 changes: 39 additions & 39 deletions snapshots/TheCompactTest.json
Original file line number Diff line number Diff line change
@@ -1,42 +1,42 @@
{
"basicTransfer": "56858",
"basicWithdrawal": "59816",
"batchClaim": "111828",
"batchClaimRegisteredWithDeposit": "111828",
"batchClaimRegisteredWithDepositWithWitness": "112590",
"batchClaimWithWitness": "112584",
"batchDepositAndRegisterViaPermit2": "221900",
"batchDepositAndRegisterWithWitnessViaPermit2": "221878",
"batchTransfer": "81536",
"batchWithdrawal": "99951",
"claim": "56975",
"claimAndWithdraw": "73266",
"claimWithWitness": "59440",
"depositAndRegisterViaPermit2": "124270",
"depositBatchSingleERC20": "67868",
"depositBatchSingleNative": "28171",
"depositBatchViaPermit2NativeAndERC20": "129592",
"depositBatchViaPermit2SingleERC20": "104746",
"depositERC20AndURI": "67117",
"depositERC20Basic": "67119",
"depositERC20ViaPermit2AndURI": "98312",
"depositETHAndURI": "26777",
"depositETHBasic": "28384",
"qualifiedBatchClaim": "113246",
"qualifiedBatchClaimWithWitness": "112710",
"qualifiedClaim": "60234",
"qualifiedClaimWithWitness": "58774",
"qualifiedSplitBatchClaim": "140934",
"qualifiedSplitBatchClaimWithWitness": "140926",
"qualifiedSplitClaim": "86521",
"qualifiedSplitClaimWithWitness": "86887",
"basicTransfer": "56867",
"basicWithdrawal": "59992",
"batchClaim": "112512",
"batchClaimRegisteredWithDeposit": "112512",
"batchClaimRegisteredWithDepositWithWitness": "113271",
"batchClaimWithWitness": "113265",
"batchDepositAndRegisterViaPermit2": "222059",
"batchDepositAndRegisterWithWitnessViaPermit2": "222037",
"batchTransfer": "81344",
"batchWithdrawal": "100093",
"claim": "56974",
"claimAndWithdraw": "73432",
"claimWithWitness": "59471",
"depositAndRegisterViaPermit2": "124429",
"depositBatchSingleERC20": "68050",
"depositBatchSingleNative": "28353",
"depositBatchViaPermit2NativeAndERC20": "129751",
"depositBatchViaPermit2SingleERC20": "104905",
"depositERC20AndURI": "67276",
"depositERC20Basic": "67302",
"depositERC20ViaPermit2AndURI": "98471",
"depositETHAndURI": "26754",
"depositETHBasic": "28391",
"qualifiedBatchClaim": "114134",
"qualifiedBatchClaimWithWitness": "113672",
"qualifiedClaim": "60406",
"qualifiedClaimWithWitness": "59098",
"qualifiedSplitBatchClaim": "141486",
"qualifiedSplitBatchClaimWithWitness": "141552",
"qualifiedSplitClaim": "86977",
"qualifiedSplitClaimWithWitness": "87452",
"register": "25379",
"splitBatchClaim": "140396",
"splitBatchClaimWithWitness": "140360",
"splitBatchTransfer": "110611",
"splitBatchWithdrawal": "139819",
"splitClaim": "86444",
"splitClaimWithWitness": "85925",
"splitTransfer": "82748",
"splitWithdrawal": "93702"
"splitBatchClaim": "140788",
"splitBatchClaimWithWitness": "140749",
"splitBatchTransfer": "110652",
"splitBatchWithdrawal": "140361",
"splitClaim": "86751",
"splitClaimWithWitness": "86232",
"splitTransfer": "82482",
"splitWithdrawal": "93770"
}
6 changes: 2 additions & 4 deletions src/TheCompact.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ import { Scope } from "./types/Scope.sol";
import { ResetPeriod } from "./types/ResetPeriod.sol";
import { ForcedWithdrawalStatus } from "./types/ForcedWithdrawalStatus.sol";

import { AllocatorLogic } from "./lib/AllocatorLogic.sol";
import { ClaimProcessor } from "./lib/ClaimProcessor.sol";
import { Extsload } from "./lib/Extsload.sol";
import { TheCompactLogic } from "./lib/TheCompactLogic.sol";

import { ERC6909 } from "solady/tokens/ERC6909.sol";
import { ISignatureTransfer } from "permit2/src/interfaces/ISignatureTransfer.sol";
Expand All @@ -26,7 +24,7 @@ import { ISignatureTransfer } from "permit2/src/interfaces/ISignatureTransfer.so
* formation and mediation of reusable "resource locks."
* This contract has not yet been properly tested, audited, or reviewed.
*/
contract TheCompact is ITheCompact, AllocatorLogic, ClaimProcessor, ERC6909, Extsload {
contract TheCompact is ITheCompact, ERC6909, TheCompactLogic {
function deposit(address allocator) external payable returns (uint256) {
return _performBasicNativeTokenDeposit(allocator);
}
Expand Down
Loading
Loading