Skip to content

Commit 9bdf43c

Browse files
Update docs to match current state (#66)
1 parent 9de59f8 commit 9bdf43c

File tree

5 files changed

+24
-758
lines changed

5 files changed

+24
-758
lines changed

CLAUDE.md

Lines changed: 15 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -34,55 +34,35 @@ Deployment scripts are in `script/` directory. Required environment variables:
3434

3535
### Core Components
3636

37-
This is a Solidity project implementing **Sapient Signer modules** for Sequence v3 wallets, focusing on cross-chain payment and bridging functionality through LiFi and relay protocols.
37+
This is a Solidity project implementing cross-chain payment and bridging functionality through TrailsRouter and TrailsIntentEntrypoint for Sequence v3 wallets.
3838

3939
#### Primary Contracts
40-
- **TrailsLiFiSapientSigner** (`src/TrailsLiFiSapientSigner.sol`) - Validates LiFi protocol operations (swaps/bridges) via off-chain attestations. Targets a specific immutable `TARGET_LIFI_DIAMOND` address for security.
41-
- **TrailsRelaySapientSigner** (`src/TrailsRelaySapientSigner.sol`) - Validates relay operations through similar attestation mechanism.
42-
- **TrailsTokenSweeper** (`src/TrailsTokenSweeper.sol`) - Utility contract for token recovery operations.
40+
- **TrailsRouter** (`src/TrailsRouter.sol`) - Consolidated router contract combining multicall routing, balance injection, and token sweeping functionality. Executes via delegatecall from Sequence v3 wallets.
41+
- **TrailsRouterShim** (`src/TrailsRouterShim.sol`) - Lightweight shim that wraps router calls and records execution success using storage sentinels.
42+
- **TrailsIntentEntrypoint** (`src/TrailsIntentEntrypoint.sol`) - EIP-712 signature-based entrypoint for depositing tokens to intent addresses with user authorization.
4343

4444
#### Library Architecture
4545
The project uses a modular library approach under `src/libraries/`:
4646

47-
**Execution Info Management:**
48-
- `TrailsExecutionInfoInterpreter.sol` - Standardizes cross-chain execution data
49-
- `TrailsExecutionInfoParams.sol` - Parameter handling for execution info
47+
**Sentinel Management:**
48+
- `TrailsSentinelLib.sol` - Manages storage sentinels for conditional execution tracking using tstore/sstore
5049

51-
**LiFi Integration:**
52-
- `TrailsLiFiFlagDecoder.sol` - Decodes LiFi call data using flag-based strategies
53-
- `TrailsLiFiInterpreter.sol` - Interprets and validates LiFi operations
54-
- `TrailsLiFiValidator.sol` - Validation logic for LiFi transactions
55-
56-
**Relay Integration:**
57-
- `TrailsRelayDecoder.sol` - Decodes relay call data
58-
- `TrailsRelayInterpreter.sol` - Interprets relay operations
59-
- `TrailsRelayValidator.sol` - Validation logic for relay transactions
60-
- `TrailsRelayParams.sol` - Parameter handling for relay operations
50+
### Key Architecture Patterns
6151

62-
#### Interface Definitions
63-
- `TrailsExecutionInfo.sol` - Core execution info structure
64-
- `TrailsLiFi.sol` - LiFi-specific interfaces and decoding strategies
65-
- `TrailsRelay.sol` - Relay-specific interfaces
52+
**Delegatecall-Only Execution:** TrailsRouter and TrailsRouterShim are designed to execute only via delegatecall from Sequence v3 wallets. Direct calls are blocked via `onlyDelegatecall` modifier.
6653

67-
### Key Architecture Patterns
54+
**Success Sentinel Pattern:** Operations track success/failure via storage sentinels keyed by `opHash`. This enables conditional fee collection and fallback refund logic.
6855

69-
**Sapient Signer Integration:** Both main contracts implement `ISapient` interface and integrate with Sequence wallet configuration trees as "Sapient Signer Leaves". They validate off-chain attestations to authorize operations without requiring direct wallet pre-approval.
56+
**Balance Injection:** Runtime balance injection allows protocols to receive exact token amounts when bridge amounts are unknown beforehand (due to slippage and fees).
7057

71-
**Validation Flow:**
72-
1. Contract receives payload and encoded signature (attestation)
73-
2. Validates target addresses match immutable contract addresses
74-
3. Recovers attestation signer from signature
75-
4. Decodes and interprets operation data using libraries
76-
5. Computes intent hash from operations + signer
77-
6. Returns hash for comparison against wallet's configured `imageHash`
58+
**EIP-712 Intent Authorization:** TrailsIntentEntrypoint uses EIP-712 signatures to authorize deposits to intent addresses, preventing replay attacks via nonce tracking.
7859

79-
**Security Model:** Each contract is deployed with immutable target addresses to prevent authorization of calls to arbitrary contracts. All validation is stateless and deterministic.
8060

8161
### External Dependencies
82-
- **Sequence Wallet v3** - Core wallet infrastructure and payload handling
83-
- **OpenZeppelin** - Cryptographic utilities (ECDSA, MessageHashUtils)
84-
- **LiFi Protocol** - Cross-chain bridge/swap interfaces
85-
- **ERC2470** - Singleton deployment pattern
62+
- **Sequence Wallet v3** (`wallet-contracts-v3`) - Core wallet infrastructure and payload handling (`IDelegatedExtension`)
63+
- **OpenZeppelin** (`openzeppelin-contracts`) - Token standards (IERC20, IERC20Permit), SafeERC20, cryptographic utilities (ECDSA), and security (ReentrancyGuard)
64+
- **Tstorish** (`tstorish`) - Storage library for tstore/sstore operations
65+
- **ERC2470** (`erc2470-libs`) - Singleton deployment pattern for deterministic addresses
8666

8767
### Testing Structure
8868
Tests mirror the source structure with unit tests for libraries and integration tests for main contracts. Mock contracts in `test/mocks/` simulate external protocol interactions.

CODE4ARENA.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Trails Contracts — Code4rena Audit Prep
22

3-
These contracts are used with **Trails** (https://docs.trails.build/) and Sequence v3 **sapient signer** wallets. The closed‑source **Intent Machine** is **out of scope** for this audit, but auditors can exercise public API interfaces that drive the on‑chain flows.
3+
These contracts are used with **Trails** (https://docs.trails.build/) and Sequence v3 wallets. The closed‑source **Intent Machine** is **out of scope** for this audit, but auditors can exercise public API interfaces that drive the on‑chain flows.
44

55
---
66

docs/README.md

Lines changed: 8 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,18 @@ Welcome to the comprehensive documentation for the Trails smart contract ecosyst
66

77
### Core Contracts
88

9-
#### 🚀 TrailsEntrypointV2 - Revolutionary 1-Click Transactions
10-
**[Technical Specification →](TrailsEntrypointV2.md)**
9+
#### 🚀 TrailsIntentEntrypoint - Revolutionary 1-Click Transactions
10+
**[Technical Specification →](../src/TrailsIntentEntrypoint.sol)**
1111

1212
The latest innovation in the Trails ecosystem: a single entrypoint contract that enables true 1-click crypto transactions by accepting intents through ETH/ERC20 transfers with calldata suffixes.
1313

1414
**Key Features:**
1515
- Single entrypoint for all intent-based operations
16-
- Transfer suffix pattern eliminates approve step
17-
- Commit-prove pattern with signature validation
16+
- EIP-712 signature verification for secure intent authorization
17+
- ERC-2612 permit support for gasless approvals
1818
- Generic multicall execution for bridges, swaps, and DeFi operations
1919
- Comprehensive safety mechanisms and emergency functions
2020

21-
#### 🔐 Sapient Signer Architecture
22-
**[Sapient Signer Documentation →](SAPIENT_SIGNER.md)**
23-
24-
Framework for Sequence v3 wallet integration enabling off-chain attestation validation for automated protocol operations.
25-
26-
**Core Modules:**
27-
- TrailsLiFiSapientSigner - LiFi protocol validation
28-
- TrailsRelaySapientSigner - Relay operation validation
29-
- TrailsTokenSweeper - Token recovery utilities
30-
3121
## 🏗️ Architecture Overview
3222

3323
### Design Principles
@@ -70,7 +60,7 @@ forge build
7060
forge test
7161

7262
# Run specific tests
73-
forge test --match-contract TrailsEntrypointV2Test
63+
forge test --match-contract TrailsIntentEntrypointTest
7464
```
7565

7666
### Testing Strategy
@@ -110,67 +100,10 @@ forge script script/Deploy.s.sol --rpc-url $RPC_URL --broadcast --verify
110100

111101
## 🚀 Usage Examples
112102

113-
### Simple ETH Bridge
114-
115-
```javascript
116-
// 1. Commit intent
117-
const intent = {
118-
sender: userAddress,
119-
token: ZERO_ADDRESS, // ETH
120-
amount: parseEther("1.0"),
121-
destinationChain: 137, // Polygon
122-
destinationAddress: userAddress,
123-
extraData: "0x",
124-
nonce: await entrypoint.nonces(userAddress),
125-
deadline: Math.floor(Date.now() / 1000) + 3600
126-
};
127-
128-
const intentHash = await entrypoint.commitIntent(intent);
129-
130-
// 2. Send ETH with intent hash suffix
131-
const calldata = ethers.utils.concat([
132-
ethers.utils.randomBytes(32),
133-
intentHash
134-
]);
135-
136-
await user.sendTransaction({
137-
to: entrypoint.address,
138-
value: intent.amount,
139-
data: calldata
140-
});
141-
142-
// 3. Backend proves and executes
143-
await entrypoint.proveETHDeposit(intentHash, txProof);
144-
await entrypoint.executeIntent(intentHash, bridgeCalls);
145-
```
103+
For integration examples and usage guides, please refer to:
146104

147-
### ERC20 Swap + Bridge
148-
149-
```javascript
150-
// 1. Commit ERC20 intent
151-
const intent = {
152-
sender: userAddress,
153-
token: USDC_ADDRESS,
154-
amount: parseUnits("100", 6),
155-
destinationChain: 42161, // Arbitrum
156-
destinationAddress: userAddress,
157-
extraData: encodeSwapData(USDC_ADDRESS, WETH_ADDRESS),
158-
nonce: await entrypoint.nonces(userAddress),
159-
deadline: Math.floor(Date.now() / 1000) + 3600
160-
};
161-
162-
// 2. Deposit ERC20
163-
await usdc.approve(entrypoint.address, intent.amount);
164-
await entrypoint.depositERC20WithIntent(intentHash, USDC_ADDRESS, intent.amount);
165-
166-
// 3. Execute swap + bridge
167-
const calls = [
168-
{ target: DEX_ADDRESS, data: swapCalldata, value: 0 },
169-
{ target: BRIDGE_ADDRESS, data: bridgeCalldata, value: 0 }
170-
];
171-
172-
await entrypoint.executeIntent(intentHash, calls);
173-
```
105+
- **[Trails Website](https://trails.build)** - Learn more about Trails and explore the platform
106+
- **[Trails SDK Documentation](https://docs.trails.build/sdk/get-started)** - Complete SDK integration guide with React widget examples
174107

175108
## 📈 Future Roadmap
176109

docs/SAPIENT_SIGNER.md

Lines changed: 0 additions & 96 deletions
This file was deleted.

0 commit comments

Comments
 (0)