Skip to content

Commit

Permalink
tx: De-sszify 4844 blob transaction (#2708)
Browse files Browse the repository at this point in the history
* tx: De-sszify 4844 blob transaction

* add the network serialization

* fix tests spec

* fix wrong update

* fix beacon payload data

* fix client spec

* increase spec coverage
  • Loading branch information
g11tech authored May 22, 2023
1 parent 3f2cd73 commit dd8afc5
Show file tree
Hide file tree
Showing 10 changed files with 297 additions and 285 deletions.
21 changes: 21 additions & 0 deletions packages/block/test/from-beacon-payload.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ tape('[fromExecutionPayloadJson]: 4844 devnet 5', async function (t) {
for (const payload of [payload87335, payload87475]) {
try {
const block = await Block.fromBeaconPayloadJson(payload, { common })
block.validateBlobTransactions({ excessDataGas: BigInt(0), _common: common } as any)
st.pass(`successfully constructed block=${block.header.number}`)
} catch (e) {
st.fail(`failed to construct block, error: ${e}`)
Expand All @@ -30,6 +31,7 @@ tape('[fromExecutionPayloadJson]: 4844 devnet 5', async function (t) {

t.test('should validate block hash', async function (st) {
try {
// construct a payload with differing block hash
await Block.fromBeaconPayloadJson(
{ ...payload87335, block_hash: payload87475.block_hash },
{ common }
Expand All @@ -40,4 +42,23 @@ tape('[fromExecutionPayloadJson]: 4844 devnet 5', async function (t) {
st.ok(`${e}`.includes('Invalid blockHash'), 'failed with correct error')
}
})

t.test('should validate excess data gas', async function (st) {
try {
// construct a payload with a different excess data gas but matching hash
const block = await Block.fromBeaconPayloadJson(
{
...payload87475,
excess_data_gas: payload87335.excess_data_gas,
block_hash: '0x506ff15910ef7c5a713b21f225b3ffb4bfb4aeea4ea4891e3a71c0ad7bf6a8e0',
},
{ common }
)
block.validateBlobTransactions({ excessDataGas: BigInt(0), _common: common } as any)
st.fail(`should have failed constructing the block`)
} catch (e) {
st.pass(`correctly failed constructing block, error: ${e}`)
st.ok(`${e}`.includes('block excessDataGas mismatch'), 'failed with correct error')
}
})
})
10 changes: 5 additions & 5 deletions packages/block/test/testdata/payload-slot-87335.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
"timestamp": "1683551220",
"extra_data": "0x4e65746865726d696e64",
"base_fee_per_gas": "7",
"block_hash": "0x8479de330419e8acc597cda0fb467dcd1fdd4fb0f20f54970328df8c328a1f37",
"block_hash": "0x56351338f4a1531e2b591693bdd1d028deee00f7850396677560eafaa6017e30",
"transactions": [
"0x034500000001e9bb1e21fa4231a0050610632a251534ec30db0bf16522d75984c6ee2352780786ce89539029546384c7b6bafb0ef813e5e0e09e4d2e20019a7bfa81e0f9bb7ded96b92001000000000000000000000000000000000000000000000000000000360000000000000060641a2a0100000000000000000000000000000000000000000000000000000060641a2a010000000000000000000000000000000000000000000000000000005034030000000000c000000002a8080000000000000000000000000000000000000000000000000000000000d5000000d500000060641a2a01000000000000000000000000000000000000000000000000000000d500000001ffb38a7a99e3e2335be83fc74b7faa19d55312410153a6a1e053cf4c5a09e84088ed8ad7cb53d76c8168f1b82f7cfebfcd06da1a",
"0x03450000000082d39507b7ef0730d68f3f34efbb8a39554190ed59a85ebf9b78a9b532371014f228a560fd39464d0eff6f46f87673722e00b9e208dfea92a089273847e87272ed96b92001000000000000000000000000000000000000000000000000000000f0000000000000000094357700000000000000000000000000000000000000000000000000000000155ed0b20000000000000000000000000000000000000000000000000000000020a1070000000000c00000000100000000000000000000000000000000000000000000000000000000000000c1000000c6000000155ed0b200000000000000000000000000000000000000000000000000000000c6000000005f495f495501d343d3cd62abd9c5754cbe5128c25ea90786a8ae75fb79c8cf95f4dcdd08ec",
"0x0345000000002941f6a7f01787837c09d5ff963c2c1455859e8a0eb6dc67df79fee5860769b698d105864d1a4793f026aa235256713f791bbcfb3617f09564b8d30ced012f11ed96b92001000000000000000000000000000000000000000000000000000000f10000000000000000ca9a3b000000000000000000000000000000000000000000000000000000000e9435770000000000000000000000000000000000000000000000000000000020a1070000000000c00000000100000000000000000000000000000000000000000000000000000000000000c1000000c60000000e94357700000000000000000000000000000000000000000000000000000000c6000000005f495f495501d552e24560ec2f168be1d4a6385df61c70afe4288f00a3ad172da1a6f2b4f2",
"0x0345000000002901e4b944c111f83699f8633f713a17752cd28fa5c8b44d2202586ef022f13232daec47ffb63f822261edd54c2e0d195fbefe486adf7a002757facb72a8a243ed96b92001000000000000000000000000000000000000000000000000000000000000000000000000c2eb0b0000000000000000000000000000000000000000000000000000000007ca9a3b000000000000000000000000000000000000000000000000000000005034030000000000c00000000000000000000000000000000000000000000000000000000000000000000000d5000000d500000000a3e11100000000000000000000000000000000000000000000000000000000d500000001c8d369b164361a8961286cfbab3bc10f962185a8011df88a2971c8a7ac494a7ba37ec1acaa1fc1edeeb38c839b5d1693d47b69b0"
"0x03f89d850120b996ed3685012a1a646085012a1a64608303345094ffb38a7a99e3e2335be83fc74b7faa19d55312418308a80280c085012a1a6460e1a00153a6a1e053cf4c5a09e84088ed8ad7cb53d76c8168f1b82f7cfebfcd06da1a01a007785223eec68459d72265f10bdb30ec3415252a63100605a03142fa211ebbe9a07dbbf9e081fa7b9a01202e4d9ee0e0e513f80efbbab6c784635429905389ce86",
"0x03f889850120b996ed81f0847735940084b2d05e158307a1208001855f495f4955c084b2d05e15e1a001d343d3cd62abd9c5754cbe5128c25ea90786a8ae75fb79c8cf95f4dcdd08ec80a014103732b5a9789bbf5ea859ed904155398abbef343f8fd63007efb70795d382a07272e847382789a092eadf08e2b9002e727376f8466fff0e4d4639fd60a528f2",
"0x03f889850120b996ed81f1843b9aca00847735940e8307a1208001855f495f4955c0847735940ee1a001d552e24560ec2f168be1d4a6385df61c70afe4288f00a3ad172da1a6f2b4f280a0b6690786e5fe79df67dcb60e8a9e8555142c3c96ffd5097c838717f0a7f64129a0112f01ed0cd3b86495f01736fbbc1b793f71565223aa26f093471a4d8605d198",
"0x03f897850120b996ed80840bebc200843b9aca078303345094c8d369b164361a8961286cfbab3bc10f962185a88080c08411e1a300e1a0011df88a2971c8a7ac494a7ba37ec1acaa1fc1edeeb38c839b5d1693d47b69b080a032f122f06e5802224db4c8a58fd22c75173a713f63f89936f811c144b9e40129a043a2a872cbfa5727007adf6a48febe5f190d2e4cd5ed6122823fb6ff47ecda32"
],
"withdrawals": [],
"excess_data_gas": "262144"
Expand Down
8 changes: 4 additions & 4 deletions packages/block/test/testdata/payload-slot-87475.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
"timestamp": "1683552900",
"extra_data": "0x4e65746865726d696e64",
"base_fee_per_gas": "9",
"block_hash": "0xfb640e94f3c2250ab223c41f07c3d72d5d0a589226ce09aab1827933d9a72548",
"block_hash": "0xd1ede53dab0cf183787351c90d4077a6e8a9b759781b2e7500a4fb607342892f",
"transactions": [
"0x02f8f3850120b996ed1a85012a1645a985012a1645b0830186a0948e4fc0f136ba56a151fd1530d4d6695df6a0fb4a80b880d08cc67f792879a8e1d0d5569a51af02f456f410ad93b1de0c038b667b7c5577898a95d960f0527fb7298b05f6a2c83ed6f508eee540edb1248b9235bb26fa566927967d32652b88610110527fe29d11468a1e028eedc6143170491b87a32609c236cb7068ebb1799c616c393061013052604a61015053600d6101515360b661c001a0f49f3f2b301cc72120fd1dcb1fe218012623035f5824d17343e802a4741c4e60a02a40bf4d7a5d52c8f554b04c635a898650584c5452be62a5304e50ca59e4d55f",
"0x03450000000035b76d7ab2125a71b16cd133f628bcc74d36ad96911c3f76792dba3079846028a9ff798cc5073a117864b0165b0364fe3b51e6d74d485e037a217d3f0734042ded96b92001000000000000000000000000000000000000000000000000000000040000000000000000c2eb0b0000000000000000000000000000000000000000000000000000000007ca9a3b000000000000000000000000000000000000000000000000000000005034030000000000c00000000000000000000000000000000000000000000000000000000000000000000000d50000001901000000a3e1110000000000000000000000000000000000000000000000000000000019010000018a185c5a7941b20253a2923690dd54a9e7bfd0a9a8d55bda000000000000000000000000573d9cd570267bb9d1547192e51e5c8d017d7034000000000000000000000000000000000000000000000000000000000000000001a974d0ba16f7a378867bb0dd359d78fdf831a2b73823a8a1eea34e6615cb99",
"0x034500000000843fc3910959c8f1ca89f33616d514d345a92327d9497a4a4b4ce77310889ef539092ff31a42fe9b2299b451eddcac33292b6739905e43eea7f84e3f00baab5ded96b92001000000000000000000000000000000000000000000000000000000050000000000000000c2eb0b0000000000000000000000000000000000000000000000000000000007ca9a3b000000000000000000000000000000000000000000000000000000005034030000000000c00000000000000000000000000000000000000000000000000000000000000000000000d50000001901000000a3e1110000000000000000000000000000000000000000000000000000000019010000018a185c5a7941b20253a2923690dd54a9e7bfd0a9a8d55bda000000000000000000000000573d9cd570267bb9d1547192e51e5c8d017d70340000000000000000000000000000000000000000000000000000000000000000011df88a2971c8a7ac494a7ba37ec1acaa1fc1edeeb38c839b5d1693d47b69b0",
"0x0345000000015259d613c5dc94b70c901f2bba5192b74ac9907bf9076efed6da2667a81be5f693178852ae064b88d5e1b19dbb41300209318044a054af6cd8211c9387f8ab2bed96b9200100000000000000000000000000000000000000000000000000000006000000000000000065cd1d0000000000000000000000000000000000000000000000000000000007ca9a3b000000000000000000000000000000000000000000000000000000005034030000000000c00000000000000000000000000000000000000000000000000000000000000000000000d50000001901000000a3e1110000000000000000000000000000000000000000000000000000000019010000018a185c5a7941b20253a2923690dd54a9e7bfd0a9a8d55bda000000000000000000000000573d9cd570267bb9d1547192e51e5c8d017d70340000000000000000000000000000000000000000000000000000000000000000011df88a2971c8a7ac494a7ba37ec1acaa1fc1edeeb38c839b5d1693d47b69b0"
"0x03f8dc850120b996ed04840bebc200843b9aca0783033450948a185c5a7941b20253a2923690dd54a9e7bfd0a980b844a8d55bda000000000000000000000000573d9cd570267bb9d1547192e51e5c8d017d70340000000000000000000000000000000000000000000000000000000000000000c08411e1a300e1a001a974d0ba16f7a378867bb0dd359d78fdf831a2b73823a8a1eea34e6615cb9980a02860847930ba2d79763f1c9196ad364dc7bc28f633d16cb1715a12b27a6db735a02d0434073f7d217a035e484dd7e6513bfe64035b16b06478113a07c58c79ffa9",
"0x03f8dc850120b996ed05840bebc200843b9aca0783033450948a185c5a7941b20253a2923690dd54a9e7bfd0a980b844a8d55bda000000000000000000000000573d9cd570267bb9d1547192e51e5c8d017d70340000000000000000000000000000000000000000000000000000000000000000c08411e1a300e1a0011df88a2971c8a7ac494a7ba37ec1acaa1fc1edeeb38c839b5d1693d47b69b080a0f59e881073e74c4b4a7a49d92723a945d314d51636f389caf1c8590991c33f84a05dabba003f4ef8a7ee435e9039672b2933acdced51b499229bfe421af32f0939",
"0x03f8dc850120b996ed06841dcd6500843b9aca0783033450948a185c5a7941b20253a2923690dd54a9e7bfd0a980b844a8d55bda000000000000000000000000573d9cd570267bb9d1547192e51e5c8d017d70340000000000000000000000000000000000000000000000000000000000000000c08411e1a300e1a0011df88a2971c8a7ac494a7ba37ec1acaa1fc1edeeb38c839b5d1693d47b69b001a0f6e51ba86726dad6fe6e07f97b90c94ab79251ba2b1f900cb794dcc513d65952a02babf887931c21d86caf54a044803109023041bb9db1e1d5884b06ae52881793"
],
"withdrawals": [],
"excess_data_gas": "131072"
Expand Down
7 changes: 4 additions & 3 deletions packages/client/lib/net/protocol/ethprotocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -246,11 +246,12 @@ export class EthProtocol extends Protocol {
return [
bytesToBigInt(reqId),
txs.map((txData) => {
// Blob transactions are deserialized with network wrapper
if (txData[0] === 5) {
// Blob transactions are deserialized with network wrapper
return BlobEIP4844Transaction.fromSerializedBlobTxNetworkWrapper(txData)
return BlobEIP4844Transaction.fromSerializedBlobTxNetworkWrapper(txData, { common })
} else {
return TransactionFactory.fromBlockBodyData(txData, { common })
}
return TransactionFactory.fromBlockBodyData(txData)
}),
]
},
Expand Down
2 changes: 1 addition & 1 deletion packages/client/test/rpc/engine/getPayloadV3.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ tape(`${method}: call with known payload`, async (t) => {
const { executionPayload, blobsBundle } = res.body.result
t.equal(
executionPayload.blockHash,
'0x3c599ece59439d2dc938e7a2b5e1c675cf8173b6be654f0a689b96936eba96e2',
'0xc95747af99348f5fd5f0e694973fbac29f3206155babc2232bfff202fdad8e2c',
'built expected block'
)
const { commitments, proofs, blobs } = blobsBundle
Expand Down
13 changes: 11 additions & 2 deletions packages/tx/src/baseTransaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import { checkMaxInitCodeSize } from './util'
import type {
AccessListEIP2930TxData,
AccessListEIP2930ValuesArray,
BlobEIP4844TxData,
BlobEIP4844ValuesArray,
FeeMarketEIP1559TxData,
FeeMarketEIP1559ValuesArray,
JsonTx,
Expand Down Expand Up @@ -91,7 +93,10 @@ export abstract class BaseTransaction<TransactionObject> {
*/
protected DEFAULT_HARDFORK: string | Hardfork = Hardfork.Shanghai

constructor(txData: TxData | AccessListEIP2930TxData | FeeMarketEIP1559TxData, opts: TxOptions) {
constructor(
txData: TxData | AccessListEIP2930TxData | FeeMarketEIP1559TxData | BlobEIP4844TxData,
opts: TxOptions
) {
const { nonce, gasLimit, to, value, data, v, r, s, type } = txData
this._type = Number(bytesToBigInt(toBytes(type)))

Expand Down Expand Up @@ -257,7 +262,11 @@ export abstract class BaseTransaction<TransactionObject> {
* signature parameters `v`, `r` and `s` for encoding. For an EIP-155 compliant
* representation for external signing use {@link BaseTransaction.getMessageToSign}.
*/
abstract raw(): TxValuesArray | AccessListEIP2930ValuesArray | FeeMarketEIP1559ValuesArray
abstract raw():
| TxValuesArray
| AccessListEIP2930ValuesArray
| FeeMarketEIP1559ValuesArray
| BlobEIP4844ValuesArray

/**
* Returns the encoding of the transaction.
Expand Down
Loading

0 comments on commit dd8afc5

Please sign in to comment.