Skip to content

Commit a06a712

Browse files
spalladinoclaude
andcommitted
feat: add EIP-7594 (PeerDAS) blob support
Implements EIP-7594 blob transaction support alongside existing EIP-4844 blobs. BREAKING CHANGES: - `blobsToProofs` now returns `Hex[][]` or `ByteArray[][]` instead of flat arrays - EIP-4844: Returns `[[proof]]` (one proof per blob, wrapped in array) - EIP-7594: Returns `[[proof1, ...proof128], ...]` (128 cell proofs per blob) - `BlobSidecar.proof` type now accepts `type | type[]` to support both formats Features: - Add optional `blobVersion` parameter ('4844' | '7594') to blob-related methods - Automatic blob version detection based on chain ID (Sepolia uses EIP-7594) - Add `getBlobVersion` helper for chain-based version selection - Support for `computeCellsAndKzgProofs` in KZG interface - EIP-7594 uses wrapper version byte `0x01` in transaction serialization - Transaction parsing handles both 4-element (EIP-4844) and 5-element (EIP-7594) wrappers Implementation: - `blobsToProofs`: Returns array of proof arrays, uses `computeCellsAndKzgProofs` for EIP-7594 - `toBlobSidecars`: Handles proof arrays, unwraps single proofs for EIP-4844 - `serializeTransaction`: Flattens proof arrays, adds version byte for EIP-7594 - `parseTransaction`: Groups proofs by blob dynamically based on count - `getBlobVersion`: Auto-detects version from chain ID with override support Documentation: - Update blob transaction guide with EIP-7594 information - Add `blobVersion` parameter docs to `blobsToProofs` and `toBlobSidecars` - Document proof structure differences between EIP-4844 and EIP-7594 Tests: - Add comprehensive EIP-7594 test coverage (128 tests passing) - Mock KZG implementation with `computeCellsAndKzgProofs` for testing - Test serialization, parsing, and round-trip for both blob versions - Verify automatic chain-based version detection Dependencies: - Update `@paulmillr/trusted-setups` to 0.3.0 (PeerDAS support) - Update `micro-eth-signer` to 0.17.3 (includes `computeCellsAndProofs`) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent 5031192 commit a06a712

19 files changed

+719
-282
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
"@changesets/changelog-github": "^0.4.8",
5353
"@changesets/cli": "^2.29.7",
5454
"@ethereumjs/rlp": "^5.0.2",
55-
"@paulmillr/trusted-setups": "^0.1.2",
55+
"@paulmillr/trusted-setups": "^0.3.0",
5656
"@pimlico/alto": "0.0.18",
5757
"@size-limit/preset-big-lib": "^11.2.0",
5858
"@types/bun": "^1.2.22",
@@ -63,7 +63,7 @@
6363
"ethers": "^6.15.0",
6464
"glob": "^10.4.5",
6565
"knip": "^5.64.0",
66-
"micro-eth-signer": "^0.14.0",
66+
"micro-eth-signer": "^0.17.3",
6767
"permissionless": "^0.2.57",
6868
"prool": "0.0.24",
6969
"publint": "^0.2.12",

pnpm-lock.yaml

Lines changed: 49 additions & 42 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

site/pages/docs/guides/blob-transactions.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@
22

33
Blob Transactions are a new type of transaction in Ethereum (introduced in [EIP-4844](https://eips.ethereum.org/EIPS/eip-4844)) that allows you to broadcast BLObs (Binary Large Objects) to the Ethereum network. Blob Transactions are like any other transaction, but with the added ability to carry a payload of Blobs. Blobs are extremely larger than regular calldata (~128kB), however unlike regular calldata, they are not accessible on the EVM. The EVM can only view the commitments of the blobs. Blobs are also transient, and only last for 4096 epochs (approx. 18 days).
44

5-
To read more on Blob Transactions and EIP-4844, check out these resources:
5+
Viem also supports [EIP-7594](https://eips.ethereum.org/EIPS/eip-7594) (PeerDAS) blobs, which use a different proof format. On Sepolia, EIP-7594 is automatically used, while other chains default to EIP-4844.
6+
7+
To read more on Blob Transactions and EIP-4844, check out these resources:
68

79
- [EIP-4844 Spec](https://eips.ethereum.org/EIPS/eip-4844)
10+
- [EIP-7594 Spec](https://eips.ethereum.org/EIPS/eip-7594)
811
- [EIP-4844 Website](https://www.eip4844.com/#faq)
912
- [EIP-4844 FAQ](https://notes.ethereum.org/@vbuterin/proto_danksharding_faq#Proto-Danksharding-FAQ)
1013

site/pages/docs/utilities/blobsToProofs.md

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,31 @@ const blobs = toBlobs({ data: '0x...' })
9999
const kzg = setupKzg(cKzg, mainnetTrustedSetupPath) // [!code focus]
100100
const commitments = blobsToCommitments({ blobs, kzg })
101101

102-
const proofs = blobsToProofs({
102+
const proofs = blobsToProofs({
103103
blobs,
104104
commitments,
105105
kzg, // [!code focus]
106-
})
106+
})
107+
```
108+
109+
### blobVersion (optional)
110+
111+
- **Type:** `'4844' | '7594'`
112+
- **Default:** `'4844'`
113+
114+
The blob version to use for proof generation. Defaults to `'4844'` (EIP-4844). Use `'7594'` for EIP-7594 (PeerDAS) blobs.
115+
116+
```ts twoslash
117+
import { blobsToCommitments, blobsToProofs, toBlobs } from 'viem'
118+
import { kzg } from './kzg'
119+
120+
const blobs = toBlobs({ data: '0x...' })
121+
const commitments = blobsToCommitments({ blobs, kzg })
122+
123+
const proofs = blobsToProofs({
124+
blobs,
125+
commitments,
126+
kzg,
127+
blobVersion: '7594', // [!code focus]
128+
})
107129
```

site/pages/docs/utilities/toBlobSidecars.md

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -205,14 +205,32 @@ const kzg = defineKzg({} as any)
205205
// ---cut---
206206
import { toBlobSidecars, toBlobs } from 'viem'
207207

208-
const sidecars = toBlobSidecars({
208+
const sidecars = toBlobSidecars({
209209
data: '0x1234',
210-
kzg,
211-
to: 'bytes', // [!code focus]
212-
})
210+
kzg,
211+
to: 'bytes', // [!code focus]
212+
})
213213

214214
sidecars // [!code focus]
215215
// ^?
216216

217217

218+
```
219+
220+
### blobVersion (optional)
221+
222+
- **Type:** `'4844' | '7594'`
223+
- **Default:** `'4844'`
224+
225+
The blob version to use for proof generation. Defaults to `'4844'` (EIP-4844). Use `'7594'` for EIP-7594 (PeerDAS) blobs.
226+
227+
```ts twoslash
228+
import { toBlobSidecars } from 'viem'
229+
import { kzg } from './kzg'
230+
231+
const sidecars = toBlobSidecars({
232+
data: '0x...',
233+
kzg,
234+
blobVersion: '7594', // [!code focus]
235+
})
218236
```

src/actions/wallet/sendRawTransaction.test.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@ test('default', async () => {
2424
expect(hash).toBeDefined()
2525
})
2626

27-
test.skip('4844', async () => {
27+
test('4844', async () => {
2828
const client = createClient({
2929
chain: sepolia,
30-
transport: http('https://ethereum-sepolia-rpc.publicnode.com'),
30+
transport: http(process.env.RPC_URL),
3131
})
3232

33-
const privateKey = '0x'
33+
const privateKey = process.env.PRIVATE_KEY
3434
const account = privateKeyToAccount(privateKey)
3535
const blobs = toBlobs({ data: stringToHex(blobData) })
3636
const nonce = await getTransactionCount(client, {
@@ -52,5 +52,6 @@ test.skip('4844', async () => {
5252
const hash = await sendRawTransaction(client, {
5353
serializedTransaction: serialized,
5454
})
55+
console.log(hash)
5556
expect(hash).toBeDefined()
5657
}, 20_000)

src/types/eip4844.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,12 @@ export type BlobSidecar<type extends Hex | ByteArray = Hex | ByteArray> = {
55
blob: type
66
/** The KZG commitment corresponding to this blob. */
77
commitment: type
8-
/** The KZG proof corresponding to this blob and commitment. */
9-
proof: type
8+
/**
9+
* The KZG proof(s) corresponding to this blob and commitment.
10+
* - EIP-4844: Single proof
11+
* - EIP-7594: Array of cell proofs (128 proofs)
12+
*/
13+
proof: type | type[]
1014
}
1115
export type BlobSidecars<type extends Hex | ByteArray = Hex | ByteArray> =
1216
BlobSidecar<type>[]

src/types/kzg.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ export type Kzg = {
1515
* commitment.
1616
*/
1717
computeBlobKzgProof(blob: ByteArray, commitment: ByteArray): ByteArray
18+
/**
19+
* Compute cells and their KZG proofs for a blob (EIP-7594).
20+
* Returns a tuple of [cells, proofs].
21+
*/
22+
computeCellsAndKzgProofs?(blob: ByteArray): [ByteArray[], ByteArray[]]
1823
}
1924

2025
export type GetTransactionRequestKzgParameter<

0 commit comments

Comments
 (0)