diff --git a/yarn-project/.yarn/patches/viem-npm-2.23.7-0552761b08.patch b/yarn-project/.yarn/patches/viem-npm-2.23.7-0552761b08.patch new file mode 100644 index 000000000000..57b6830e2f54 --- /dev/null +++ b/yarn-project/.yarn/patches/viem-npm-2.23.7-0552761b08.patch @@ -0,0 +1,1664 @@ +diff --git a/_esm/utils/transaction/parseTransaction.js b/_esm/utils/transaction/parseTransaction.js +index 6390fb1bf43b2d93af2836443d669e4ecb07d11e..47cb6448869138da57919338dd51dfeae6b923be 100644 +--- a/_esm/utils/transaction/parseTransaction.js ++++ b/_esm/utils/transaction/parseTransaction.js +@@ -1,350 +1,375 @@ +-import { InvalidAddressError, } from '../../errors/address.js'; +-import { InvalidLegacyVError, InvalidSerializedTransactionError, } from '../../errors/transaction.js'; ++import { InvalidAddressError } from '../../errors/address.js'; ++import { ++ InvalidLegacyVError, ++ InvalidSerializedTransactionError, ++} from '../../errors/transaction.js'; + import { isAddress } from '../address/isAddress.js'; + import { toBlobSidecars } from '../blob/toBlobSidecars.js'; + import { isHex } from '../data/isHex.js'; + import { padHex } from '../data/pad.js'; + import { trim } from '../data/trim.js'; +-import { hexToBigInt, hexToNumber, } from '../encoding/fromHex.js'; ++import { hexToBigInt, hexToNumber } from '../encoding/fromHex.js'; + import { fromRlp } from '../encoding/fromRlp.js'; + import { isHash } from '../hash/isHash.js'; +-import { assertTransactionEIP1559, assertTransactionEIP2930, assertTransactionEIP4844, assertTransactionEIP7702, assertTransactionLegacy, } from './assertTransaction.js'; +-import { getSerializedTransactionType, } from './getSerializedTransactionType.js'; ++import { ++ assertTransactionEIP1559, ++ assertTransactionEIP2930, ++ assertTransactionEIP4844, ++ assertTransactionEIP7702, ++ assertTransactionLegacy, ++} from './assertTransaction.js'; ++import { getSerializedTransactionType } from './getSerializedTransactionType.js'; + export function parseTransaction(serializedTransaction) { +- const type = getSerializedTransactionType(serializedTransaction); +- if (type === 'eip1559') +- return parseTransactionEIP1559(serializedTransaction); +- if (type === 'eip2930') +- return parseTransactionEIP2930(serializedTransaction); +- if (type === 'eip4844') +- return parseTransactionEIP4844(serializedTransaction); +- if (type === 'eip7702') +- return parseTransactionEIP7702(serializedTransaction); +- return parseTransactionLegacy(serializedTransaction); ++ const type = getSerializedTransactionType(serializedTransaction); ++ if (type === 'eip1559') return parseTransactionEIP1559(serializedTransaction); ++ if (type === 'eip2930') return parseTransactionEIP2930(serializedTransaction); ++ if (type === 'eip4844') return parseTransactionEIP4844(serializedTransaction); ++ if (type === 'eip7702') return parseTransactionEIP7702(serializedTransaction); ++ return parseTransactionLegacy(serializedTransaction); + } + function parseTransactionEIP7702(serializedTransaction) { +- const transactionArray = toTransactionArray(serializedTransaction); +- const [chainId, nonce, maxPriorityFeePerGas, maxFeePerGas, gas, to, value, data, accessList, authorizationList, v, r, s,] = transactionArray; +- if (transactionArray.length !== 10 && transactionArray.length !== 13) +- throw new InvalidSerializedTransactionError({ +- attributes: { +- chainId, +- nonce, +- maxPriorityFeePerGas, +- maxFeePerGas, +- gas, +- to, +- value, +- data, +- accessList, +- authorizationList, +- ...(transactionArray.length > 9 +- ? { +- v, +- r, +- s, +- } +- : {}), +- }, +- serializedTransaction, +- type: 'eip7702', +- }); +- const transaction = { +- chainId: hexToNumber(chainId), +- type: 'eip7702', +- }; +- if (isHex(to) && to !== '0x') +- transaction.to = to; +- if (isHex(gas) && gas !== '0x') +- transaction.gas = hexToBigInt(gas); +- if (isHex(data) && data !== '0x') +- transaction.data = data; +- if (isHex(nonce) && nonce !== '0x') +- transaction.nonce = hexToNumber(nonce); +- if (isHex(value) && value !== '0x') +- transaction.value = hexToBigInt(value); +- if (isHex(maxFeePerGas) && maxFeePerGas !== '0x') +- transaction.maxFeePerGas = hexToBigInt(maxFeePerGas); +- if (isHex(maxPriorityFeePerGas) && maxPriorityFeePerGas !== '0x') +- transaction.maxPriorityFeePerGas = hexToBigInt(maxPriorityFeePerGas); +- if (accessList.length !== 0 && accessList !== '0x') +- transaction.accessList = parseAccessList(accessList); +- if (authorizationList.length !== 0 && authorizationList !== '0x') +- transaction.authorizationList = parseAuthorizationList(authorizationList); +- assertTransactionEIP7702(transaction); +- const signature = transactionArray.length === 13 +- ? parseEIP155Signature(transactionArray) +- : undefined; +- return { ...signature, ...transaction }; ++ const transactionArray = toTransactionArray(serializedTransaction); ++ const [ ++ chainId, ++ nonce, ++ maxPriorityFeePerGas, ++ maxFeePerGas, ++ gas, ++ to, ++ value, ++ data, ++ accessList, ++ authorizationList, ++ v, ++ r, ++ s, ++ ] = transactionArray; ++ if (transactionArray.length !== 10 && transactionArray.length !== 13) ++ throw new InvalidSerializedTransactionError({ ++ attributes: { ++ chainId, ++ nonce, ++ maxPriorityFeePerGas, ++ maxFeePerGas, ++ gas, ++ to, ++ value, ++ data, ++ accessList, ++ authorizationList, ++ ...(transactionArray.length > 9 ++ ? { ++ v, ++ r, ++ s, ++ } ++ : {}), ++ }, ++ serializedTransaction, ++ type: 'eip7702', ++ }); ++ const transaction = { ++ chainId: hexToNumber(chainId), ++ type: 'eip7702', ++ }; ++ if (isHex(to) && to !== '0x') transaction.to = to; ++ if (isHex(gas) && gas !== '0x') transaction.gas = hexToBigInt(gas); ++ if (isHex(data) && data !== '0x') transaction.data = data; ++ if (isHex(nonce) && nonce !== '0x') transaction.nonce = hexToNumber(nonce); ++ if (isHex(value) && value !== '0x') transaction.value = hexToBigInt(value); ++ if (isHex(maxFeePerGas) && maxFeePerGas !== '0x') ++ transaction.maxFeePerGas = hexToBigInt(maxFeePerGas); ++ if (isHex(maxPriorityFeePerGas) && maxPriorityFeePerGas !== '0x') ++ transaction.maxPriorityFeePerGas = hexToBigInt(maxPriorityFeePerGas); ++ if (accessList.length !== 0 && accessList !== '0x') ++ transaction.accessList = parseAccessList(accessList); ++ if (authorizationList.length !== 0 && authorizationList !== '0x') ++ transaction.authorizationList = parseAuthorizationList(authorizationList); ++ assertTransactionEIP7702(transaction); ++ const signature = ++ transactionArray.length === 13 ++ ? parseEIP155Signature(transactionArray) ++ : undefined; ++ return { ...signature, ...transaction }; + } + function parseTransactionEIP4844(serializedTransaction) { +- const transactionOrWrapperArray = toTransactionArray(serializedTransaction); +- const hasNetworkWrapper = transactionOrWrapperArray.length === 4; +- const transactionArray = hasNetworkWrapper +- ? transactionOrWrapperArray[0] +- : transactionOrWrapperArray; +- const wrapperArray = hasNetworkWrapper +- ? transactionOrWrapperArray.slice(1) +- : []; +- const [chainId, nonce, maxPriorityFeePerGas, maxFeePerGas, gas, to, value, data, accessList, maxFeePerBlobGas, blobVersionedHashes, v, r, s,] = transactionArray; +- const [blobs, commitments, proofs] = wrapperArray; +- if (!(transactionArray.length === 11 || transactionArray.length === 14)) +- throw new InvalidSerializedTransactionError({ +- attributes: { +- chainId, +- nonce, +- maxPriorityFeePerGas, +- maxFeePerGas, +- gas, +- to, +- value, +- data, +- accessList, +- ...(transactionArray.length > 9 +- ? { +- v, +- r, +- s, +- } +- : {}), +- }, +- serializedTransaction, +- type: 'eip4844', +- }); +- const transaction = { +- blobVersionedHashes: blobVersionedHashes, +- chainId: hexToNumber(chainId), +- type: 'eip4844', +- }; +- if (isHex(to) && to !== '0x') +- transaction.to = to; +- if (isHex(gas) && gas !== '0x') +- transaction.gas = hexToBigInt(gas); +- if (isHex(data) && data !== '0x') +- transaction.data = data; +- if (isHex(nonce) && nonce !== '0x') +- transaction.nonce = hexToNumber(nonce); +- if (isHex(value) && value !== '0x') +- transaction.value = hexToBigInt(value); +- if (isHex(maxFeePerBlobGas) && maxFeePerBlobGas !== '0x') +- transaction.maxFeePerBlobGas = hexToBigInt(maxFeePerBlobGas); +- if (isHex(maxFeePerGas) && maxFeePerGas !== '0x') +- transaction.maxFeePerGas = hexToBigInt(maxFeePerGas); +- if (isHex(maxPriorityFeePerGas) && maxPriorityFeePerGas !== '0x') +- transaction.maxPriorityFeePerGas = hexToBigInt(maxPriorityFeePerGas); +- if (accessList.length !== 0 && accessList !== '0x') +- transaction.accessList = parseAccessList(accessList); +- if (blobs && commitments && proofs) +- transaction.sidecars = toBlobSidecars({ +- blobs: blobs, +- commitments: commitments, +- proofs: proofs, +- }); +- assertTransactionEIP4844(transaction); +- const signature = transactionArray.length === 14 +- ? parseEIP155Signature(transactionArray) +- : undefined; +- return { ...signature, ...transaction }; ++ const transactionOrWrapperArray = toTransactionArray(serializedTransaction); ++ const hasNetworkWrapper = transactionOrWrapperArray.length === 5; ++ const transactionArray = hasNetworkWrapper ++ ? transactionOrWrapperArray[0] ++ : transactionOrWrapperArray; ++ const wrapperArray = hasNetworkWrapper ++ ? transactionOrWrapperArray.slice(1) ++ : []; ++ const [ ++ chainId, ++ nonce, ++ maxPriorityFeePerGas, ++ maxFeePerGas, ++ gas, ++ to, ++ value, ++ data, ++ accessList, ++ maxFeePerBlobGas, ++ blobVersionedHashes, ++ v, ++ r, ++ s, ++ ] = transactionArray; ++ const [blobs, commitments, proofs] = wrapperArray; ++ if (!(transactionArray.length === 11 || transactionArray.length === 14)) ++ throw new InvalidSerializedTransactionError({ ++ attributes: { ++ chainId, ++ nonce, ++ maxPriorityFeePerGas, ++ maxFeePerGas, ++ gas, ++ to, ++ value, ++ data, ++ accessList, ++ ...(transactionArray.length > 9 ++ ? { ++ v, ++ r, ++ s, ++ } ++ : {}), ++ }, ++ serializedTransaction, ++ type: 'eip4844', ++ }); ++ const transaction = { ++ blobVersionedHashes: blobVersionedHashes, ++ chainId: hexToNumber(chainId), ++ type: 'eip4844', ++ }; ++ if (isHex(to) && to !== '0x') transaction.to = to; ++ if (isHex(gas) && gas !== '0x') transaction.gas = hexToBigInt(gas); ++ if (isHex(data) && data !== '0x') transaction.data = data; ++ if (isHex(nonce) && nonce !== '0x') transaction.nonce = hexToNumber(nonce); ++ if (isHex(value) && value !== '0x') transaction.value = hexToBigInt(value); ++ if (isHex(maxFeePerBlobGas) && maxFeePerBlobGas !== '0x') ++ transaction.maxFeePerBlobGas = hexToBigInt(maxFeePerBlobGas); ++ if (isHex(maxFeePerGas) && maxFeePerGas !== '0x') ++ transaction.maxFeePerGas = hexToBigInt(maxFeePerGas); ++ if (isHex(maxPriorityFeePerGas) && maxPriorityFeePerGas !== '0x') ++ transaction.maxPriorityFeePerGas = hexToBigInt(maxPriorityFeePerGas); ++ if (accessList.length !== 0 && accessList !== '0x') ++ transaction.accessList = parseAccessList(accessList); ++ if (blobs && commitments && proofs) ++ transaction.sidecars = toBlobSidecars({ ++ blobs: blobs, ++ commitments: commitments, ++ proofs: proofs, ++ }); ++ assertTransactionEIP4844(transaction); ++ const signature = ++ transactionArray.length === 14 ++ ? parseEIP155Signature(transactionArray) ++ : undefined; ++ return { ...signature, ...transaction }; + } + function parseTransactionEIP1559(serializedTransaction) { +- const transactionArray = toTransactionArray(serializedTransaction); +- const [chainId, nonce, maxPriorityFeePerGas, maxFeePerGas, gas, to, value, data, accessList, v, r, s,] = transactionArray; +- if (!(transactionArray.length === 9 || transactionArray.length === 12)) +- throw new InvalidSerializedTransactionError({ +- attributes: { +- chainId, +- nonce, +- maxPriorityFeePerGas, +- maxFeePerGas, +- gas, +- to, +- value, +- data, +- accessList, +- ...(transactionArray.length > 9 +- ? { +- v, +- r, +- s, +- } +- : {}), +- }, +- serializedTransaction, +- type: 'eip1559', +- }); +- const transaction = { +- chainId: hexToNumber(chainId), +- type: 'eip1559', +- }; +- if (isHex(to) && to !== '0x') +- transaction.to = to; +- if (isHex(gas) && gas !== '0x') +- transaction.gas = hexToBigInt(gas); +- if (isHex(data) && data !== '0x') +- transaction.data = data; +- if (isHex(nonce) && nonce !== '0x') +- transaction.nonce = hexToNumber(nonce); +- if (isHex(value) && value !== '0x') +- transaction.value = hexToBigInt(value); +- if (isHex(maxFeePerGas) && maxFeePerGas !== '0x') +- transaction.maxFeePerGas = hexToBigInt(maxFeePerGas); +- if (isHex(maxPriorityFeePerGas) && maxPriorityFeePerGas !== '0x') +- transaction.maxPriorityFeePerGas = hexToBigInt(maxPriorityFeePerGas); +- if (accessList.length !== 0 && accessList !== '0x') +- transaction.accessList = parseAccessList(accessList); +- assertTransactionEIP1559(transaction); +- const signature = transactionArray.length === 12 +- ? parseEIP155Signature(transactionArray) +- : undefined; +- return { ...signature, ...transaction }; ++ const transactionArray = toTransactionArray(serializedTransaction); ++ const [ ++ chainId, ++ nonce, ++ maxPriorityFeePerGas, ++ maxFeePerGas, ++ gas, ++ to, ++ value, ++ data, ++ accessList, ++ v, ++ r, ++ s, ++ ] = transactionArray; ++ if (!(transactionArray.length === 9 || transactionArray.length === 12)) ++ throw new InvalidSerializedTransactionError({ ++ attributes: { ++ chainId, ++ nonce, ++ maxPriorityFeePerGas, ++ maxFeePerGas, ++ gas, ++ to, ++ value, ++ data, ++ accessList, ++ ...(transactionArray.length > 9 ++ ? { ++ v, ++ r, ++ s, ++ } ++ : {}), ++ }, ++ serializedTransaction, ++ type: 'eip1559', ++ }); ++ const transaction = { ++ chainId: hexToNumber(chainId), ++ type: 'eip1559', ++ }; ++ if (isHex(to) && to !== '0x') transaction.to = to; ++ if (isHex(gas) && gas !== '0x') transaction.gas = hexToBigInt(gas); ++ if (isHex(data) && data !== '0x') transaction.data = data; ++ if (isHex(nonce) && nonce !== '0x') transaction.nonce = hexToNumber(nonce); ++ if (isHex(value) && value !== '0x') transaction.value = hexToBigInt(value); ++ if (isHex(maxFeePerGas) && maxFeePerGas !== '0x') ++ transaction.maxFeePerGas = hexToBigInt(maxFeePerGas); ++ if (isHex(maxPriorityFeePerGas) && maxPriorityFeePerGas !== '0x') ++ transaction.maxPriorityFeePerGas = hexToBigInt(maxPriorityFeePerGas); ++ if (accessList.length !== 0 && accessList !== '0x') ++ transaction.accessList = parseAccessList(accessList); ++ assertTransactionEIP1559(transaction); ++ const signature = ++ transactionArray.length === 12 ++ ? parseEIP155Signature(transactionArray) ++ : undefined; ++ return { ...signature, ...transaction }; + } + function parseTransactionEIP2930(serializedTransaction) { +- const transactionArray = toTransactionArray(serializedTransaction); +- const [chainId, nonce, gasPrice, gas, to, value, data, accessList, v, r, s] = transactionArray; +- if (!(transactionArray.length === 8 || transactionArray.length === 11)) +- throw new InvalidSerializedTransactionError({ +- attributes: { +- chainId, +- nonce, +- gasPrice, +- gas, +- to, +- value, +- data, +- accessList, +- ...(transactionArray.length > 8 +- ? { +- v, +- r, +- s, +- } +- : {}), +- }, +- serializedTransaction, +- type: 'eip2930', +- }); +- const transaction = { +- chainId: hexToNumber(chainId), +- type: 'eip2930', +- }; +- if (isHex(to) && to !== '0x') +- transaction.to = to; +- if (isHex(gas) && gas !== '0x') +- transaction.gas = hexToBigInt(gas); +- if (isHex(data) && data !== '0x') +- transaction.data = data; +- if (isHex(nonce) && nonce !== '0x') +- transaction.nonce = hexToNumber(nonce); +- if (isHex(value) && value !== '0x') +- transaction.value = hexToBigInt(value); +- if (isHex(gasPrice) && gasPrice !== '0x') +- transaction.gasPrice = hexToBigInt(gasPrice); +- if (accessList.length !== 0 && accessList !== '0x') +- transaction.accessList = parseAccessList(accessList); +- assertTransactionEIP2930(transaction); +- const signature = transactionArray.length === 11 +- ? parseEIP155Signature(transactionArray) +- : undefined; +- return { ...signature, ...transaction }; ++ const transactionArray = toTransactionArray(serializedTransaction); ++ const [chainId, nonce, gasPrice, gas, to, value, data, accessList, v, r, s] = ++ transactionArray; ++ if (!(transactionArray.length === 8 || transactionArray.length === 11)) ++ throw new InvalidSerializedTransactionError({ ++ attributes: { ++ chainId, ++ nonce, ++ gasPrice, ++ gas, ++ to, ++ value, ++ data, ++ accessList, ++ ...(transactionArray.length > 8 ++ ? { ++ v, ++ r, ++ s, ++ } ++ : {}), ++ }, ++ serializedTransaction, ++ type: 'eip2930', ++ }); ++ const transaction = { ++ chainId: hexToNumber(chainId), ++ type: 'eip2930', ++ }; ++ if (isHex(to) && to !== '0x') transaction.to = to; ++ if (isHex(gas) && gas !== '0x') transaction.gas = hexToBigInt(gas); ++ if (isHex(data) && data !== '0x') transaction.data = data; ++ if (isHex(nonce) && nonce !== '0x') transaction.nonce = hexToNumber(nonce); ++ if (isHex(value) && value !== '0x') transaction.value = hexToBigInt(value); ++ if (isHex(gasPrice) && gasPrice !== '0x') ++ transaction.gasPrice = hexToBigInt(gasPrice); ++ if (accessList.length !== 0 && accessList !== '0x') ++ transaction.accessList = parseAccessList(accessList); ++ assertTransactionEIP2930(transaction); ++ const signature = ++ transactionArray.length === 11 ++ ? parseEIP155Signature(transactionArray) ++ : undefined; ++ return { ...signature, ...transaction }; + } + function parseTransactionLegacy(serializedTransaction) { +- const transactionArray = fromRlp(serializedTransaction, 'hex'); +- const [nonce, gasPrice, gas, to, value, data, chainIdOrV_, r, s] = transactionArray; +- if (!(transactionArray.length === 6 || transactionArray.length === 9)) +- throw new InvalidSerializedTransactionError({ +- attributes: { +- nonce, +- gasPrice, +- gas, +- to, +- value, +- data, +- ...(transactionArray.length > 6 +- ? { +- v: chainIdOrV_, +- r, +- s, +- } +- : {}), +- }, +- serializedTransaction, +- type: 'legacy', +- }); +- const transaction = { +- type: 'legacy', +- }; +- if (isHex(to) && to !== '0x') +- transaction.to = to; +- if (isHex(gas) && gas !== '0x') +- transaction.gas = hexToBigInt(gas); +- if (isHex(data) && data !== '0x') +- transaction.data = data; +- if (isHex(nonce) && nonce !== '0x') +- transaction.nonce = hexToNumber(nonce); +- if (isHex(value) && value !== '0x') +- transaction.value = hexToBigInt(value); +- if (isHex(gasPrice) && gasPrice !== '0x') +- transaction.gasPrice = hexToBigInt(gasPrice); +- assertTransactionLegacy(transaction); +- if (transactionArray.length === 6) +- return transaction; +- const chainIdOrV = isHex(chainIdOrV_) && chainIdOrV_ !== '0x' +- ? hexToBigInt(chainIdOrV_) +- : 0n; +- if (s === '0x' && r === '0x') { +- if (chainIdOrV > 0) +- transaction.chainId = Number(chainIdOrV); +- return transaction; +- } +- const v = chainIdOrV; +- const chainId = Number((v - 35n) / 2n); +- if (chainId > 0) +- transaction.chainId = chainId; +- else if (v !== 27n && v !== 28n) +- throw new InvalidLegacyVError({ v }); +- transaction.v = v; +- transaction.s = s; +- transaction.r = r; +- transaction.yParity = v % 2n === 0n ? 1 : 0; ++ const transactionArray = fromRlp(serializedTransaction, 'hex'); ++ const [nonce, gasPrice, gas, to, value, data, chainIdOrV_, r, s] = ++ transactionArray; ++ if (!(transactionArray.length === 6 || transactionArray.length === 9)) ++ throw new InvalidSerializedTransactionError({ ++ attributes: { ++ nonce, ++ gasPrice, ++ gas, ++ to, ++ value, ++ data, ++ ...(transactionArray.length > 6 ++ ? { ++ v: chainIdOrV_, ++ r, ++ s, ++ } ++ : {}), ++ }, ++ serializedTransaction, ++ type: 'legacy', ++ }); ++ const transaction = { ++ type: 'legacy', ++ }; ++ if (isHex(to) && to !== '0x') transaction.to = to; ++ if (isHex(gas) && gas !== '0x') transaction.gas = hexToBigInt(gas); ++ if (isHex(data) && data !== '0x') transaction.data = data; ++ if (isHex(nonce) && nonce !== '0x') transaction.nonce = hexToNumber(nonce); ++ if (isHex(value) && value !== '0x') transaction.value = hexToBigInt(value); ++ if (isHex(gasPrice) && gasPrice !== '0x') ++ transaction.gasPrice = hexToBigInt(gasPrice); ++ assertTransactionLegacy(transaction); ++ if (transactionArray.length === 6) return transaction; ++ const chainIdOrV = ++ isHex(chainIdOrV_) && chainIdOrV_ !== '0x' ? hexToBigInt(chainIdOrV_) : 0n; ++ if (s === '0x' && r === '0x') { ++ if (chainIdOrV > 0) transaction.chainId = Number(chainIdOrV); + return transaction; ++ } ++ const v = chainIdOrV; ++ const chainId = Number((v - 35n) / 2n); ++ if (chainId > 0) transaction.chainId = chainId; ++ else if (v !== 27n && v !== 28n) throw new InvalidLegacyVError({ v }); ++ transaction.v = v; ++ transaction.s = s; ++ transaction.r = r; ++ transaction.yParity = v % 2n === 0n ? 1 : 0; ++ return transaction; + } + export function toTransactionArray(serializedTransaction) { +- return fromRlp(`0x${serializedTransaction.slice(4)}`, 'hex'); ++ return fromRlp(`0x${serializedTransaction.slice(4)}`, 'hex'); + } + export function parseAccessList(accessList_) { +- const accessList = []; +- for (let i = 0; i < accessList_.length; i++) { +- const [address, storageKeys] = accessList_[i]; +- if (!isAddress(address, { strict: false })) +- throw new InvalidAddressError({ address }); +- accessList.push({ +- address: address, +- storageKeys: storageKeys.map((key) => (isHash(key) ? key : trim(key))), +- }); +- } +- return accessList; ++ const accessList = []; ++ for (let i = 0; i < accessList_.length; i++) { ++ const [address, storageKeys] = accessList_[i]; ++ if (!isAddress(address, { strict: false })) ++ throw new InvalidAddressError({ address }); ++ accessList.push({ ++ address: address, ++ storageKeys: storageKeys.map((key) => (isHash(key) ? key : trim(key))), ++ }); ++ } ++ return accessList; + } + function parseAuthorizationList(serializedAuthorizationList) { +- const authorizationList = []; +- for (let i = 0; i < serializedAuthorizationList.length; i++) { +- const [chainId, contractAddress, nonce, yParity, r, s] = serializedAuthorizationList[i]; +- authorizationList.push({ +- chainId: hexToNumber(chainId), +- contractAddress, +- nonce: hexToNumber(nonce), +- ...parseEIP155Signature([yParity, r, s]), +- }); +- } +- return authorizationList; ++ const authorizationList = []; ++ for (let i = 0; i < serializedAuthorizationList.length; i++) { ++ const [chainId, contractAddress, nonce, yParity, r, s] = ++ serializedAuthorizationList[i]; ++ authorizationList.push({ ++ chainId: hexToNumber(chainId), ++ contractAddress, ++ nonce: hexToNumber(nonce), ++ ...parseEIP155Signature([yParity, r, s]), ++ }); ++ } ++ return authorizationList; + } + function parseEIP155Signature(transactionArray) { +- const signature = transactionArray.slice(-3); +- const v = signature[0] === '0x' || hexToBigInt(signature[0]) === 0n ? 27n : 28n; +- return { +- r: padHex(signature[1], { size: 32 }), +- s: padHex(signature[2], { size: 32 }), +- v, +- yParity: v === 27n ? 0 : 1, +- }; ++ const signature = transactionArray.slice(-3); ++ const v = ++ signature[0] === '0x' || hexToBigInt(signature[0]) === 0n ? 27n : 28n; ++ return { ++ r: padHex(signature[1], { size: 32 }), ++ s: padHex(signature[2], { size: 32 }), ++ v, ++ yParity: v === 27n ? 0 : 1, ++ }; + } + //# sourceMappingURL=parseTransaction.js.map +diff --git a/_esm/utils/transaction/serializeTransaction.js b/_esm/utils/transaction/serializeTransaction.js +index 0a305af80eae7bdf1effb4fb3891fc6ff074fc18..7581e6667f6135a67b0119148b562b6912c9af1e 100644 +--- a/_esm/utils/transaction/serializeTransaction.js ++++ b/_esm/utils/transaction/serializeTransaction.js +@@ -1,219 +1,264 @@ +-import { InvalidLegacyVError, } from '../../errors/transaction.js'; +-import { blobsToCommitments, } from '../blob/blobsToCommitments.js'; +-import { blobsToProofs, } from '../blob/blobsToProofs.js'; +-import { commitmentsToVersionedHashes, } from '../blob/commitmentsToVersionedHashes.js'; +-import { toBlobSidecars, } from '../blob/toBlobSidecars.js'; ++import { InvalidLegacyVError } from '../../errors/transaction.js'; ++import { blobsToCommitments } from '../blob/blobsToCommitments.js'; ++import { blobsToProofs } from '../blob/blobsToProofs.js'; ++import { commitmentsToVersionedHashes } from '../blob/commitmentsToVersionedHashes.js'; ++import { toBlobSidecars } from '../blob/toBlobSidecars.js'; + import { concatHex } from '../data/concat.js'; + import { trim } from '../data/trim.js'; + import { bytesToHex, toHex } from '../encoding/toHex.js'; + import { toRlp } from '../encoding/toRlp.js'; +-import { serializeAuthorizationList, } from '../../experimental/eip7702/utils/serializeAuthorizationList.js'; +-import { assertTransactionEIP1559, assertTransactionEIP2930, assertTransactionEIP4844, assertTransactionEIP7702, assertTransactionLegacy, } from './assertTransaction.js'; +-import { getTransactionType, } from './getTransactionType.js'; +-import { serializeAccessList, } from './serializeAccessList.js'; ++import { serializeAuthorizationList } from '../../experimental/eip7702/utils/serializeAuthorizationList.js'; ++import { ++ assertTransactionEIP1559, ++ assertTransactionEIP2930, ++ assertTransactionEIP4844, ++ assertTransactionEIP7702, ++ assertTransactionLegacy, ++} from './assertTransaction.js'; ++import { getTransactionType } from './getTransactionType.js'; ++import { serializeAccessList } from './serializeAccessList.js'; + export function serializeTransaction(transaction, signature) { +- const type = getTransactionType(transaction); +- if (type === 'eip1559') +- return serializeTransactionEIP1559(transaction, signature); +- if (type === 'eip2930') +- return serializeTransactionEIP2930(transaction, signature); +- if (type === 'eip4844') +- return serializeTransactionEIP4844(transaction, signature); +- if (type === 'eip7702') +- return serializeTransactionEIP7702(transaction, signature); +- return serializeTransactionLegacy(transaction, signature); ++ const type = getTransactionType(transaction); ++ if (type === 'eip1559') ++ return serializeTransactionEIP1559(transaction, signature); ++ if (type === 'eip2930') ++ return serializeTransactionEIP2930(transaction, signature); ++ if (type === 'eip4844') ++ return serializeTransactionEIP4844(transaction, signature); ++ if (type === 'eip7702') ++ return serializeTransactionEIP7702(transaction, signature); ++ return serializeTransactionLegacy(transaction, signature); + } + function serializeTransactionEIP7702(transaction, signature) { +- const { authorizationList, chainId, gas, nonce, to, value, maxFeePerGas, maxPriorityFeePerGas, accessList, data, } = transaction; +- assertTransactionEIP7702(transaction); +- const serializedAccessList = serializeAccessList(accessList); +- const serializedAuthorizationList = serializeAuthorizationList(authorizationList); +- return concatHex([ +- '0x04', +- toRlp([ +- toHex(chainId), +- nonce ? toHex(nonce) : '0x', +- maxPriorityFeePerGas ? toHex(maxPriorityFeePerGas) : '0x', +- maxFeePerGas ? toHex(maxFeePerGas) : '0x', +- gas ? toHex(gas) : '0x', +- to ?? '0x', +- value ? toHex(value) : '0x', +- data ?? '0x', +- serializedAccessList, +- serializedAuthorizationList, +- ...toYParitySignatureArray(transaction, signature), +- ]), +- ]); ++ const { ++ authorizationList, ++ chainId, ++ gas, ++ nonce, ++ to, ++ value, ++ maxFeePerGas, ++ maxPriorityFeePerGas, ++ accessList, ++ data, ++ } = transaction; ++ assertTransactionEIP7702(transaction); ++ const serializedAccessList = serializeAccessList(accessList); ++ const serializedAuthorizationList = ++ serializeAuthorizationList(authorizationList); ++ return concatHex([ ++ '0x04', ++ toRlp([ ++ toHex(chainId), ++ nonce ? toHex(nonce) : '0x', ++ maxPriorityFeePerGas ? toHex(maxPriorityFeePerGas) : '0x', ++ maxFeePerGas ? toHex(maxFeePerGas) : '0x', ++ gas ? toHex(gas) : '0x', ++ to ?? '0x', ++ value ? toHex(value) : '0x', ++ data ?? '0x', ++ serializedAccessList, ++ serializedAuthorizationList, ++ ...toYParitySignatureArray(transaction, signature), ++ ]), ++ ]); + } + function serializeTransactionEIP4844(transaction, signature) { +- const { chainId, gas, nonce, to, value, maxFeePerBlobGas, maxFeePerGas, maxPriorityFeePerGas, accessList, data, } = transaction; +- assertTransactionEIP4844(transaction); +- let blobVersionedHashes = transaction.blobVersionedHashes; +- let sidecars = transaction.sidecars; +- // If `blobs` are passed, we will need to compute the KZG commitments & proofs. +- if (transaction.blobs && +- (typeof blobVersionedHashes === 'undefined' || +- typeof sidecars === 'undefined')) { +- const blobs = (typeof transaction.blobs[0] === 'string' +- ? transaction.blobs +- : transaction.blobs.map((x) => bytesToHex(x))); +- const kzg = transaction.kzg; +- const commitments = blobsToCommitments({ +- blobs, +- kzg, +- }); +- if (typeof blobVersionedHashes === 'undefined') +- blobVersionedHashes = commitmentsToVersionedHashes({ +- commitments, +- }); +- if (typeof sidecars === 'undefined') { +- const proofs = blobsToProofs({ blobs, commitments, kzg }); +- sidecars = toBlobSidecars({ blobs, commitments, proofs }); +- } ++ const { ++ chainId, ++ gas, ++ nonce, ++ to, ++ value, ++ maxFeePerBlobGas, ++ maxFeePerGas, ++ maxPriorityFeePerGas, ++ accessList, ++ data, ++ } = transaction; ++ assertTransactionEIP4844(transaction); ++ let blobVersionedHashes = transaction.blobVersionedHashes; ++ let sidecars = transaction.sidecars; ++ // If `blobs` are passed, we will need to compute the KZG commitments & proofs. ++ if ( ++ transaction.blobs && ++ (typeof blobVersionedHashes === 'undefined' || ++ typeof sidecars === 'undefined') ++ ) { ++ const blobs = ++ typeof transaction.blobs[0] === 'string' ++ ? transaction.blobs ++ : transaction.blobs.map((x) => bytesToHex(x)); ++ const kzg = transaction.kzg; ++ const commitments = blobsToCommitments({ ++ blobs, ++ kzg, ++ }); ++ if (typeof blobVersionedHashes === 'undefined') ++ blobVersionedHashes = commitmentsToVersionedHashes({ ++ commitments, ++ }); ++ if (typeof sidecars === 'undefined') { ++ const proofs = blobsToProofs({ blobs, commitments, kzg }); ++ sidecars = toBlobSidecars({ blobs, commitments, proofs }); + } +- const serializedAccessList = serializeAccessList(accessList); +- const serializedTransaction = [ +- toHex(chainId), +- nonce ? toHex(nonce) : '0x', +- maxPriorityFeePerGas ? toHex(maxPriorityFeePerGas) : '0x', +- maxFeePerGas ? toHex(maxFeePerGas) : '0x', +- gas ? toHex(gas) : '0x', +- to ?? '0x', +- value ? toHex(value) : '0x', +- data ?? '0x', +- serializedAccessList, +- maxFeePerBlobGas ? toHex(maxFeePerBlobGas) : '0x', +- blobVersionedHashes ?? [], +- ...toYParitySignatureArray(transaction, signature), +- ]; +- const blobs = []; +- const commitments = []; +- const proofs = []; +- if (sidecars) +- for (let i = 0; i < sidecars.length; i++) { +- const { blob, commitment, proof } = sidecars[i]; +- blobs.push(blob); +- commitments.push(commitment); +- proofs.push(proof); +- } ++ } ++ const serializedAccessList = serializeAccessList(accessList); ++ const serializedTransaction = [ ++ toHex(chainId), ++ nonce ? toHex(nonce) : '0x', ++ maxPriorityFeePerGas ? toHex(maxPriorityFeePerGas) : '0x', ++ maxFeePerGas ? toHex(maxFeePerGas) : '0x', ++ gas ? toHex(gas) : '0x', ++ to ?? '0x', ++ value ? toHex(value) : '0x', ++ data ?? '0x', ++ serializedAccessList, ++ maxFeePerBlobGas ? toHex(maxFeePerBlobGas) : '0x', ++ blobVersionedHashes ?? [], ++ ...toYParitySignatureArray(transaction, signature), ++ ]; ++ const blobs = []; ++ const commitments = []; ++ const proofs = []; ++ if (sidecars) ++ for (let i = 0; i < sidecars.length; i++) { ++ const { blob, commitment, proof } = sidecars[i]; ++ blobs.push(blob); ++ commitments.push(commitment); ++ // proof can be a single proof (EIP-4844) or an array of proofs (EIP-7594) ++ if (Array.isArray(proof)) { ++ proofs.push(...proof); ++ } else { ++ proofs.push(proof); ++ } ++ } ++ ++ if (chainId === 11155111) { + return concatHex([ +- '0x03', +- sidecars +- ? // If sidecars are enabled, envelope turns into a "wrapper": +- toRlp([serializedTransaction, blobs, commitments, proofs]) +- : // If sidecars are disabled, standard envelope is used: +- toRlp(serializedTransaction), ++ '0x03', ++ sidecars ++ ? // If sidecars are enabled, envelope turns into a "wrapper": ++ toRlp([serializedTransaction, '0x01', blobs, commitments, proofs]) ++ : // If sidecars are disabled, standard envelope is used: ++ toRlp(serializedTransaction), + ]); ++ } ++ ++ return concatHex([ ++ '0x03', ++ sidecars ++ ? // If sidecars are enabled, envelope turns into a "wrapper": ++ toRlp([serializedTransaction, blobs, commitments, proofs]) ++ : // If sidecars are disabled, standard envelope is used: ++ toRlp(serializedTransaction), ++ ]); + } + function serializeTransactionEIP1559(transaction, signature) { +- const { chainId, gas, nonce, to, value, maxFeePerGas, maxPriorityFeePerGas, accessList, data, } = transaction; +- assertTransactionEIP1559(transaction); +- const serializedAccessList = serializeAccessList(accessList); +- const serializedTransaction = [ +- toHex(chainId), +- nonce ? toHex(nonce) : '0x', +- maxPriorityFeePerGas ? toHex(maxPriorityFeePerGas) : '0x', +- maxFeePerGas ? toHex(maxFeePerGas) : '0x', +- gas ? toHex(gas) : '0x', +- to ?? '0x', +- value ? toHex(value) : '0x', +- data ?? '0x', +- serializedAccessList, +- ...toYParitySignatureArray(transaction, signature), +- ]; +- return concatHex([ +- '0x02', +- toRlp(serializedTransaction), +- ]); ++ const { ++ chainId, ++ gas, ++ nonce, ++ to, ++ value, ++ maxFeePerGas, ++ maxPriorityFeePerGas, ++ accessList, ++ data, ++ } = transaction; ++ assertTransactionEIP1559(transaction); ++ const serializedAccessList = serializeAccessList(accessList); ++ const serializedTransaction = [ ++ toHex(chainId), ++ nonce ? toHex(nonce) : '0x', ++ maxPriorityFeePerGas ? toHex(maxPriorityFeePerGas) : '0x', ++ maxFeePerGas ? toHex(maxFeePerGas) : '0x', ++ gas ? toHex(gas) : '0x', ++ to ?? '0x', ++ value ? toHex(value) : '0x', ++ data ?? '0x', ++ serializedAccessList, ++ ...toYParitySignatureArray(transaction, signature), ++ ]; ++ return concatHex(['0x02', toRlp(serializedTransaction)]); + } + function serializeTransactionEIP2930(transaction, signature) { +- const { chainId, gas, data, nonce, to, value, accessList, gasPrice } = transaction; +- assertTransactionEIP2930(transaction); +- const serializedAccessList = serializeAccessList(accessList); +- const serializedTransaction = [ +- toHex(chainId), +- nonce ? toHex(nonce) : '0x', +- gasPrice ? toHex(gasPrice) : '0x', +- gas ? toHex(gas) : '0x', +- to ?? '0x', +- value ? toHex(value) : '0x', +- data ?? '0x', +- serializedAccessList, +- ...toYParitySignatureArray(transaction, signature), +- ]; +- return concatHex([ +- '0x01', +- toRlp(serializedTransaction), +- ]); ++ const { chainId, gas, data, nonce, to, value, accessList, gasPrice } = ++ transaction; ++ assertTransactionEIP2930(transaction); ++ const serializedAccessList = serializeAccessList(accessList); ++ const serializedTransaction = [ ++ toHex(chainId), ++ nonce ? toHex(nonce) : '0x', ++ gasPrice ? toHex(gasPrice) : '0x', ++ gas ? toHex(gas) : '0x', ++ to ?? '0x', ++ value ? toHex(value) : '0x', ++ data ?? '0x', ++ serializedAccessList, ++ ...toYParitySignatureArray(transaction, signature), ++ ]; ++ return concatHex(['0x01', toRlp(serializedTransaction)]); + } + function serializeTransactionLegacy(transaction, signature) { +- const { chainId = 0, gas, data, nonce, to, value, gasPrice } = transaction; +- assertTransactionLegacy(transaction); +- let serializedTransaction = [ +- nonce ? toHex(nonce) : '0x', +- gasPrice ? toHex(gasPrice) : '0x', +- gas ? toHex(gas) : '0x', +- to ?? '0x', +- value ? toHex(value) : '0x', +- data ?? '0x', ++ const { chainId = 0, gas, data, nonce, to, value, gasPrice } = transaction; ++ assertTransactionLegacy(transaction); ++ let serializedTransaction = [ ++ nonce ? toHex(nonce) : '0x', ++ gasPrice ? toHex(gasPrice) : '0x', ++ gas ? toHex(gas) : '0x', ++ to ?? '0x', ++ value ? toHex(value) : '0x', ++ data ?? '0x', ++ ]; ++ if (signature) { ++ const v = (() => { ++ // EIP-155 (inferred chainId) ++ if (signature.v >= 35n) { ++ const inferredChainId = (signature.v - 35n) / 2n; ++ if (inferredChainId > 0) return signature.v; ++ return 27n + (signature.v === 35n ? 0n : 1n); ++ } ++ // EIP-155 (explicit chainId) ++ if (chainId > 0) ++ return BigInt(chainId * 2) + BigInt(35n + signature.v - 27n); ++ // Pre-EIP-155 (no chainId) ++ const v = 27n + (signature.v === 27n ? 0n : 1n); ++ if (signature.v !== v) throw new InvalidLegacyVError({ v: signature.v }); ++ return v; ++ })(); ++ const r = trim(signature.r); ++ const s = trim(signature.s); ++ serializedTransaction = [ ++ ...serializedTransaction, ++ toHex(v), ++ r === '0x00' ? '0x' : r, ++ s === '0x00' ? '0x' : s, + ]; +- if (signature) { +- const v = (() => { +- // EIP-155 (inferred chainId) +- if (signature.v >= 35n) { +- const inferredChainId = (signature.v - 35n) / 2n; +- if (inferredChainId > 0) +- return signature.v; +- return 27n + (signature.v === 35n ? 0n : 1n); +- } +- // EIP-155 (explicit chainId) +- if (chainId > 0) +- return BigInt(chainId * 2) + BigInt(35n + signature.v - 27n); +- // Pre-EIP-155 (no chainId) +- const v = 27n + (signature.v === 27n ? 0n : 1n); +- if (signature.v !== v) +- throw new InvalidLegacyVError({ v: signature.v }); +- return v; +- })(); +- const r = trim(signature.r); +- const s = trim(signature.s); +- serializedTransaction = [ +- ...serializedTransaction, +- toHex(v), +- r === '0x00' ? '0x' : r, +- s === '0x00' ? '0x' : s, +- ]; +- } +- else if (chainId > 0) { +- serializedTransaction = [ +- ...serializedTransaction, +- toHex(chainId), +- '0x', +- '0x', +- ]; +- } +- return toRlp(serializedTransaction); ++ } else if (chainId > 0) { ++ serializedTransaction = [ ++ ...serializedTransaction, ++ toHex(chainId), ++ '0x', ++ '0x', ++ ]; ++ } ++ return toRlp(serializedTransaction); + } + export function toYParitySignatureArray(transaction, signature_) { +- const signature = signature_ ?? transaction; +- const { v, yParity } = signature; +- if (typeof signature.r === 'undefined') +- return []; +- if (typeof signature.s === 'undefined') +- return []; +- if (typeof v === 'undefined' && typeof yParity === 'undefined') +- return []; +- const r = trim(signature.r); +- const s = trim(signature.s); +- const yParity_ = (() => { +- if (typeof yParity === 'number') +- return yParity ? toHex(1) : '0x'; +- if (v === 0n) +- return '0x'; +- if (v === 1n) +- return toHex(1); +- return v === 27n ? '0x' : toHex(1); +- })(); +- return [yParity_, r === '0x00' ? '0x' : r, s === '0x00' ? '0x' : s]; ++ const signature = signature_ ?? transaction; ++ const { v, yParity } = signature; ++ if (typeof signature.r === 'undefined') return []; ++ if (typeof signature.s === 'undefined') return []; ++ if (typeof v === 'undefined' && typeof yParity === 'undefined') return []; ++ const r = trim(signature.r); ++ const s = trim(signature.s); ++ const yParity_ = (() => { ++ if (typeof yParity === 'number') return yParity ? toHex(1) : '0x'; ++ if (v === 0n) return '0x'; ++ if (v === 1n) return toHex(1); ++ return v === 27n ? '0x' : toHex(1); ++ })(); ++ return [yParity_, r === '0x00' ? '0x' : r, s === '0x00' ? '0x' : s]; + } + //# sourceMappingURL=serializeTransaction.js.map +diff --git a/package.json b/package.json +index c119f5955094a66a4807f94e496a0f9009de2102..7003b57a45c09a067f1bc16bc85263d1154ad127 100644 +--- a/package.json ++++ b/package.json +@@ -203,5 +203,6 @@ + "wallet", + "web3", + "typescript" +- ] ++ ], ++ "packageManager": "yarn@4.10.3+sha512.c38cafb5c7bb273f3926d04e55e1d8c9dfa7d9c3ea1f36a4868fa028b9e5f72298f0b7f401ad5eb921749eb012eb1c3bb74bf7503df3ee43fd600d14a018266f" + } +diff --git a/utils/transaction/serializeTransaction.ts b/utils/transaction/serializeTransaction.ts +index a8aa0baf074fb39f5ddfad0b683e71740464e155..a60a98f6894c347bf1319ae0c41d00e798a0ed33 100644 +--- a/utils/transaction/serializeTransaction.ts ++++ b/utils/transaction/serializeTransaction.ts +@@ -1,14 +1,14 @@ + import { + InvalidLegacyVError, + type InvalidLegacyVErrorType, +-} from '../../errors/transaction.js' +-import type { ErrorType } from '../../errors/utils.js' ++} from '../../errors/transaction.js'; ++import type { ErrorType } from '../../errors/utils.js'; + import type { + ByteArray, + Hex, + Signature, + SignatureLegacy, +-} from '../../types/misc.js' ++} from '../../types/misc.js'; + import type { + TransactionSerializable, + TransactionSerializableEIP1559, +@@ -24,33 +24,33 @@ import type { + TransactionSerializedEIP7702, + TransactionSerializedLegacy, + TransactionType, +-} from '../../types/transaction.js' +-import type { OneOf } from '../../types/utils.js' ++} from '../../types/transaction.js'; ++import type { OneOf } from '../../types/utils.js'; + import { + type BlobsToCommitmentsErrorType, + blobsToCommitments, +-} from '../blob/blobsToCommitments.js' ++} from '../blob/blobsToCommitments.js'; + import { + blobsToProofs, + type blobsToProofsErrorType, +-} from '../blob/blobsToProofs.js' ++} from '../blob/blobsToProofs.js'; + import { + type CommitmentsToVersionedHashesErrorType, + commitmentsToVersionedHashes, +-} from '../blob/commitmentsToVersionedHashes.js' ++} from '../blob/commitmentsToVersionedHashes.js'; + import { + type ToBlobSidecarsErrorType, + toBlobSidecars, +-} from '../blob/toBlobSidecars.js' +-import { type ConcatHexErrorType, concatHex } from '../data/concat.js' +-import { trim } from '../data/trim.js' +-import { type ToHexErrorType, bytesToHex, toHex } from '../encoding/toHex.js' +-import { type ToRlpErrorType, toRlp } from '../encoding/toRlp.js' ++} from '../blob/toBlobSidecars.js'; ++import { type ConcatHexErrorType, concatHex } from '../data/concat.js'; ++import { trim } from '../data/trim.js'; ++import { type ToHexErrorType, bytesToHex, toHex } from '../encoding/toHex.js'; ++import { type ToRlpErrorType, toRlp } from '../encoding/toRlp.js'; + + import { + type SerializeAuthorizationListErrorType, + serializeAuthorizationList, +-} from '../../experimental/eip7702/utils/serializeAuthorizationList.js' ++} from '../../experimental/eip7702/utils/serializeAuthorizationList.js'; + import { + type AssertTransactionEIP1559ErrorType, + type AssertTransactionEIP2930ErrorType, +@@ -62,22 +62,22 @@ import { + assertTransactionEIP4844, + assertTransactionEIP7702, + assertTransactionLegacy, +-} from './assertTransaction.js' ++} from './assertTransaction.js'; + import { + type GetTransactionType, + type GetTransactionTypeErrorType, + getTransactionType, +-} from './getTransactionType.js' ++} from './getTransactionType.js'; + import { + type SerializeAccessListErrorType, + serializeAccessList, +-} from './serializeAccessList.js' ++} from './serializeAccessList.js'; + + export type SerializedTransactionReturnType< + transaction extends TransactionSerializable = TransactionSerializable, + /// + _transactionType extends TransactionType = GetTransactionType, +-> = TransactionSerialized<_transactionType> ++> = TransactionSerialized<_transactionType>; + + export type SerializeTransactionFn< + transaction extends TransactionSerializableGeneric = TransactionSerializable, +@@ -86,7 +86,7 @@ export type SerializeTransactionFn< + > = typeof serializeTransaction< + OneOf, + _transactionType +-> ++>; + + export type SerializeTransactionErrorType = + | GetTransactionTypeErrorType +@@ -95,7 +95,7 @@ export type SerializeTransactionErrorType = + | SerializeTransactionEIP4844ErrorType + | SerializeTransactionEIP7702ErrorType + | SerializeTransactionLegacyErrorType +- | ErrorType ++ | ErrorType; + + export function serializeTransaction< + const transaction extends TransactionSerializable, +@@ -105,36 +105,36 @@ export function serializeTransaction< + transaction: transaction, + signature?: Signature | undefined, + ): SerializedTransactionReturnType { +- const type = getTransactionType(transaction) as GetTransactionType ++ const type = getTransactionType(transaction) as GetTransactionType; + + if (type === 'eip1559') + return serializeTransactionEIP1559( + transaction as TransactionSerializableEIP1559, + signature, +- ) as SerializedTransactionReturnType ++ ) as SerializedTransactionReturnType; + + if (type === 'eip2930') + return serializeTransactionEIP2930( + transaction as TransactionSerializableEIP2930, + signature, +- ) as SerializedTransactionReturnType ++ ) as SerializedTransactionReturnType; + + if (type === 'eip4844') + return serializeTransactionEIP4844( + transaction as TransactionSerializableEIP4844, + signature, +- ) as SerializedTransactionReturnType ++ ) as SerializedTransactionReturnType; + + if (type === 'eip7702') + return serializeTransactionEIP7702( + transaction as TransactionSerializableEIP7702, + signature, +- ) as SerializedTransactionReturnType ++ ) as SerializedTransactionReturnType; + + return serializeTransactionLegacy( + transaction as TransactionSerializableLegacy, + signature as SignatureLegacy, +- ) as SerializedTransactionReturnType ++ ) as SerializedTransactionReturnType; + } + + type SerializeTransactionEIP7702ErrorType = +@@ -145,7 +145,7 @@ type SerializeTransactionEIP7702ErrorType = + | ToHexErrorType + | ToRlpErrorType + | SerializeAccessListErrorType +- | ErrorType ++ | ErrorType; + + function serializeTransactionEIP7702( + transaction: TransactionSerializableEIP7702, +@@ -162,13 +162,13 @@ function serializeTransactionEIP7702( + maxPriorityFeePerGas, + accessList, + data, +- } = transaction ++ } = transaction; + +- assertTransactionEIP7702(transaction) ++ assertTransactionEIP7702(transaction); + +- const serializedAccessList = serializeAccessList(accessList) ++ const serializedAccessList = serializeAccessList(accessList); + const serializedAuthorizationList = +- serializeAuthorizationList(authorizationList) ++ serializeAuthorizationList(authorizationList); + + return concatHex([ + '0x04', +@@ -185,7 +185,7 @@ function serializeTransactionEIP7702( + serializedAuthorizationList, + ...toYParitySignatureArray(transaction, signature), + ]), +- ]) as TransactionSerializedEIP7702 ++ ]) as TransactionSerializedEIP7702; + } + + type SerializeTransactionEIP4844ErrorType = +@@ -199,7 +199,7 @@ type SerializeTransactionEIP4844ErrorType = + | ToHexErrorType + | ToRlpErrorType + | SerializeAccessListErrorType +- | ErrorType ++ | ErrorType; + + function serializeTransactionEIP4844( + transaction: TransactionSerializableEIP4844, +@@ -216,12 +216,12 @@ function serializeTransactionEIP4844( + maxPriorityFeePerGas, + accessList, + data, +- } = transaction ++ } = transaction; + +- assertTransactionEIP4844(transaction) ++ assertTransactionEIP4844(transaction); + +- let blobVersionedHashes = transaction.blobVersionedHashes +- let sidecars = transaction.sidecars ++ let blobVersionedHashes = transaction.blobVersionedHashes; ++ let sidecars = transaction.sidecars; + // If `blobs` are passed, we will need to compute the KZG commitments & proofs. + if ( + transaction.blobs && +@@ -232,24 +232,24 @@ function serializeTransactionEIP4844( + typeof transaction.blobs[0] === 'string' + ? transaction.blobs + : (transaction.blobs as ByteArray[]).map((x) => bytesToHex(x)) +- ) as Hex[] +- const kzg = transaction.kzg! ++ ) as Hex[]; ++ const kzg = transaction.kzg!; + const commitments = blobsToCommitments({ + blobs, + kzg, +- }) ++ }); + + if (typeof blobVersionedHashes === 'undefined') + blobVersionedHashes = commitmentsToVersionedHashes({ + commitments, +- }) ++ }); + if (typeof sidecars === 'undefined') { +- const proofs = blobsToProofs({ blobs, commitments, kzg }) +- sidecars = toBlobSidecars({ blobs, commitments, proofs }) ++ const proofs = blobsToProofs({ blobs, commitments, kzg }); ++ sidecars = toBlobSidecars({ blobs, commitments, proofs }); + } + } + +- const serializedAccessList = serializeAccessList(accessList) ++ const serializedAccessList = serializeAccessList(accessList); + + const serializedTransaction = [ + toHex(chainId), +@@ -264,27 +264,33 @@ function serializeTransactionEIP4844( + maxFeePerBlobGas ? toHex(maxFeePerBlobGas) : '0x', + blobVersionedHashes ?? [], + ...toYParitySignatureArray(transaction, signature), +- ] as const ++ ] as const; + +- const blobs: Hex[] = [] +- const commitments: Hex[] = [] +- const proofs: Hex[] = [] ++ const blobs: Hex[] = []; ++ const commitments: Hex[] = []; ++ const proofs: Hex[] = []; + if (sidecars) + for (let i = 0; i < sidecars.length; i++) { +- const { blob, commitment, proof } = sidecars[i] +- blobs.push(blob) +- commitments.push(commitment) +- proofs.push(proof) ++ const { blob, commitment, proof } = sidecars[i]; ++ blobs.push(blob); ++ commitments.push(commitment); ++ proofs.push(...(proof as unknown as Hex[])); + } + + return concatHex([ + '0x03', + sidecars + ? // If sidecars are enabled, envelope turns into a "wrapper": +- toRlp([serializedTransaction, blobs, commitments, proofs]) ++ toRlp([ ++ serializedTransaction, ++ '0x01', ++ blobs, ++ commitments, ++ `0x${proofs.map((x) => x.replace('0x', '')).join('')}`, ++ ]) + : // If sidecars are disabled, standard envelope is used: + toRlp(serializedTransaction), +- ]) as TransactionSerializedEIP4844 ++ ]) as TransactionSerializedEIP4844; + } + + type SerializeTransactionEIP1559ErrorType = +@@ -294,7 +300,7 @@ type SerializeTransactionEIP1559ErrorType = + | ToHexErrorType + | ToRlpErrorType + | SerializeAccessListErrorType +- | ErrorType ++ | ErrorType; + + function serializeTransactionEIP1559( + transaction: TransactionSerializableEIP1559, +@@ -310,11 +316,11 @@ function serializeTransactionEIP1559( + maxPriorityFeePerGas, + accessList, + data, +- } = transaction ++ } = transaction; + +- assertTransactionEIP1559(transaction) ++ assertTransactionEIP1559(transaction); + +- const serializedAccessList = serializeAccessList(accessList) ++ const serializedAccessList = serializeAccessList(accessList); + + const serializedTransaction = [ + toHex(chainId), +@@ -327,12 +333,12 @@ function serializeTransactionEIP1559( + data ?? '0x', + serializedAccessList, + ...toYParitySignatureArray(transaction, signature), +- ] ++ ]; + + return concatHex([ + '0x02', + toRlp(serializedTransaction), +- ]) as TransactionSerializedEIP1559 ++ ]) as TransactionSerializedEIP1559; + } + + type SerializeTransactionEIP2930ErrorType = +@@ -342,18 +348,18 @@ type SerializeTransactionEIP2930ErrorType = + | ToHexErrorType + | ToRlpErrorType + | SerializeAccessListErrorType +- | ErrorType ++ | ErrorType; + + function serializeTransactionEIP2930( + transaction: TransactionSerializableEIP2930, + signature?: Signature | undefined, + ): TransactionSerializedEIP2930 { + const { chainId, gas, data, nonce, to, value, accessList, gasPrice } = +- transaction ++ transaction; + +- assertTransactionEIP2930(transaction) ++ assertTransactionEIP2930(transaction); + +- const serializedAccessList = serializeAccessList(accessList) ++ const serializedAccessList = serializeAccessList(accessList); + + const serializedTransaction = [ + toHex(chainId), +@@ -365,12 +371,12 @@ function serializeTransactionEIP2930( + data ?? '0x', + serializedAccessList, + ...toYParitySignatureArray(transaction, signature), +- ] ++ ]; + + return concatHex([ + '0x01', + toRlp(serializedTransaction), +- ]) as TransactionSerializedEIP2930 ++ ]) as TransactionSerializedEIP2930; + } + + type SerializeTransactionLegacyErrorType = +@@ -378,15 +384,15 @@ type SerializeTransactionLegacyErrorType = + | InvalidLegacyVErrorType + | ToHexErrorType + | ToRlpErrorType +- | ErrorType ++ | ErrorType; + + function serializeTransactionLegacy( + transaction: TransactionSerializableLegacy, + signature?: SignatureLegacy | undefined, + ): TransactionSerializedLegacy { +- const { chainId = 0, gas, data, nonce, to, value, gasPrice } = transaction ++ const { chainId = 0, gas, data, nonce, to, value, gasPrice } = transaction; + +- assertTransactionLegacy(transaction) ++ assertTransactionLegacy(transaction); + + let serializedTransaction = [ + nonce ? toHex(nonce) : '0x', +@@ -395,69 +401,69 @@ function serializeTransactionLegacy( + to ?? '0x', + value ? toHex(value) : '0x', + data ?? '0x', +- ] ++ ]; + + if (signature) { + const v = (() => { + // EIP-155 (inferred chainId) + if (signature.v >= 35n) { +- const inferredChainId = (signature.v - 35n) / 2n +- if (inferredChainId > 0) return signature.v +- return 27n + (signature.v === 35n ? 0n : 1n) ++ const inferredChainId = (signature.v - 35n) / 2n; ++ if (inferredChainId > 0) return signature.v; ++ return 27n + (signature.v === 35n ? 0n : 1n); + } + + // EIP-155 (explicit chainId) + if (chainId > 0) +- return BigInt(chainId * 2) + BigInt(35n + signature.v - 27n) ++ return BigInt(chainId * 2) + BigInt(35n + signature.v - 27n); + + // Pre-EIP-155 (no chainId) +- const v = 27n + (signature.v === 27n ? 0n : 1n) +- if (signature.v !== v) throw new InvalidLegacyVError({ v: signature.v }) +- return v +- })() ++ const v = 27n + (signature.v === 27n ? 0n : 1n); ++ if (signature.v !== v) throw new InvalidLegacyVError({ v: signature.v }); ++ return v; ++ })(); + +- const r = trim(signature.r) +- const s = trim(signature.s) ++ const r = trim(signature.r); ++ const s = trim(signature.s); + + serializedTransaction = [ + ...serializedTransaction, + toHex(v), + r === '0x00' ? '0x' : r, + s === '0x00' ? '0x' : s, +- ] ++ ]; + } else if (chainId > 0) { + serializedTransaction = [ + ...serializedTransaction, + toHex(chainId), + '0x', + '0x', +- ] ++ ]; + } + +- return toRlp(serializedTransaction) as TransactionSerializedLegacy ++ return toRlp(serializedTransaction) as TransactionSerializedLegacy; + } + + export function toYParitySignatureArray( + transaction: TransactionSerializableGeneric, + signature_?: Signature | undefined, + ) { +- const signature = signature_ ?? transaction +- const { v, yParity } = signature ++ const signature = signature_ ?? transaction; ++ const { v, yParity } = signature; + +- if (typeof signature.r === 'undefined') return [] +- if (typeof signature.s === 'undefined') return [] +- if (typeof v === 'undefined' && typeof yParity === 'undefined') return [] ++ if (typeof signature.r === 'undefined') return []; ++ if (typeof signature.s === 'undefined') return []; ++ if (typeof v === 'undefined' && typeof yParity === 'undefined') return []; + +- const r = trim(signature.r) +- const s = trim(signature.s) ++ const r = trim(signature.r); ++ const s = trim(signature.s); + + const yParity_ = (() => { +- if (typeof yParity === 'number') return yParity ? toHex(1) : '0x' +- if (v === 0n) return '0x' +- if (v === 1n) return toHex(1) ++ if (typeof yParity === 'number') return yParity ? toHex(1) : '0x'; ++ if (v === 0n) return '0x'; ++ if (v === 1n) return toHex(1); + +- return v === 27n ? '0x' : toHex(1) +- })() ++ return v === 27n ? '0x' : toHex(1); ++ })(); + +- return [yParity_, r === '0x00' ? '0x' : r, s === '0x00' ? '0x' : s] ++ return [yParity_, r === '0x00' ? '0x' : r, s === '0x00' ? '0x' : s]; + } diff --git a/yarn-project/archiver/package.json b/yarn-project/archiver/package.json index 68e1b00a467e..aba10763b407 100644 --- a/yarn-project/archiver/package.json +++ b/yarn-project/archiver/package.json @@ -82,7 +82,7 @@ "lodash.omit": "^4.5.0", "tsc-watch": "^6.0.0", "tslib": "^2.5.0", - "viem": "2.23.7" + "viem": "patch:viem@npm%3A2.23.7#~/.yarn/patches/viem-npm-2.23.7-0552761b08.patch" }, "devDependencies": { "@jest/globals": "^30.0.0", diff --git a/yarn-project/aztec-faucet/package.json b/yarn-project/aztec-faucet/package.json index 738663c27c92..c6cb879a099f 100644 --- a/yarn-project/aztec-faucet/package.json +++ b/yarn-project/aztec-faucet/package.json @@ -70,7 +70,7 @@ "koa": "^2.16.1", "koa-bodyparser": "^4.4.1", "koa-router": "^13.1.1", - "viem": "2.23.7", + "viem": "patch:viem@npm%3A2.23.7#~/.yarn/patches/viem-npm-2.23.7-0552761b08.patch", "zod": "^3.23.8" }, "devDependencies": { diff --git a/yarn-project/aztec-node/package.json b/yarn-project/aztec-node/package.json index d7c5fbfc4f28..ee86b0e278d2 100644 --- a/yarn-project/aztec-node/package.json +++ b/yarn-project/aztec-node/package.json @@ -92,7 +92,7 @@ "koa": "^2.16.1", "koa-router": "^13.1.1", "tslib": "^2.4.0", - "viem": "2.23.7" + "viem": "patch:viem@npm%3A2.23.7#~/.yarn/patches/viem-npm-2.23.7-0552761b08.patch" }, "devDependencies": { "@jest/globals": "^30.0.0", diff --git a/yarn-project/aztec.js/package.json b/yarn-project/aztec.js/package.json index f1d70539924a..ae3c1fbb766e 100644 --- a/yarn-project/aztec.js/package.json +++ b/yarn-project/aztec.js/package.json @@ -90,7 +90,7 @@ "@aztec/stdlib": "workspace:^", "axios": "^1.12.0", "tslib": "^2.4.0", - "viem": "2.23.7" + "viem": "patch:viem@npm%3A2.23.7#~/.yarn/patches/viem-npm-2.23.7-0552761b08.patch" }, "devDependencies": { "@jest/globals": "^30.0.0", diff --git a/yarn-project/aztec/package.json b/yarn-project/aztec/package.json index 1c73b3d8195d..5ef0193a6773 100644 --- a/yarn-project/aztec/package.json +++ b/yarn-project/aztec/package.json @@ -65,7 +65,7 @@ "commander": "^12.1.0", "koa": "^2.16.1", "koa-router": "^13.1.1", - "viem": "2.23.7" + "viem": "patch:viem@npm%3A2.23.7#~/.yarn/patches/viem-npm-2.23.7-0552761b08.patch" }, "files": [ "dest", diff --git a/yarn-project/bb-prover/package.json b/yarn-project/bb-prover/package.json index ba17d4434ac7..a592eaae6206 100644 --- a/yarn-project/bb-prover/package.json +++ b/yarn-project/bb-prover/package.json @@ -99,7 +99,7 @@ "jest-mock-extended": "^4.0.0", "ts-node": "^10.9.1", "typescript": "^5.3.3", - "viem": "2.23.7" + "viem": "patch:viem@npm%3A2.23.7#~/.yarn/patches/viem-npm-2.23.7-0552761b08.patch" }, "files": [ "dest", diff --git a/yarn-project/blob-lib/package.json b/yarn-project/blob-lib/package.json index ab7b9dbb0e6d..8b2283e1297e 100644 --- a/yarn-project/blob-lib/package.json +++ b/yarn-project/blob-lib/package.json @@ -28,7 +28,7 @@ "dependencies": { "@aztec/constants": "workspace:^", "@aztec/foundation": "workspace:^", - "c-kzg": "4.0.0-alpha.1", + "c-kzg": "4.1.0", "tslib": "^2.4.0" }, "devDependencies": { diff --git a/yarn-project/blob-lib/src/blob.test.ts b/yarn-project/blob-lib/src/blob.test.ts index de6c6536158d..a2cab6d15828 100644 --- a/yarn-project/blob-lib/src/blob.test.ts +++ b/yarn-project/blob-lib/src/blob.test.ts @@ -21,7 +21,7 @@ const { } = cKzg; try { - loadTrustedSetup(); + loadTrustedSetup(8); } catch (error: any) { if (error.message.includes('trusted setup is already loaded')) { // NB: The c-kzg lib has no way of checking whether the setup is loaded or not, diff --git a/yarn-project/blob-lib/src/blob.ts b/yarn-project/blob-lib/src/blob.ts index 598f1d565f30..3ff6c24cc3e9 100644 --- a/yarn-project/blob-lib/src/blob.ts +++ b/yarn-project/blob-lib/src/blob.ts @@ -279,6 +279,7 @@ export class Blob { return { blobToKzgCommitment: cKzg.blobToKzgCommitment, computeBlobKzgProof: cKzg.computeBlobKzgProof, + computeCellsAndKzgProofs: cKzg.computeCellsAndKzgProofs, }; } diff --git a/yarn-project/blob-lib/src/blob_batching.test.ts b/yarn-project/blob-lib/src/blob_batching.test.ts index faa3eeb6fb03..c536a7c3a6b4 100644 --- a/yarn-project/blob-lib/src/blob_batching.test.ts +++ b/yarn-project/blob-lib/src/blob_batching.test.ts @@ -19,7 +19,7 @@ const trustedSetup = JSON.parse( const { FIELD_ELEMENTS_PER_BLOB, computeKzgProof, loadTrustedSetup, verifyKzgProof } = cKzg; try { - loadTrustedSetup(); + loadTrustedSetup(8); } catch (error: any) { if (error.message.includes('trusted setup is already loaded')) { // NB: The c-kzg lib has no way of checking whether the setup is loaded or not, diff --git a/yarn-project/blob-lib/src/blob_batching_public_inputs.test.ts b/yarn-project/blob-lib/src/blob_batching_public_inputs.test.ts index 8f4ea690f17c..8b4397bbe06b 100644 --- a/yarn-project/blob-lib/src/blob_batching_public_inputs.test.ts +++ b/yarn-project/blob-lib/src/blob_batching_public_inputs.test.ts @@ -15,7 +15,7 @@ import { import { makeBatchedBlobAccumulator, makeBlockBlobPublicInputs } from './testing.js'; try { - cKzg.loadTrustedSetup(); + cKzg.loadTrustedSetup(8); } catch (error: any) { if (error.message.includes('trusted setup is already loaded')) { // NB: The c-kzg lib has no way of checking whether the setup is loaded or not, diff --git a/yarn-project/blob-lib/src/index.ts b/yarn-project/blob-lib/src/index.ts index b6b53c7392af..f7ee96e507e0 100644 --- a/yarn-project/blob-lib/src/index.ts +++ b/yarn-project/blob-lib/src/index.ts @@ -11,7 +11,7 @@ export * from './blob_batching_public_inputs.js'; export * from './sponge_blob.js'; try { - loadTrustedSetup(); + loadTrustedSetup(8); } catch (error: any) { if (error.message.includes('trusted setup is already loaded')) { // NB: The c-kzg lib has no way of checking whether the setup is loaded or not, diff --git a/yarn-project/blob-lib/src/types.ts b/yarn-project/blob-lib/src/types.ts index 45cc5c026e4f..cb2177febba9 100644 --- a/yarn-project/blob-lib/src/types.ts +++ b/yarn-project/blob-lib/src/types.ts @@ -11,4 +11,5 @@ export interface BlobKzgInstance { blobToKzgCommitment(blob: Uint8Array): Uint8Array; /** Function to compute KZG proof for blob data */ computeBlobKzgProof(blob: Uint8Array, commitment: Uint8Array): Uint8Array; + computeCellsAndKzgProofs(blob: Uint8Array): [Uint8Array[], Uint8Array[]]; } diff --git a/yarn-project/blob-sink/package.json b/yarn-project/blob-sink/package.json index e7ded4f1072c..1ada47dda5af 100644 --- a/yarn-project/blob-sink/package.json +++ b/yarn-project/blob-sink/package.json @@ -68,7 +68,7 @@ "snappy": "^7.2.2", "source-map-support": "^0.5.21", "tslib": "^2.4.0", - "viem": "2.23.7", + "viem": "patch:viem@npm%3A2.23.7#~/.yarn/patches/viem-npm-2.23.7-0552761b08.patch", "zod": "^3.23.8" }, "devDependencies": { diff --git a/yarn-project/cli/package.json b/yarn-project/cli/package.json index cd383c41e6a3..45bf247714ab 100644 --- a/yarn-project/cli/package.json +++ b/yarn-project/cli/package.json @@ -89,7 +89,7 @@ "semver": "^7.5.4", "source-map-support": "^0.5.21", "tslib": "^2.4.0", - "viem": "2.23.7" + "viem": "patch:viem@npm%3A2.23.7#~/.yarn/patches/viem-npm-2.23.7-0552761b08.patch" }, "devDependencies": { "@aztec/accounts": "workspace:^", diff --git a/yarn-project/end-to-end/package.json b/yarn-project/end-to-end/package.json index bb964017d205..86b321d68360 100644 --- a/yarn-project/end-to-end/package.json +++ b/yarn-project/end-to-end/package.json @@ -96,7 +96,7 @@ "tslib": "^2.4.0", "typescript": "^5.3.3", "util": "^0.12.5", - "viem": "2.23.7", + "viem": "patch:viem@npm%3A2.23.7#~/.yarn/patches/viem-npm-2.23.7-0552761b08.patch", "zod": "^3.23.8" }, "devDependencies": { diff --git a/yarn-project/epoch-cache/package.json b/yarn-project/epoch-cache/package.json index 02c5ffec103a..fb63d8b213d8 100644 --- a/yarn-project/epoch-cache/package.json +++ b/yarn-project/epoch-cache/package.json @@ -35,7 +35,7 @@ "get-port": "^7.1.0", "jest-mock-extended": "^4.0.0", "tslib": "^2.4.0", - "viem": "2.23.7", + "viem": "patch:viem@npm%3A2.23.7#~/.yarn/patches/viem-npm-2.23.7-0552761b08.patch", "zod": "^3.23.8" }, "devDependencies": { diff --git a/yarn-project/ethereum/package.json b/yarn-project/ethereum/package.json index 04a205409707..eb18bea03393 100644 --- a/yarn-project/ethereum/package.json +++ b/yarn-project/ethereum/package.json @@ -40,7 +40,7 @@ "lodash.chunk": "^4.2.0", "lodash.pickby": "^4.5.0", "tslib": "^2.4.0", - "viem": "2.23.7", + "viem": "patch:viem@npm%3A2.23.7#~/.yarn/patches/viem-npm-2.23.7-0552761b08.patch", "zod": "^3.23.8" }, "devDependencies": { diff --git a/yarn-project/ethereum/src/l1_tx_utils/l1_tx_utils.ts b/yarn-project/ethereum/src/l1_tx_utils/l1_tx_utils.ts index 68f143f0e89b..467f78d4cc13 100644 --- a/yarn-project/ethereum/src/l1_tx_utils/l1_tx_utils.ts +++ b/yarn-project/ethereum/src/l1_tx_utils/l1_tx_utils.ts @@ -5,6 +5,7 @@ import { EthAddress } from '@aztec/foundation/eth-address'; import { type Logger, createLogger } from '@aztec/foundation/log'; import { retryUntil } from '@aztec/foundation/retry'; import { sleep } from '@aztec/foundation/sleep'; +import { bufferToHex } from '@aztec/foundation/string'; import { DateProvider } from '@aztec/foundation/timer'; import { RollupAbi } from '@aztec/l1-artifacts/RollupAbi'; @@ -22,6 +23,7 @@ import { formatGwei, serializeTransaction, } from 'viem'; +import { defaultPrepareTransactionRequestParameters } from 'viem/actions'; import { jsonRpc } from 'viem/nonce'; import type { ViemClient } from '../types.js'; @@ -157,11 +159,25 @@ export class L1TxUtils extends ReadOnlyL1TxUtils { private async signTransaction(txRequest: TransactionSerializable): Promise<`0x${string}`> { const signature = await this.signer(txRequest, this.getSenderAddress()); - return serializeTransaction(txRequest, signature); + const res = serializeTransaction(txRequest, signature); + return res; } - protected async prepareSignedTransaction(txData: PrepareTransactionRequestRequest) { - const txRequest = await this.client.prepareTransactionRequest(txData); + protected async prepareSignedTransaction(txData: PrepareTransactionRequestRequest, isBlobTx: boolean) { + const txRequest = await this.client.prepareTransactionRequest({ + ...txData, + ...(isBlobTx ? { parameters: [...defaultPrepareTransactionRequestParameters, 'sidecars'] } : {}), + }); + const kzg = txData.kzg! as any; + + if (txData.blobs?.length && this.client.chain.id === 11155111) { + for (let i = 0; i < txData.blobs.length; i++) { + const blob = txData.blobs![i]; + const [_, cellProofs] = kzg.computeCellsAndKzgProofs(blob) as [Uint8Array[], Uint8Array[]]; + txRequest.sidecars![i]!.proof = cellProofs.map(el => bufferToHex(Buffer.from(el))) as any; + i++; + } + } return await this.signTransaction(txRequest as TransactionSerializable); } @@ -218,7 +234,7 @@ export class L1TxUtils extends ReadOnlyL1TxUtils { } // Send the new tx - const signedRequest = await this.prepareSignedTransaction(txData); + const signedRequest = await this.prepareSignedTransaction(txData, !!blobInputs); const txHash = await this.client.sendRawTransaction({ serializedTransaction: signedRequest }); // Create the new state for monitoring @@ -433,7 +449,7 @@ export class L1TxUtils extends ReadOnlyL1TxUtils { const txData = this.makeTxData(state, { isCancelTx }); - const signedRequest = await this.prepareSignedTransaction(txData); + const signedRequest = await this.prepareSignedTransaction(txData, isBlobTx); const newHash = await this.client.sendRawTransaction({ serializedTransaction: signedRequest }); this.logger.verbose( @@ -682,7 +698,7 @@ export class L1TxUtils extends ReadOnlyL1TxUtils { state.lastSentAtL1Ts = new Date(await this.getL1Timestamp()); const txData = this.makeTxData(state, { isCancelTx: true }); - const signedRequest = await this.prepareSignedTransaction(txData); + const signedRequest = await this.prepareSignedTransaction(txData, isBlobTx); const cancelTxHash = await this.client.sendRawTransaction({ serializedTransaction: signedRequest }); state.cancelTxHashes.push(cancelTxHash); diff --git a/yarn-project/ethereum/src/utils.ts b/yarn-project/ethereum/src/utils.ts index d480b8f809fa..08e9f41f6cee 100644 --- a/yarn-project/ethereum/src/utils.ts +++ b/yarn-project/ethereum/src/utils.ts @@ -178,7 +178,7 @@ export function formatViemError(error: any, abi: Abi = ErrorsAbi): FormattedViem // If it's a regular Error instance, return it with its message if (error instanceof Error) { - return new FormattedViemError(error.message, (error as any)?.metaMessages); + return error; } const body = String(error); diff --git a/yarn-project/foundation/package.json b/yarn-project/foundation/package.json index 9963f060de07..399112f8b0ac 100644 --- a/yarn-project/foundation/package.json +++ b/yarn-project/foundation/package.json @@ -153,7 +153,7 @@ "ts-node": "^10.9.1", "typescript": "^5.3.3", "typescript-eslint": "^8.32.1", - "viem": "2.23.7" + "viem": "patch:viem@npm%3A2.23.7#~/.yarn/patches/viem-npm-2.23.7-0552761b08.patch" }, "files": [ "dest", diff --git a/yarn-project/node-keystore/package.json b/yarn-project/node-keystore/package.json index 1e8cf57ba40d..d2f4b85bc4e9 100644 --- a/yarn-project/node-keystore/package.json +++ b/yarn-project/node-keystore/package.json @@ -67,7 +67,7 @@ "@aztec/stdlib": "workspace:^", "@ethersproject/wallet": "^5.7.0", "tslib": "^2.4.0", - "viem": "2.23.7", + "viem": "patch:viem@npm%3A2.23.7#~/.yarn/patches/viem-npm-2.23.7-0552761b08.patch", "zod": "^3.23.8" }, "devDependencies": { diff --git a/yarn-project/p2p/package.json b/yarn-project/p2p/package.json index 5e1608c60de1..02c38a50c8da 100644 --- a/yarn-project/p2p/package.json +++ b/yarn-project/p2p/package.json @@ -117,7 +117,7 @@ "ts-node": "^10.9.1", "typescript": "^5.3.3", "uint8arrays": "^5.0.3", - "viem": "2.23.7" + "viem": "patch:viem@npm%3A2.23.7#~/.yarn/patches/viem-npm-2.23.7-0552761b08.patch" }, "files": [ "dest", diff --git a/yarn-project/prover-node/package.json b/yarn-project/prover-node/package.json index cffecbe7fb26..43e20e7c9dc4 100644 --- a/yarn-project/prover-node/package.json +++ b/yarn-project/prover-node/package.json @@ -79,7 +79,7 @@ "@aztec/world-state": "workspace:^", "source-map-support": "^0.5.21", "tslib": "^2.4.0", - "viem": "2.23.7" + "viem": "patch:viem@npm%3A2.23.7#~/.yarn/patches/viem-npm-2.23.7-0552761b08.patch" }, "devDependencies": { "@jest/globals": "^30.0.0", diff --git a/yarn-project/pxe/package.json b/yarn-project/pxe/package.json index 59a3fc2c90be..b39a83ab6888 100644 --- a/yarn-project/pxe/package.json +++ b/yarn-project/pxe/package.json @@ -82,7 +82,7 @@ "lodash.omit": "^4.5.0", "sha3": "^2.1.4", "tslib": "^2.4.0", - "viem": "2.23.7" + "viem": "patch:viem@npm%3A2.23.7#~/.yarn/patches/viem-npm-2.23.7-0552761b08.patch" }, "devDependencies": { "@aztec/merkle-tree": "workspace:^", diff --git a/yarn-project/sequencer-client/package.json b/yarn-project/sequencer-client/package.json index e8d41af1cf30..f78e9bdfeec9 100644 --- a/yarn-project/sequencer-client/package.json +++ b/yarn-project/sequencer-client/package.json @@ -52,7 +52,7 @@ "@aztec/world-state": "workspace:^", "lodash.chunk": "^4.2.0", "tslib": "^2.4.0", - "viem": "2.23.7" + "viem": "patch:viem@npm%3A2.23.7#~/.yarn/patches/viem-npm-2.23.7-0552761b08.patch" }, "devDependencies": { "@aztec/archiver": "workspace:^", diff --git a/yarn-project/simulator/package.json b/yarn-project/simulator/package.json index c6b3526b884c..4c78d07c1a72 100644 --- a/yarn-project/simulator/package.json +++ b/yarn-project/simulator/package.json @@ -91,7 +91,7 @@ "jest-mock-extended": "^4.0.0", "ts-node": "^10.9.1", "typescript": "^5.3.3", - "viem": "2.23.7" + "viem": "patch:viem@npm%3A2.23.7#~/.yarn/patches/viem-npm-2.23.7-0552761b08.patch" }, "files": [ "dest", diff --git a/yarn-project/slasher/package.json b/yarn-project/slasher/package.json index 12a7cd486659..aacbda4b9ab7 100644 --- a/yarn-project/slasher/package.json +++ b/yarn-project/slasher/package.json @@ -63,7 +63,7 @@ "@aztec/telemetry-client": "workspace:^", "source-map-support": "^0.5.21", "tslib": "^2.4.0", - "viem": "2.23.7", + "viem": "patch:viem@npm%3A2.23.7#~/.yarn/patches/viem-npm-2.23.7-0552761b08.patch", "zod": "^3.23.8" }, "devDependencies": { diff --git a/yarn-project/stdlib/package.json b/yarn-project/stdlib/package.json index 4c8a91a2b294..3625dfffcf60 100644 --- a/yarn-project/stdlib/package.json +++ b/yarn-project/stdlib/package.json @@ -87,7 +87,7 @@ "msgpackr": "^1.11.2", "pako": "^2.1.0", "tslib": "^2.4.0", - "viem": "2.23.7", + "viem": "patch:viem@npm%3A2.23.7#~/.yarn/patches/viem-npm-2.23.7-0552761b08.patch", "zod": "^3.23.8" }, "devDependencies": { diff --git a/yarn-project/telemetry-client/package.json b/yarn-project/telemetry-client/package.json index 4d6d35260cdf..d5e63915f937 100644 --- a/yarn-project/telemetry-client/package.json +++ b/yarn-project/telemetry-client/package.json @@ -42,7 +42,7 @@ "@opentelemetry/sdk-trace-node": "^1.28.0", "@opentelemetry/semantic-conventions": "^1.28.0", "prom-client": "^15.1.3", - "viem": "2.23.7" + "viem": "patch:viem@npm%3A2.23.7#~/.yarn/patches/viem-npm-2.23.7-0552761b08.patch" }, "devDependencies": { "@jest/globals": "^30.0.0", diff --git a/yarn-project/validator-client/package.json b/yarn-project/validator-client/package.json index 2ce0f0e5eb84..ebef8b555339 100644 --- a/yarn-project/validator-client/package.json +++ b/yarn-project/validator-client/package.json @@ -77,7 +77,7 @@ "koa": "^2.16.1", "koa-router": "^13.1.1", "tslib": "^2.4.0", - "viem": "2.23.7" + "viem": "patch:viem@npm%3A2.23.7#~/.yarn/patches/viem-npm-2.23.7-0552761b08.patch" }, "devDependencies": { "@jest/globals": "^30.0.0", diff --git a/yarn-project/yarn.lock b/yarn-project/yarn.lock index af7293fd29ee..f084dbd08fb0 100644 --- a/yarn-project/yarn.lock +++ b/yarn-project/yarn.lock @@ -765,7 +765,7 @@ __metadata: tsc-watch: "npm:^6.0.0" tslib: "npm:^2.5.0" typescript: "npm:^5.3.3" - viem: "npm:2.23.7" + viem: "patch:viem@npm%3A2.23.7#~/.yarn/patches/viem-npm-2.23.7-0552761b08.patch" languageName: unknown linkType: soft @@ -787,7 +787,7 @@ __metadata: koa-router: "npm:^13.1.1" ts-node: "npm:^10.9.1" typescript: "npm:^5.3.3" - viem: "npm:2.23.7" + viem: "patch:viem@npm%3A2.23.7#~/.yarn/patches/viem-npm-2.23.7-0552761b08.patch" zod: "npm:^3.23.8" bin: aztec-faucet: ./dest/bin/index.js @@ -831,7 +831,7 @@ __metadata: ts-node: "npm:^10.9.1" tslib: "npm:^2.4.0" typescript: "npm:^5.3.3" - viem: "npm:2.23.7" + viem: "patch:viem@npm%3A2.23.7#~/.yarn/patches/viem-npm-2.23.7-0552761b08.patch" bin: aztec-node: ./dest/bin/index.js languageName: unknown @@ -864,7 +864,7 @@ __metadata: tslib: "npm:^2.4.0" typescript: "npm:^5.3.3" util: "npm:^0.12.5" - viem: "npm:2.23.7" + viem: "patch:viem@npm%3A2.23.7#~/.yarn/patches/viem-npm-2.23.7-0552761b08.patch" languageName: unknown linkType: soft @@ -934,7 +934,7 @@ __metadata: koa-router: "npm:^13.1.1" ts-node: "npm:^10.9.1" typescript: "npm:^5.3.3" - viem: "npm:2.23.7" + viem: "patch:viem@npm%3A2.23.7#~/.yarn/patches/viem-npm-2.23.7-0552761b08.patch" bin: aztec: ./dest/bin/index.js languageName: unknown @@ -971,7 +971,7 @@ __metadata: ts-node: "npm:^10.9.1" tslib: "npm:^2.4.0" typescript: "npm:^5.3.3" - viem: "npm:2.23.7" + viem: "patch:viem@npm%3A2.23.7#~/.yarn/patches/viem-npm-2.23.7-0552761b08.patch" bin: bb-cli: ./dest/bb/index.js languageName: unknown @@ -1002,7 +1002,7 @@ __metadata: "@jest/globals": "npm:^30.0.0" "@types/jest": "npm:^30.0.0" "@types/node": "npm:^22.15.17" - c-kzg: "npm:4.0.0-alpha.1" + c-kzg: "npm:4.1.0" get-port: "npm:^7.1.0" jest: "npm:^30.0.0" ts-node: "npm:^10.9.1" @@ -1035,7 +1035,7 @@ __metadata: ts-node: "npm:^10.9.1" tslib: "npm:^2.4.0" typescript: "npm:^5.3.3" - viem: "npm:2.23.7" + viem: "patch:viem@npm%3A2.23.7#~/.yarn/patches/viem-npm-2.23.7-0552761b08.patch" zod: "npm:^3.23.8" bin: blob-sink-client: ./dest/client/bin/index.js @@ -1159,7 +1159,7 @@ __metadata: ts-node: "npm:^10.9.1" tslib: "npm:^2.4.0" typescript: "npm:^5.3.3" - viem: "npm:2.23.7" + viem: "patch:viem@npm%3A2.23.7#~/.yarn/patches/viem-npm-2.23.7-0552761b08.patch" peerDependencies: "@aztec/accounts": "workspace:^" "@aztec/bb-prover": "workspace:^" @@ -1277,7 +1277,7 @@ __metadata: tslib: "npm:^2.4.0" typescript: "npm:^5.3.3" util: "npm:^0.12.5" - viem: "npm:2.23.7" + viem: "patch:viem@npm%3A2.23.7#~/.yarn/patches/viem-npm-2.23.7-0552761b08.patch" zod: "npm:^3.23.8" languageName: unknown linkType: soft @@ -1318,7 +1318,7 @@ __metadata: ts-node: "npm:^10.9.1" tslib: "npm:^2.4.0" typescript: "npm:^5.3.3" - viem: "npm:2.23.7" + viem: "patch:viem@npm%3A2.23.7#~/.yarn/patches/viem-npm-2.23.7-0552761b08.patch" zod: "npm:^3.23.8" languageName: unknown linkType: soft @@ -1347,7 +1347,7 @@ __metadata: ts-node: "npm:^10.9.1" tslib: "npm:^2.4.0" typescript: "npm:^5.3.3" - viem: "npm:2.23.7" + viem: "patch:viem@npm%3A2.23.7#~/.yarn/patches/viem-npm-2.23.7-0552761b08.patch" zod: "npm:^3.23.8" languageName: unknown linkType: soft @@ -1404,7 +1404,7 @@ __metadata: typescript: "npm:^5.3.3" typescript-eslint: "npm:^8.32.1" undici: "npm:^5.28.5" - viem: "npm:2.23.7" + viem: "patch:viem@npm%3A2.23.7#~/.yarn/patches/viem-npm-2.23.7-0552761b08.patch" zod: "npm:^3.23.8" languageName: unknown linkType: soft @@ -1569,7 +1569,7 @@ __metadata: ts-node: "npm:^10.9.1" tslib: "npm:^2.4.0" typescript: "npm:^5.3.3" - viem: "npm:2.23.7" + viem: "patch:viem@npm%3A2.23.7#~/.yarn/patches/viem-npm-2.23.7-0552761b08.patch" zod: "npm:^3.23.8" languageName: unknown linkType: soft @@ -1782,7 +1782,7 @@ __metadata: tslib: "npm:^2.4.0" typescript: "npm:^5.3.3" uint8arrays: "npm:^5.0.3" - viem: "npm:2.23.7" + viem: "patch:viem@npm%3A2.23.7#~/.yarn/patches/viem-npm-2.23.7-0552761b08.patch" xxhash-wasm: "npm:^1.1.0" languageName: unknown linkType: soft @@ -1882,7 +1882,7 @@ __metadata: ts-node: "npm:^10.9.1" tslib: "npm:^2.4.0" typescript: "npm:^5.3.3" - viem: "npm:2.23.7" + viem: "patch:viem@npm%3A2.23.7#~/.yarn/patches/viem-npm-2.23.7-0552761b08.patch" languageName: unknown linkType: soft @@ -1921,7 +1921,7 @@ __metadata: ts-node: "npm:^10.9.1" tslib: "npm:^2.4.0" typescript: "npm:^5.3.3" - viem: "npm:2.23.7" + viem: "patch:viem@npm%3A2.23.7#~/.yarn/patches/viem-npm-2.23.7-0552761b08.patch" bin: pxe: ./dest/bin/index.js languageName: unknown @@ -1992,7 +1992,7 @@ __metadata: ts-node: "npm:^10.9.1" tslib: "npm:^2.4.0" typescript: "npm:^5.3.3" - viem: "npm:2.23.7" + viem: "patch:viem@npm%3A2.23.7#~/.yarn/patches/viem-npm-2.23.7-0552761b08.patch" languageName: unknown linkType: soft @@ -2026,7 +2026,7 @@ __metadata: ts-node: "npm:^10.9.1" tslib: "npm:^2.4.0" typescript: "npm:^5.3.3" - viem: "npm:2.23.7" + viem: "patch:viem@npm%3A2.23.7#~/.yarn/patches/viem-npm-2.23.7-0552761b08.patch" languageName: unknown linkType: soft @@ -2052,7 +2052,7 @@ __metadata: ts-node: "npm:^10.9.1" tslib: "npm:^2.4.0" typescript: "npm:^5.3.3" - viem: "npm:2.23.7" + viem: "patch:viem@npm%3A2.23.7#~/.yarn/patches/viem-npm-2.23.7-0552761b08.patch" zod: "npm:^3.23.8" languageName: unknown linkType: soft @@ -2095,7 +2095,7 @@ __metadata: ts-node: "npm:^10.9.1" tslib: "npm:^2.4.0" typescript: "npm:^5.3.3" - viem: "npm:2.23.7" + viem: "patch:viem@npm%3A2.23.7#~/.yarn/patches/viem-npm-2.23.7-0552761b08.patch" zod: "npm:^3.23.8" languageName: unknown linkType: soft @@ -2127,7 +2127,7 @@ __metadata: prom-client: "npm:^15.1.3" ts-node: "npm:^10.9.1" typescript: "npm:^5.3.3" - viem: "npm:2.23.7" + viem: "patch:viem@npm%3A2.23.7#~/.yarn/patches/viem-npm-2.23.7-0552761b08.patch" languageName: unknown linkType: soft @@ -2186,7 +2186,7 @@ __metadata: ts-node: "npm:^10.9.1" tslib: "npm:^2.4.0" typescript: "npm:^5.3.3" - viem: "npm:2.23.7" + viem: "patch:viem@npm%3A2.23.7#~/.yarn/patches/viem-npm-2.23.7-0552761b08.patch" bin: validator-client: ./dest/bin/index.js languageName: unknown @@ -10099,14 +10099,14 @@ __metadata: languageName: node linkType: hard -"c-kzg@npm:4.0.0-alpha.1": - version: 4.0.0-alpha.1 - resolution: "c-kzg@npm:4.0.0-alpha.1" +"c-kzg@npm:4.1.0": + version: 4.1.0 + resolution: "c-kzg@npm:4.1.0" dependencies: bindings: "npm:^1.5.0" - node-addon-api: "npm:^5.0.0" + node-addon-api: "npm:^8.3.1" node-gyp: "npm:latest" - checksum: 10/4095348ee345cc6db318e52fd14a6619200e5e76e5b9dcd665948bcb0b5273deb97833d910ac2aaa1ee6697610af36998f122c36a3ecb7bd674e3343328fcb42 + checksum: 10/c5caf4b0d16ebb4890c3eb5b0a7c79792295c733767c1279fee4255a5aaab1eecbbf633ceb54a9102707d111e749da73465eeb07921bcdf7cc0126ceb7457100 languageName: node linkType: hard @@ -17634,21 +17634,21 @@ __metadata: languageName: node linkType: hard -"node-addon-api@npm:^5.0.0": - version: 5.1.0 - resolution: "node-addon-api@npm:5.1.0" +"node-addon-api@npm:^6.1.0": + version: 6.1.0 + resolution: "node-addon-api@npm:6.1.0" dependencies: node-gyp: "npm:latest" - checksum: 10/595f59ffb4630564f587c502119cbd980d302e482781021f3b479f5fc7e41cf8f2f7280fdc2795f32d148e4f3259bd15043c52d4a3442796aa6f1ae97b959636 + checksum: 10/8eea1d4d965930a177a0508695beb0d89b4c1d80bf330646a035357a1e8fc31e0d09686e2374996e96e757b947a7ece319f98ede3146683f162597c0bcb4df90 languageName: node linkType: hard -"node-addon-api@npm:^6.1.0": - version: 6.1.0 - resolution: "node-addon-api@npm:6.1.0" +"node-addon-api@npm:^8.3.1": + version: 8.5.0 + resolution: "node-addon-api@npm:8.5.0" dependencies: node-gyp: "npm:latest" - checksum: 10/8eea1d4d965930a177a0508695beb0d89b4c1d80bf330646a035357a1e8fc31e0d09686e2374996e96e757b947a7ece319f98ede3146683f162597c0bcb4df90 + checksum: 10/9a893f4f835fbc3908e0070f7bcacf36e37fd06be8008409b104c30df4092a0d9a29927b3a74cdbc1d34338274ba4116d597a41f573e06c29538a1a70d07413f languageName: node linkType: hard @@ -22183,6 +22183,27 @@ __metadata: languageName: node linkType: hard +"viem@patch:viem@npm%3A2.23.7#~/.yarn/patches/viem-npm-2.23.7-0552761b08.patch": + version: 2.23.7 + resolution: "viem@patch:viem@npm%3A2.23.7#~/.yarn/patches/viem-npm-2.23.7-0552761b08.patch::version=2.23.7&hash=ac9049" + dependencies: + "@noble/curves": "npm:1.8.1" + "@noble/hashes": "npm:1.7.1" + "@scure/bip32": "npm:1.6.2" + "@scure/bip39": "npm:1.5.4" + abitype: "npm:1.0.8" + isows: "npm:1.0.6" + ox: "npm:0.6.7" + ws: "npm:8.18.0" + peerDependencies: + typescript: ">=5.0.4" + peerDependenciesMeta: + typescript: + optional: true + checksum: 10/9ba32cf004ff9222bbab49d1066362c63161eae0dbe746b7c19da9c242f52ff173f3346eea3fc91b2c087267bbd7011679ae41c4cddb5a9fe7878d193f1e26ca + languageName: node + linkType: hard + "vite@npm:^7.1.7": version: 7.1.7 resolution: "vite@npm:7.1.7"