Skip to content

Commit

Permalink
contracts integration
Browse files Browse the repository at this point in the history
  • Loading branch information
ian-shim committed Nov 21, 2024
1 parent 5ce2098 commit cd97fb8
Show file tree
Hide file tree
Showing 14 changed files with 922 additions and 95 deletions.
260 changes: 245 additions & 15 deletions contracts/bindings/EigenDAServiceManager/binding.go

Large diffs are not rendered by default.

449 changes: 449 additions & 0 deletions contracts/bindings/IEigenDARelayRegistry/binding.go

Large diffs are not rendered by default.

213 changes: 180 additions & 33 deletions contracts/bindings/IEigenDAServiceManager/binding.go

Large diffs are not rendered by default.

48 changes: 24 additions & 24 deletions contracts/bindings/MockRollup/binding.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion contracts/compile.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ function create_binding {
forge clean
forge build

contracts="PaymentVault SocketRegistry AVSDirectory DelegationManager BitmapUtils OperatorStateRetriever RegistryCoordinator BLSApkRegistry IndexRegistry StakeRegistry BN254 EigenDAServiceManager IEigenDAServiceManager MockRollup EjectionManager"
contracts="PaymentVault SocketRegistry AVSDirectory DelegationManager BitmapUtils OperatorStateRetriever RegistryCoordinator BLSApkRegistry IndexRegistry StakeRegistry BN254 EigenDAServiceManager IEigenDAServiceManager MockRollup EjectionManager IEigenDARelayRegistry"
for contract in $contracts; do
create_binding ./ $contract ./bindings
done
Expand Down
2 changes: 1 addition & 1 deletion core/eth/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ func (t *Writer) BuildConfirmBatchTxn(ctx context.Context, batchHeader *core.Bat
}

signedStakeForQuorums := serializeSignedStakeForQuorums(quorums)
batchH := eigendasrvmg.IEigenDAServiceManagerBatchHeader{
batchH := eigendasrvmg.BatchHeader{
BlobHeadersRoot: batchHeader.BatchRoot,
QuorumNumbers: quorumNumbers,
SignedStakeForQuorums: signedStakeForQuorums,
Expand Down
2 changes: 1 addition & 1 deletion core/serialization.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func (h BatchHeader) GetBatchHeaderHash() ([32]byte, error) {

// HashBatchHeader returns the hash of the BatchHeader that is used to emit the BatchConfirmed event
// ref: https://github.com/Layr-Labs/eigenda/blob/master/contracts/src/libraries/EigenDAHasher.sol#L57
func HashBatchHeader(batchHeader binding.IEigenDAServiceManagerBatchHeader) ([32]byte, error) {
func HashBatchHeader(batchHeader binding.BatchHeader) ([32]byte, error) {
// The order here has to match the field ordering of BatchHeader defined in IEigenDAServiceManager.sol
batchHeaderType, err := abi.NewType("tuple", "", []abi.ArgumentMarshaling{
{
Expand Down
2 changes: 1 addition & 1 deletion core/serialization_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func TestBatchHeaderEncoding(t *testing.T) {
assert.NoError(t, err)
assert.Equal(t, hexutil.Encode(hash[:]), reducedBatchHeaderHash)

onchainBatchHeader := binding.IEigenDAServiceManagerBatchHeader{
onchainBatchHeader := binding.BatchHeader{
BlobHeadersRoot: batchRoot,
QuorumNumbers: []byte{0},
SignedStakeForQuorums: []byte{100},
Expand Down
16 changes: 8 additions & 8 deletions inabox/tests/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,17 +181,17 @@ var _ = Describe("Inabox Integration", func() {
})
})

func blobHeaderFromProto(blobHeader *disperserpb.BlobHeader) rollupbindings.IEigenDAServiceManagerBlobHeader {
quorums := make([]rollupbindings.IEigenDAServiceManagerQuorumBlobParam, len(blobHeader.GetBlobQuorumParams()))
func blobHeaderFromProto(blobHeader *disperserpb.BlobHeader) rollupbindings.BlobHeader {
quorums := make([]rollupbindings.QuorumBlobParam, len(blobHeader.GetBlobQuorumParams()))
for i, quorum := range blobHeader.GetBlobQuorumParams() {
quorums[i] = rollupbindings.IEigenDAServiceManagerQuorumBlobParam{
quorums[i] = rollupbindings.QuorumBlobParam{
QuorumNumber: uint8(quorum.GetQuorumNumber()),
AdversaryThresholdPercentage: uint8(quorum.GetAdversaryThresholdPercentage()),
ConfirmationThresholdPercentage: uint8(quorum.GetConfirmationThresholdPercentage()),
ChunkLength: quorum.ChunkLength,
}
}
return rollupbindings.IEigenDAServiceManagerBlobHeader{
return rollupbindings.BlobHeader{
Commitment: rollupbindings.BN254G1Point{
X: new(big.Int).SetBytes(blobHeader.GetCommitment().X),
Y: new(big.Int).SetBytes(blobHeader.GetCommitment().Y),
Expand All @@ -201,25 +201,25 @@ func blobHeaderFromProto(blobHeader *disperserpb.BlobHeader) rollupbindings.IEig
}
}

func blobVerificationProofFromProto(verificationProof *disperserpb.BlobVerificationProof) rollupbindings.EigenDARollupUtilsBlobVerificationProof {
func blobVerificationProofFromProto(verificationProof *disperserpb.BlobVerificationProof) rollupbindings.BlobVerificationProof {
batchMetadataProto := verificationProof.GetBatchMetadata()
batchHeaderProto := verificationProof.GetBatchMetadata().GetBatchHeader()
var batchRoot [32]byte
copy(batchRoot[:], batchHeaderProto.GetBatchRoot())
batchHeader := rollupbindings.IEigenDAServiceManagerBatchHeader{
batchHeader := rollupbindings.BatchHeader{
BlobHeadersRoot: batchRoot,
QuorumNumbers: batchHeaderProto.GetQuorumNumbers(),
SignedStakeForQuorums: batchHeaderProto.GetQuorumSignedPercentages(),
ReferenceBlockNumber: batchHeaderProto.GetReferenceBlockNumber(),
}
var sig [32]byte
copy(sig[:], batchMetadataProto.GetSignatoryRecordHash())
batchMetadata := rollupbindings.IEigenDAServiceManagerBatchMetadata{
batchMetadata := rollupbindings.BatchMetadata{
BatchHeader: batchHeader,
SignatoryRecordHash: sig,
ConfirmationBlockNumber: batchMetadataProto.GetConfirmationBlockNumber(),
}
return rollupbindings.EigenDARollupUtilsBlobVerificationProof{
return rollupbindings.BlobVerificationProof{
BatchId: verificationProof.GetBatchId(),
BlobIndex: verificationProof.GetBlobIndex(),
BatchMetadata: batchMetadata,
Expand Down
6 changes: 3 additions & 3 deletions retriever/eth/chain_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
)

type ChainClient interface {
FetchBatchHeader(ctx context.Context, serviceManagerAddress gcommon.Address, batchHeaderHash []byte, fromBlock *big.Int, toBlock *big.Int) (*binding.IEigenDAServiceManagerBatchHeader, error)
FetchBatchHeader(ctx context.Context, serviceManagerAddress gcommon.Address, batchHeaderHash []byte, fromBlock *big.Int, toBlock *big.Int) (*binding.BatchHeader, error)
}

type chainClient struct {
Expand All @@ -34,7 +34,7 @@ func NewChainClient(ethClient common.EthClient, logger logging.Logger) ChainClie
// It filters logs by the batch header hashes which are logged as events by the service manager contract.
// From those logs, it identifies corresponding confirmBatch transaction and decodes batch header from the calldata.
// It takes fromBlock and toBlock as arguments to filter logs within a specific block range. This can help with optimizing queries to the chain. nil values for fromBlock and toBlock will default to genesis block and latest block respectively.
func (c *chainClient) FetchBatchHeader(ctx context.Context, serviceManagerAddress gcommon.Address, batchHeaderHash []byte, fromBlock *big.Int, toBlock *big.Int) (*binding.IEigenDAServiceManagerBatchHeader, error) {
func (c *chainClient) FetchBatchHeader(ctx context.Context, serviceManagerAddress gcommon.Address, batchHeaderHash []byte, fromBlock *big.Int, toBlock *big.Int) (*binding.BatchHeader, error) {
logs, err := c.ethClient.FilterLogs(ctx, ethereum.FilterQuery{
FromBlock: fromBlock,
ToBlock: toBlock,
Expand Down Expand Up @@ -87,5 +87,5 @@ func (c *chainClient) FetchBatchHeader(ctx context.Context, serviceManagerAddres
ReferenceBlockNumber uint32 "json:\"referenceBlockNumber\""
})

return (*binding.IEigenDAServiceManagerBatchHeader)(&batchHeaderInput), nil
return (*binding.BatchHeader)(&batchHeaderInput), nil
}
2 changes: 1 addition & 1 deletion retriever/eth/chain_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func TestFetchBatchHeader(t *testing.T) {
Index: 0,
},
}, nil)
expectedHeader := binding.IEigenDAServiceManagerBatchHeader{
expectedHeader := binding.BatchHeader{
BlobHeadersRoot: [32]byte{0},
QuorumNumbers: []byte{0},
SignedStakeForQuorums: []byte{100},
Expand Down
4 changes: 2 additions & 2 deletions retriever/mock/chain_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func NewMockChainClient() *MockChainClient {
return &MockChainClient{}
}

func (c *MockChainClient) FetchBatchHeader(ctx context.Context, serviceManagerAddress gcommon.Address, batchHeaderHash []byte, fromBlock *big.Int, toBlock *big.Int) (*binding.IEigenDAServiceManagerBatchHeader, error) {
func (c *MockChainClient) FetchBatchHeader(ctx context.Context, serviceManagerAddress gcommon.Address, batchHeaderHash []byte, fromBlock *big.Int, toBlock *big.Int) (*binding.BatchHeader, error) {
args := c.Called()
return args.Get(0).(*binding.IEigenDAServiceManagerBatchHeader), args.Error(1)
return args.Get(0).(*binding.BatchHeader), args.Error(1)
}
2 changes: 1 addition & 1 deletion retriever/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func newTestServer(t *testing.T) *retriever.Server {

func TestRetrieveBlob(t *testing.T) {
server := newTestServer(t)
chainClient.On("FetchBatchHeader").Return(&binding.IEigenDAServiceManagerBatchHeader{
chainClient.On("FetchBatchHeader").Return(&binding.BatchHeader{
BlobHeadersRoot: batchRoot,
QuorumNumbers: []byte{0},
SignedStakeForQuorums: []byte{90},
Expand Down
9 changes: 5 additions & 4 deletions tools/traffic/workers/blob_reader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ package workers
import (
"context"
"crypto/md5"
"sync"
"testing"
"time"

"github.com/Layr-Labs/eigenda/api/clients"
apiMock "github.com/Layr-Labs/eigenda/api/clients/mock"
"github.com/Layr-Labs/eigenda/common"
Expand All @@ -15,9 +19,6 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
"golang.org/x/exp/rand"
"sync"
"testing"
"time"
)

// TestBlobReaderNoOptionalReads tests the BlobReader's basic functionality'
Expand All @@ -40,7 +41,7 @@ func TestBlobReader(t *testing.T) {
mock.Anything,
mock.Anything,
mock.Anything,
mock.Anything).Return(&binding.IEigenDAServiceManagerBatchHeader{}, nil)
mock.Anything).Return(&binding.BatchHeader{}, nil)
retrievalClient := &apiMock.MockRetrievalClient{}

blobReader := NewBlobReader(
Expand Down

0 comments on commit cd97fb8

Please sign in to comment.