Skip to content

Commit

Permalink
add new error DUPLICATE_DEPOSIT_DATA
Browse files Browse the repository at this point in the history
  • Loading branch information
dfkadyr committed Sep 16, 2024
1 parent a6d3670 commit a0b80ed
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 4 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ self.addEventListener('message', async (event) => {
| `INVALID_JSON_FORMAT` | Deposit data file must be in JSON format
| `MERKLE_TREE_GENERATION_ERROR` | Failed to generate the Merkle tree
| `INVALID_PUBLIC_KEY_FORMAT` | Failed to parse deposit data public key
| `DUPLICATE_DEPOSIT_DATA` | The deposit data file has already been uploaded.
| `INVALID_WITHDRAW_ADDRESS` | The withdrawal addresses don’t match Eigen pods
| `MISSING_FIELDS` | Failed to verify the deposit data public keys. Missing fields: {fields}
| `DUPLICATE_PUBLIC_KEYS` | Failed to verify the deposit data public keys. All the entries must be unique.
Expand Down
9 changes: 9 additions & 0 deletions src/parser/depositDataParser.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { depositDataParser } from './index'
const testData = mockData[0]

const validInput: ParserInput = {
depositDataRoot: '0x406de60516154112c876f7250d8b289d4e3d840074e8cf755922dd',
vaultAddress: '0x9b6a6867d222d62dc301528190e3984d60adb06b',
network: 'holesky',
data: mockData,
Expand Down Expand Up @@ -95,5 +96,13 @@ describe('depositDataParser',() => {
await expect(depositDataParser({ ...validInput, data: [] })).rejects.toThrow(errorText)
})

it('throws ParserError if the deposit data file has already been uploaded', async () => {
const errorText = new ParserError(ErrorTypes.DUPLICATE_DEPOSIT_DATA)

await expect(depositDataParser({
...validInput, depositDataRoot: '0x406de60516154112c876f7250d8b289d4e3d840074e8cf755922dd5d3c75d1c0',
})).rejects.toThrow(errorText)
})

})

8 changes: 7 additions & 1 deletion src/parser/getPostMessage.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,28 @@
import { StandardMerkleTree } from '@openzeppelin/merkle-tree'

import type { DepositDataFile, ParserOutput } from './types'
import { ParserError, ErrorTypes } from './helpers'


type Input = {
pubkeySet: Set<string>
depositDataRoot: string
treeLeaves: Uint8Array[]
parsedFile: DepositDataFile
}

const getPostMessage = (values: Input) => {
const { pubkeySet, treeLeaves, parsedFile } = values
const { depositDataRoot, pubkeySet, treeLeaves, parsedFile } = values

const merkleTree = StandardMerkleTree.of(
treeLeaves.map((value, index) => [ value, index ]),
[ 'bytes', 'uint256' ]
)

if (depositDataRoot === merkleTree.root) {
throw new ParserError(ErrorTypes.DUPLICATE_DEPOSIT_DATA)
}

const postMessage: ParserOutput = {
merkleRoot: merkleTree.root,
validators: parsedFile?.length || 0,
Expand Down
4 changes: 3 additions & 1 deletion src/parser/helpers/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ type DynamicValues = Record<string, any>

export enum ErrorTypes {
EMPTY_FILE = 'EMPTY_FILE',
EIGEN_PODS_EMPTY = 'EIGEN_PODS_EMPTY',
MISSING_FIELDS = 'MISSING_FIELDS',
EIGEN_PODS_EMPTY = 'EIGEN_PODS_EMPTY',
INVALID_SIGNATURE = 'INVALID_SIGNATURE',
INVALID_JSON_FORMAT = 'INVALID_JSON_FORMAT',
DUPLICATE_PUBLIC_KEYS = 'DUPLICATE_PUBLIC_KEYS',
DUPLICATE_DEPOSIT_DATA = 'DUPLICATE_DEPOSIT_DATA',
INVALID_WITHDRAW_ADDRESS = 'INVALID_WITHDRAW_ADDRESS',
INVALID_PUBLIC_KEY_FORMAT = 'INVALID_PUBLIC_KEY_FORMAT',
MERKLE_TREE_GENERATION_ERROR = 'MERKLE_TREE_GENERATION_ERROR',
Expand All @@ -18,6 +19,7 @@ export const ErrorMessages: Record<ErrorTypes, string> = {
[ErrorTypes.INVALID_JSON_FORMAT]: 'Deposit data file must be in JSON format.',
[ErrorTypes.MERKLE_TREE_GENERATION_ERROR]: 'Failed to generate the Merkle tree',
[ErrorTypes.INVALID_PUBLIC_KEY_FORMAT]: 'Failed to parse deposit data public key',
[ErrorTypes.DUPLICATE_DEPOSIT_DATA]: `The deposit data file has already been uploaded.`,
[ErrorTypes.INVALID_WITHDRAW_ADDRESS]: `The withdrawal addresses don’t match Eigen pods`,
[ErrorTypes.MISSING_FIELDS]: 'Failed to verify the deposit data public keys. Missing fields: {fields}',
[ErrorTypes.DUPLICATE_PUBLIC_KEYS]: 'Failed to verify the deposit data public keys. All the entries must be unique.',
Expand Down
4 changes: 2 additions & 2 deletions src/parser/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import verifySignature from './verifySignature'


export const depositDataParser = async (input: ParserInput) => {
const { vaultAddress, network, data, onProgress } = input
const { vaultAddress, depositDataRoot, network, data, onProgress } = input

const bls = await initBls()
const parsedFile = validateJson({ data })
Expand Down Expand Up @@ -46,5 +46,5 @@ export const depositDataParser = async (input: ParserInput) => {
throw new ParserError(ErrorTypes.DUPLICATE_PUBLIC_KEYS)
}

return getPostMessage({ pubkeySet, parsedFile, treeLeaves })
return getPostMessage({ pubkeySet, parsedFile, treeLeaves, depositDataRoot })
}
1 change: 1 addition & 0 deletions src/parser/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export type DepositData = {
export type ParserInput = {
data: DepositDataFile
vaultAddress: string
depositDataRoot: string
network: SupportedNetworks
onProgress?: (progress: Progress) => void
}
Expand Down

0 comments on commit a0b80ed

Please sign in to comment.