diff --git a/eigenda/eigenda.go b/eigenda/eigenda.go index 07be3f950..73e7224ed 100644 --- a/eigenda/eigenda.go +++ b/eigenda/eigenda.go @@ -7,8 +7,10 @@ import ( "errors" "fmt" "math/big" + "strings" "github.com/Layr-Labs/eigenda/api/grpc/disperser" + "github.com/ethereum/go-ethereum/accounts/abi" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/rlp" @@ -27,6 +29,16 @@ func hasBits(checking byte, bits byte) bool { return (checking & bits) == bits } +type payload struct { + SequenceNumber *big.Int + BlobVerificationProof *BlobVerificationProof + BlobHeader *BlobHeader + AfterDelayedMessagesRead *big.Int + GasRefunder *common.Address + PrevMessageCount *big.Int + NewMessageCount *big.Int +} + type EigenDAWriter interface { Store(context.Context, []byte) (*EigenDABlobID, *EigenDABlobInfo, error) Serialize(eigenDABlobID *EigenDABlobID) ([]byte, error) @@ -77,24 +89,24 @@ type QuorumBlobParams struct { } type BlobVerificationProof struct { - BatchID uint32 - BlobIndex uint32 - BatchMetadata *BatchMetadata - InclusionProof []byte - QuorumIndices []byte + BatchID uint32 `json:"batchId"` + BlobIndex uint32 `json:"blobIndex"` + BatchMetadata BatchMetadata `json:"batchMetadata"` + InclusionProof []byte `json:"inclusionProof"` + QuorumIndices []byte `json:"quorumIndices"` } type BatchMetadata struct { - BatchHeader *BatchHeader - SignatoryRecordHash [32]byte - ConfirmationBlockNumber uint32 + BatchHeader BatchHeader `json:"batchHeader"` + SignatoryRecordHash [32]byte `json:"signatoryRecordHash"` + ConfirmationBlockNumber uint32 `json:"confirmationBlockNumber"` } type BatchHeader struct { - BlobHeadersRoot []byte - QuorumNumbers []byte - QuorumSignedPercentages []byte - ReferenceBlockNumber uint32 + BlobHeadersRoot [32]byte `json:"blobHeadersRoot"` + QuorumNumbers []byte `json:"quorumNumbers"` + SignedStakeForQuorums []byte `json:"signedStakeForQuorums"` + ReferenceBlockNumber uint32 `json:"referenceBlockNumber"` } type EigenDA struct { @@ -157,8 +169,8 @@ func (b *EigenDABlobInfo) loadBlobInfo(disperserBlobInfo *disperser.BlobInfo) { b.BlobVerificationProof.BatchID = disperserBlobInfo.GetBlobVerificationProof().GetBatchId() b.BlobVerificationProof.BlobIndex = disperserBlobInfo.GetBlobVerificationProof().GetBlobIndex() - b.BlobVerificationProof.BatchMetadata = &BatchMetadata{ - BatchHeader: &BatchHeader{}, + b.BlobVerificationProof.BatchMetadata = BatchMetadata{ + BatchHeader: BatchHeader{}, SignatoryRecordHash: signatoryRecordHash, ConfirmationBlockNumber: disperserBlobInfo.GetBlobVerificationProof().GetBatchMetadata().GetConfirmationBlockNumber(), } @@ -166,9 +178,9 @@ func (b *EigenDABlobInfo) loadBlobInfo(disperserBlobInfo *disperser.BlobInfo) { b.BlobVerificationProof.InclusionProof = disperserBlobInfo.GetBlobVerificationProof().GetInclusionProof() b.BlobVerificationProof.QuorumIndices = disperserBlobInfo.GetBlobVerificationProof().GetQuorumIndexes() - b.BlobVerificationProof.BatchMetadata.BatchHeader.BlobHeadersRoot = disperserBlobInfo.GetBlobVerificationProof().GetBatchMetadata().GetBatchHeader().GetBatchRoot() + //b.BlobVerificationProof.BatchMetadata.BatchHeader.BlobHeadersRoot = disperserBlobInfo.GetBlobVerificationProof().GetBatchMetadata().GetBatchHeader().GetBatchRoot() b.BlobVerificationProof.BatchMetadata.BatchHeader.QuorumNumbers = disperserBlobInfo.GetBlobVerificationProof().GetBatchMetadata().GetBatchHeader().GetQuorumNumbers() - b.BlobVerificationProof.BatchMetadata.BatchHeader.QuorumSignedPercentages = disperserBlobInfo.GetBlobVerificationProof().GetBatchMetadata().GetBatchHeader().GetQuorumSignedPercentages() + b.BlobVerificationProof.BatchMetadata.BatchHeader.SignedStakeForQuorums = disperserBlobInfo.GetBlobVerificationProof().GetBatchMetadata().GetBatchHeader().GetQuorumSignedPercentages() b.BlobVerificationProof.BatchMetadata.BatchHeader.ReferenceBlockNumber = disperserBlobInfo.GetBlobVerificationProof().GetBatchMetadata().GetBatchHeader().GetReferenceBlockNumber() } @@ -257,26 +269,46 @@ func RecoverPayloadFromEigenDABatch(ctx context.Context, // InclusionProof func ParseSequencerMsg(calldata []byte) *EigenDABlobInfo { - var blobVerificationProof *BlobVerificationProof - var blobHeader *BlobHeader + + // blobVerificationProof := &BlobVerificationProof{} + // blobHeader := &BlobHeader{} // try decoding at the offsets - blobVerificationProofOffset, err := convertCalldataToInt(calldata[36:68]) + // blobVerificationProofOffset, err := convertCalldataToInt(calldata[36:68]) + // if err != nil { + // // todo handle later + // panic(err) + // } + + // blobVerificationProofOffset += 4 + + // blobHeaderOffset, err := convertCalldataToInt(calldata[68:100]) + // if err != nil { + // // todo handle later + // panic(err) + // } + + sequencerInboxABI := `[ { "inputs": [ { "internalType": "uint256", "name": "_maxDataSize", "type": "uint256" }, { "internalType": "contract IReader4844", "name": "reader4844_", "type": "address" }, { "internalType": "contract IEigenDAServiceManager", "name": "eigenDAServiceManager_", "type": "address" }, { "internalType": "contract IRollupManager", "name": "eigenDARollupManager_", "type": "address" }, { "internalType": "bool", "name": "_isUsingFeeToken", "type": "bool" } ], "stateMutability": "nonpayable", "type": "constructor" }, { "inputs": [], "name": "AlreadyInit", "type": "error" }, { "inputs": [ { "internalType": "bytes32", "name": "", "type": "bytes32" } ], "name": "AlreadyValidDASKeyset", "type": "error" }, { "inputs": [], "name": "BadMaxTimeVariation", "type": "error" }, { "inputs": [], "name": "BadPostUpgradeInit", "type": "error" }, { "inputs": [ { "internalType": "uint256", "name": "stored", "type": "uint256" }, { "internalType": "uint256", "name": "received", "type": "uint256" } ], "name": "BadSequencerNumber", "type": "error" }, { "inputs": [], "name": "DataBlobsNotSupported", "type": "error" }, { "inputs": [ { "internalType": "uint256", "name": "dataLength", "type": "uint256" }, { "internalType": "uint256", "name": "maxDataLength", "type": "uint256" } ], "name": "DataTooLarge", "type": "error" }, { "inputs": [], "name": "DelayedBackwards", "type": "error" }, { "inputs": [], "name": "DelayedTooFar", "type": "error" }, { "inputs": [], "name": "Deprecated", "type": "error" }, { "inputs": [], "name": "ForceIncludeBlockTooSoon", "type": "error" }, { "inputs": [], "name": "ForceIncludeTimeTooSoon", "type": "error" }, { "inputs": [], "name": "HadZeroInit", "type": "error" }, { "inputs": [], "name": "IncorrectMessagePreimage", "type": "error" }, { "inputs": [ { "internalType": "string", "name": "name", "type": "string" } ], "name": "InitParamZero", "type": "error" }, { "inputs": [ { "internalType": "bytes1", "name": "", "type": "bytes1" } ], "name": "InvalidHeaderFlag", "type": "error" }, { "inputs": [], "name": "MissingDataHashes", "type": "error" }, { "inputs": [], "name": "NativeTokenMismatch", "type": "error" }, { "inputs": [ { "internalType": "bytes32", "name": "", "type": "bytes32" } ], "name": "NoSuchKeyset", "type": "error" }, { "inputs": [], "name": "NotBatchPoster", "type": "error" }, { "inputs": [ { "internalType": "address", "name": "", "type": "address" } ], "name": "NotBatchPosterManager", "type": "error" }, { "inputs": [], "name": "NotForked", "type": "error" }, { "inputs": [], "name": "NotOrigin", "type": "error" }, { "inputs": [ { "internalType": "address", "name": "sender", "type": "address" }, { "internalType": "address", "name": "owner", "type": "address" } ], "name": "NotOwner", "type": "error" }, { "inputs": [], "name": "RollupNotChanged", "type": "error" }, { "anonymous": false, "inputs": [ { "indexed": true, "internalType": "uint256", "name": "messageNum", "type": "uint256" }, { "indexed": false, "internalType": "bytes", "name": "data", "type": "bytes" } ], "name": "InboxMessageDelivered", "type": "event" }, { "anonymous": false, "inputs": [ { "indexed": true, "internalType": "uint256", "name": "messageNum", "type": "uint256" } ], "name": "InboxMessageDeliveredFromOrigin", "type": "event" }, { "anonymous": false, "inputs": [ { "indexed": true, "internalType": "bytes32", "name": "keysetHash", "type": "bytes32" } ], "name": "InvalidateKeyset", "type": "event" }, { "anonymous": false, "inputs": [ { "indexed": true, "internalType": "uint256", "name": "id", "type": "uint256" } ], "name": "OwnerFunctionCalled", "type": "event" }, { "anonymous": false, "inputs": [ { "indexed": true, "internalType": "uint256", "name": "batchSequenceNumber", "type": "uint256" }, { "indexed": false, "internalType": "bytes", "name": "data", "type": "bytes" } ], "name": "SequencerBatchData", "type": "event" }, { "anonymous": false, "inputs": [ { "indexed": true, "internalType": "uint256", "name": "batchSequenceNumber", "type": "uint256" }, { "indexed": true, "internalType": "bytes32", "name": "beforeAcc", "type": "bytes32" }, { "indexed": true, "internalType": "bytes32", "name": "afterAcc", "type": "bytes32" }, { "indexed": false, "internalType": "bytes32", "name": "delayedAcc", "type": "bytes32" }, { "indexed": false, "internalType": "uint256", "name": "afterDelayedMessagesRead", "type": "uint256" }, { "components": [ { "internalType": "uint64", "name": "minTimestamp", "type": "uint64" }, { "internalType": "uint64", "name": "maxTimestamp", "type": "uint64" }, { "internalType": "uint64", "name": "minBlockNumber", "type": "uint64" }, { "internalType": "uint64", "name": "maxBlockNumber", "type": "uint64" } ], "indexed": false, "internalType": "struct IBridge.TimeBounds", "name": "timeBounds", "type": "tuple" }, { "indexed": false, "internalType": "enum IBridge.BatchDataLocation", "name": "dataLocation", "type": "uint8" } ], "name": "SequencerBatchDelivered", "type": "event" }, { "anonymous": false, "inputs": [ { "indexed": true, "internalType": "bytes32", "name": "keysetHash", "type": "bytes32" }, { "indexed": false, "internalType": "bytes", "name": "keysetBytes", "type": "bytes" } ], "name": "SetValidKeyset", "type": "event" }, { "inputs": [], "name": "BROTLI_MESSAGE_HEADER_FLAG", "outputs": [ { "internalType": "bytes1", "name": "", "type": "bytes1" } ], "stateMutability": "view", "type": "function" }, { "inputs": [], "name": "DAS_MESSAGE_HEADER_FLAG", "outputs": [ { "internalType": "bytes1", "name": "", "type": "bytes1" } ], "stateMutability": "view", "type": "function" }, { "inputs": [], "name": "DATA_AUTHENTICATED_FLAG", "outputs": [ { "internalType": "bytes1", "name": "", "type": "bytes1" } ], "stateMutability": "view", "type": "function" }, { "inputs": [], "name": "DATA_BLOB_HEADER_FLAG", "outputs": [ { "internalType": "bytes1", "name": "", "type": "bytes1" } ], "stateMutability": "view", "type": "function" }, { "inputs": [], "name": "EIGENDA_MESSAGE_HEADER_FLAG", "outputs": [ { "internalType": "bytes1", "name": "", "type": "bytes1" } ], "stateMutability": "view", "type": "function" }, { "inputs": [], "name": "HEADER_LENGTH", "outputs": [ { "internalType": "uint256", "name": "", "type": "uint256" } ], "stateMutability": "view", "type": "function" }, { "inputs": [], "name": "TREE_DAS_MESSAGE_HEADER_FLAG", "outputs": [ { "internalType": "bytes1", "name": "", "type": "bytes1" } ], "stateMutability": "view", "type": "function" }, { "inputs": [], "name": "ZERO_HEAVY_MESSAGE_HEADER_FLAG", "outputs": [ { "internalType": "bytes1", "name": "", "type": "bytes1" } ], "stateMutability": "view", "type": "function" }, { "inputs": [ { "internalType": "uint256", "name": "sequenceNumber", "type": "uint256" }, { "internalType": "bytes", "name": "data", "type": "bytes" }, { "internalType": "uint256", "name": "afterDelayedMessagesRead", "type": "uint256" }, { "internalType": "contract IGasRefunder", "name": "gasRefunder", "type": "address" }, { "internalType": "uint256", "name": "prevMessageCount", "type": "uint256" }, { "internalType": "uint256", "name": "newMessageCount", "type": "uint256" } ], "name": "addSequencerL2Batch", "outputs": [], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [ { "internalType": "uint256", "name": "sequenceNumber", "type": "uint256" }, { "internalType": "uint256", "name": "afterDelayedMessagesRead", "type": "uint256" }, { "internalType": "contract IGasRefunder", "name": "gasRefunder", "type": "address" }, { "internalType": "uint256", "name": "prevMessageCount", "type": "uint256" }, { "internalType": "uint256", "name": "newMessageCount", "type": "uint256" } ], "name": "addSequencerL2BatchFromBlobs", "outputs": [], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [ { "internalType": "uint256", "name": "sequenceNumber", "type": "uint256" }, { "components": [ { "internalType": "uint32", "name": "batchId", "type": "uint32" }, { "internalType": "uint32", "name": "blobIndex", "type": "uint32" }, { "components": [ { "components": [ { "internalType": "bytes32", "name": "blobHeadersRoot", "type": "bytes32" }, { "internalType": "bytes", "name": "quorumNumbers", "type": "bytes" }, { "internalType": "bytes", "name": "signedStakeForQuorums", "type": "bytes" }, { "internalType": "uint32", "name": "referenceBlockNumber", "type": "uint32" } ], "internalType": "struct IEigenDAServiceManager.BatchHeader", "name": "batchHeader", "type": "tuple" }, { "internalType": "bytes32", "name": "signatoryRecordHash", "type": "bytes32" }, { "internalType": "uint32", "name": "confirmationBlockNumber", "type": "uint32" } ], "internalType": "struct IEigenDAServiceManager.BatchMetadata", "name": "batchMetadata", "type": "tuple" }, { "internalType": "bytes", "name": "inclusionProof", "type": "bytes" }, { "internalType": "bytes", "name": "quorumIndices", "type": "bytes" } ], "internalType": "struct EigenDARollupUtils.BlobVerificationProof", "name": "blobVerificationProof", "type": "tuple" }, { "components": [ { "components": [ { "internalType": "uint256", "name": "X", "type": "uint256" }, { "internalType": "uint256", "name": "Y", "type": "uint256" } ], "internalType": "struct BN254.G1Point", "name": "commitment", "type": "tuple" }, { "internalType": "uint32", "name": "dataLength", "type": "uint32" }, { "components": [ { "internalType": "uint8", "name": "quorumNumber", "type": "uint8" }, { "internalType": "uint8", "name": "adversaryThresholdPercentage", "type": "uint8" }, { "internalType": "uint8", "name": "confirmationThresholdPercentage", "type": "uint8" }, { "internalType": "uint32", "name": "chunkLength", "type": "uint32" } ], "internalType": "struct IEigenDAServiceManager.QuorumBlobParam[]", "name": "quorumBlobParams", "type": "tuple[]" } ], "internalType": "struct IEigenDAServiceManager.BlobHeader", "name": "blobHeader", "type": "tuple" }, { "internalType": "uint256", "name": "afterDelayedMessagesRead", "type": "uint256" }, { "internalType": "contract IGasRefunder", "name": "gasRefunder", "type": "address" }, { "internalType": "uint256", "name": "prevMessageCount", "type": "uint256" }, { "internalType": "uint256", "name": "newMessageCount", "type": "uint256" } ], "name": "addSequencerL2BatchFromEigenDA", "outputs": [], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [ { "internalType": "uint256", "name": "", "type": "uint256" }, { "internalType": "bytes", "name": "", "type": "bytes" }, { "internalType": "uint256", "name": "", "type": "uint256" }, { "internalType": "contract IGasRefunder", "name": "", "type": "address" } ], "name": "addSequencerL2BatchFromOrigin", "outputs": [], "stateMutability": "pure", "type": "function" }, { "inputs": [ { "internalType": "uint256", "name": "sequenceNumber", "type": "uint256" }, { "internalType": "bytes", "name": "data", "type": "bytes" }, { "internalType": "uint256", "name": "afterDelayedMessagesRead", "type": "uint256" }, { "internalType": "contract IGasRefunder", "name": "gasRefunder", "type": "address" }, { "internalType": "uint256", "name": "prevMessageCount", "type": "uint256" }, { "internalType": "uint256", "name": "newMessageCount", "type": "uint256" } ], "name": "addSequencerL2BatchFromOrigin", "outputs": [], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [], "name": "batchCount", "outputs": [ { "internalType": "uint256", "name": "", "type": "uint256" } ], "stateMutability": "view", "type": "function" }, { "inputs": [], "name": "batchPosterManager", "outputs": [ { "internalType": "address", "name": "", "type": "address" } ], "stateMutability": "view", "type": "function" }, { "inputs": [], "name": "bridge", "outputs": [ { "internalType": "contract IBridge", "name": "", "type": "address" } ], "stateMutability": "view", "type": "function" }, { "inputs": [ { "internalType": "bytes32", "name": "", "type": "bytes32" } ], "name": "dasKeySetInfo", "outputs": [ { "internalType": "bool", "name": "isValidKeyset", "type": "bool" }, { "internalType": "uint64", "name": "creationBlock", "type": "uint64" } ], "stateMutability": "view", "type": "function" }, { "inputs": [], "name": "eigenDARollupManager", "outputs": [ { "internalType": "contract IRollupManager", "name": "", "type": "address" } ], "stateMutability": "view", "type": "function" }, { "inputs": [], "name": "eigenDAServiceManager", "outputs": [ { "internalType": "contract IEigenDAServiceManager", "name": "", "type": "address" } ], "stateMutability": "view", "type": "function" }, { "inputs": [ { "internalType": "uint256", "name": "_totalDelayedMessagesRead", "type": "uint256" }, { "internalType": "uint8", "name": "kind", "type": "uint8" }, { "internalType": "uint64[2]", "name": "l1BlockAndTime", "type": "uint64[2]" }, { "internalType": "uint256", "name": "baseFeeL1", "type": "uint256" }, { "internalType": "address", "name": "sender", "type": "address" }, { "internalType": "bytes32", "name": "messageDataHash", "type": "bytes32" } ], "name": "forceInclusion", "outputs": [], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [ { "internalType": "bytes32", "name": "ksHash", "type": "bytes32" } ], "name": "getKeysetCreationBlock", "outputs": [ { "internalType": "uint256", "name": "", "type": "uint256" } ], "stateMutability": "view", "type": "function" }, { "inputs": [ { "internalType": "uint256", "name": "index", "type": "uint256" } ], "name": "inboxAccs", "outputs": [ { "internalType": "bytes32", "name": "", "type": "bytes32" } ], "stateMutability": "view", "type": "function" }, { "inputs": [ { "internalType": "contract IBridge", "name": "bridge_", "type": "address" }, { "components": [ { "internalType": "uint256", "name": "delayBlocks", "type": "uint256" }, { "internalType": "uint256", "name": "futureBlocks", "type": "uint256" }, { "internalType": "uint256", "name": "delaySeconds", "type": "uint256" }, { "internalType": "uint256", "name": "futureSeconds", "type": "uint256" } ], "internalType": "struct ISequencerInbox.MaxTimeVariation", "name": "maxTimeVariation_", "type": "tuple" } ], "name": "initialize", "outputs": [], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [ { "internalType": "bytes32", "name": "ksHash", "type": "bytes32" } ], "name": "invalidateKeysetHash", "outputs": [], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [ { "internalType": "address", "name": "", "type": "address" } ], "name": "isBatchPoster", "outputs": [ { "internalType": "bool", "name": "", "type": "bool" } ], "stateMutability": "view", "type": "function" }, { "inputs": [ { "internalType": "address", "name": "", "type": "address" } ], "name": "isSequencer", "outputs": [ { "internalType": "bool", "name": "", "type": "bool" } ], "stateMutability": "view", "type": "function" }, { "inputs": [], "name": "isUsingFeeToken", "outputs": [ { "internalType": "bool", "name": "", "type": "bool" } ], "stateMutability": "view", "type": "function" }, { "inputs": [ { "internalType": "bytes32", "name": "ksHash", "type": "bytes32" } ], "name": "isValidKeysetHash", "outputs": [ { "internalType": "bool", "name": "", "type": "bool" } ], "stateMutability": "view", "type": "function" }, { "inputs": [], "name": "maxDataSize", "outputs": [ { "internalType": "uint256", "name": "", "type": "uint256" } ], "stateMutability": "view", "type": "function" }, { "inputs": [], "name": "maxTimeVariation", "outputs": [ { "internalType": "uint256", "name": "", "type": "uint256" }, { "internalType": "uint256", "name": "", "type": "uint256" }, { "internalType": "uint256", "name": "", "type": "uint256" }, { "internalType": "uint256", "name": "", "type": "uint256" } ], "stateMutability": "view", "type": "function" }, { "inputs": [], "name": "postUpgradeInit", "outputs": [], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [], "name": "reader4844", "outputs": [ { "internalType": "contract IReader4844", "name": "", "type": "address" } ], "stateMutability": "view", "type": "function" }, { "inputs": [], "name": "removeDelayAfterFork", "outputs": [], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [], "name": "rollup", "outputs": [ { "internalType": "contract IOwnable", "name": "", "type": "address" } ], "stateMutability": "view", "type": "function" }, { "inputs": [ { "internalType": "address", "name": "newBatchPosterManager", "type": "address" } ], "name": "setBatchPosterManager", "outputs": [], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [ { "internalType": "address", "name": "addr", "type": "address" }, { "internalType": "bool", "name": "isBatchPoster_", "type": "bool" } ], "name": "setIsBatchPoster", "outputs": [], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [ { "internalType": "address", "name": "addr", "type": "address" }, { "internalType": "bool", "name": "isSequencer_", "type": "bool" } ], "name": "setIsSequencer", "outputs": [], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [ { "components": [ { "internalType": "uint256", "name": "delayBlocks", "type": "uint256" }, { "internalType": "uint256", "name": "futureBlocks", "type": "uint256" }, { "internalType": "uint256", "name": "delaySeconds", "type": "uint256" }, { "internalType": "uint256", "name": "futureSeconds", "type": "uint256" } ], "internalType": "struct ISequencerInbox.MaxTimeVariation", "name": "maxTimeVariation_", "type": "tuple" } ], "name": "setMaxTimeVariation", "outputs": [], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [ { "internalType": "bytes", "name": "keysetBytes", "type": "bytes" } ], "name": "setValidKeyset", "outputs": [], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [], "name": "totalDelayedMessagesRead", "outputs": [ { "internalType": "uint256", "name": "", "type": "uint256" } ], "stateMutability": "view", "type": "function" }, { "inputs": [ { "internalType": "address", "name": "newEigenDAServiceManager", "type": "address" } ], "name": "updateEigenDAServiceManager", "outputs": [], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [], "name": "updateRollupAddress", "outputs": [], "stateMutability": "nonpayable", "type": "function" } ]` + + abi, err := abi.JSON(strings.NewReader(sequencerInboxABI)) if err != nil { - // todo handle later panic(err) } - blobVerificationProofOffset += 4 + method, err := abi.MethodById(calldata[0:4]) + if err != nil { + panic(err) + } - blobHeaderOffset, err := convertCalldataToInt(calldata[68:100]) + p, err := method.Inputs.Unpack(calldata[4:]) if err != nil { - // todo handle later panic(err) } - rlp.DecodeBytes(calldata[blobVerificationProofOffset:blobHeaderOffset], blobVerificationProof) // see if this works??? - rlp.DecodeBytes(calldata[blobHeaderOffset:], blobHeader) + payload, err := convertToPayload(p) + if err != nil { + panic(err) + } // blobVerificationProofOffset, err := convertCalldataToInt(calldata[36:68]) // if err != nil { @@ -344,12 +376,56 @@ func ParseSequencerMsg(calldata []byte) *EigenDABlobInfo { // } return &EigenDABlobInfo{ - BlobVerificationProof: *blobVerificationProof, - BlobHeader: *blobHeader, + BlobVerificationProof: *payload.BlobVerificationProof, + BlobHeader: *payload.BlobHeader, } } +func convertToPayload(pa []interface{}) (payload, error) { + blobVerificationProof := pa[1].(struct { + BatchId uint32 + BlobIndex uint32 + BatchMetadata struct { + BatchHeader struct { + BlobHeadersRoot [32]uint8 + QuorumNumbers []uint8 + SignedStakeForQuorums []uint8 + ReferenceBlockNumber uint32 + } + SignatoryRecordHash [32]uint8 + ConfirmationBlockNumber uint32 + } + InclusionProof []uint8 + QuorumIndices []uint8 + }) + + return payload{ + SequenceNumber: pa[0].(*big.Int), + BlobVerificationProof: &BlobVerificationProof{ + BatchID: blobVerificationProof.BatchId, + BlobIndex: blobVerificationProof.BlobIndex, + BatchMetadata: BatchMetadata{ + BatchHeader: BatchHeader{ + BlobHeadersRoot: blobVerificationProof.BatchMetadata.BatchHeader.BlobHeadersRoot, + QuorumNumbers: blobVerificationProof.BatchMetadata.BatchHeader.QuorumNumbers, + SignedStakeForQuorums: blobVerificationProof.BatchMetadata.BatchHeader.SignedStakeForQuorums, + ReferenceBlockNumber: blobVerificationProof.BatchMetadata.BatchHeader.ReferenceBlockNumber, + }, + SignatoryRecordHash: blobVerificationProof.BatchMetadata.SignatoryRecordHash, + ConfirmationBlockNumber: blobVerificationProof.BatchMetadata.ConfirmationBlockNumber, + }, + InclusionProof: blobVerificationProof.InclusionProof, + QuorumIndices: blobVerificationProof.QuorumIndices, + }, + BlobHeader: pa[2].(*BlobHeader), + AfterDelayedMessagesRead: pa[3].(*big.Int), + GasRefunder: pa[4].(*common.Address), + PrevMessageCount: pa[5].(*big.Int), + NewMessageCount: pa[6].(*big.Int), + }, nil +} + func convertCalldataToInt(calldata []byte) (int, error) { num := new(big.Int).SetBytes(calldata) diff --git a/eigenda/eigenda_test.go b/eigenda/eigenda_test.go new file mode 100644 index 000000000..6dd4d8144 --- /dev/null +++ b/eigenda/eigenda_test.go @@ -0,0 +1,31 @@ +package eigenda + +import ( + "encoding/hex" + "testing" +) + +func TestParseSequencerMsg(t *testing.T) { + + calldataString := "6b4e9387000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000e000000000000000000000000000000000000000000000000000000000000004a00000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000268d000000000000000000000000000000000000000000000000000000000000023a00000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000038000000000000000000000000000000000000000000000000000000000000000609c2295a45e69a5369008e65fa2afc40eccb8e8be2f453998207e9b0a8d3bc72b0000000000000000000000000000000000000000000000000000000000143b152f3d0afe00f1a3eccb2a77a053c9fa850d4809913ece2f6a5dcdc9ecb5347c8b000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000c00000000000000000000000000000000000000000000000000000000000143aad0000000000000000000000000000000000000000000000000000000000000002000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000024d4f000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000016086d042bea74e8fc60ce55410490d2e8bf312ff03aca9d369296d8cb25cd622096d79ebf24023971807ca680bfeac081bca250544e65147ffc0f7fdd3f3f973b885c252331c8385b767138702b5ba6155ae518fd98ebb966c5d2dfc2364ee0d49c203f38ebd01f85755bd59903ad850ea040fb94611fd554deb03c35ce43453f616866b1248350c1f1af7f3ce0f9b1beb712de850ce4e9cdfee6073fd54b8bca69011c9eca7800d59e6831f055972ae7430b8b52423cf455c2e0a3b11343890c713b16d87b5458476d589dd0f2146b14b9380f69aa8b1b546c75de4bfe925167204dd92138a76c02a4854973ed7016c6c110d41563acbc8cafefbe5d2f0ff490a83cd05a84bdfdd1542ebbbf20ca8b8968407a993919ffe5e159faf5941a95ae878a69d797b170a7a375d88b92c000c70871ae9ed5042f481743a27e97cf8665e8ebdea8f3dc226cc4c9a1cf3863ab4e60900a600fbfe5381cc0912f7aab88686000000000000000000000000000000000000000000000000000000000000000200010000000000000000000000000000000000000000000000000000000000001a78ee576b0026de661b72106bf447f5bb70881f24a3fa8b1f312992c8e165970633b392b3d3f66407d912aafcc2f0231c31918f0485e8476975edc710fcb45200000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000021000000000000000000000000000000000000000000000000000000000000003700000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000002100000000000000000000000000000000000000000000000000000000000000370000000000000000000000000000000000000000000000000000000000000001" + + calldata, err := hex.DecodeString(calldataString) + + expected := &EigenDABlobID{ + // BatchHeader content for hashing + BlobIndex: 570, + ReferenceBlockNumber: 1325741, + QuorumIDs: []uint32{0, 1}, + } + + // Call the function with the mock calldata + result := ParseSequencerMsg(calldata) + if err != nil { + t.Fatalf("ParseSequencerMsg returned an error: %v", err) + } + + if result.BlobVerificationProof.BlobIndex != expected.BlobIndex { + t.Errorf("BlobIndex was incorrect, got: %v, want: %v", result.BlobVerificationProof.BlobIndex, expected.BlobIndex) + } + +}