Skip to content

Commit

Permalink
Add nubit integration fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
sieniven committed Jul 30, 2024
1 parent fc42ce2 commit 0ec372c
Show file tree
Hide file tree
Showing 20 changed files with 591 additions and 312 deletions.
14 changes: 2 additions & 12 deletions cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,6 @@ func newDataAvailability(c config.Config, st *state.State, etherman *etherman.Cl
return nil, fmt.Errorf("error getting data availability protocol name: %v", err)
}
var daBackend dataavailability.DABackender
daProtocolName = string(dataavailability.Nubit)
switch daProtocolName {
case string(dataavailability.DataAvailabilityCommittee):
var (
Expand All @@ -355,7 +354,7 @@ func newDataAvailability(c config.Config, st *state.State, etherman *etherman.Cl
if err != nil {
return nil, err
}
case string(dataavailability.Nubit):
case string(dataavailability.DataAvailabilityNubitDA):
var (
pk *ecdsa.PrivateKey
err error
Expand All @@ -367,16 +366,7 @@ func newDataAvailability(c config.Config, st *state.State, etherman *etherman.Cl
}
}

dacAddr, err := etherman.GetDAProtocolAddr()
if err != nil {
return nil, fmt.Errorf("error getting trusted sequencer URI. Error: %v", err)
}

daBackend, err = nubit.NewNubitDABackend(
c.Etherman.URL,
dacAddr,
pk,
)
daBackend, err = nubit.NewNubitDABackend(&c.DataAvailability, pk)
if err != nil {
return nil, err
}
Expand Down
3 changes: 3 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

"github.com/0xPolygonHermez/zkevm-node/aggregator"
"github.com/0xPolygonHermez/zkevm-node/config/types"
"github.com/0xPolygonHermez/zkevm-node/dataavailability/nubit"
"github.com/0xPolygonHermez/zkevm-node/db"
"github.com/0xPolygonHermez/zkevm-node/etherman"
"github.com/0xPolygonHermez/zkevm-node/ethtxmanager"
Expand Down Expand Up @@ -105,6 +106,8 @@ type Config struct {
SequenceSender sequencesender.Config
// Configuration of the aggregator service
Aggregator aggregator.Config
// Configuration of the NubitDA data availability service
DataAvailability nubit.Config
// Configuration of the genesis of the network. This is used to known the initial state of the network
NetworkConfig NetworkConfig
// Configuration of the gas price suggester service
Expand Down
7 changes: 7 additions & 0 deletions config/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,13 @@ AggLayerTxTimeout = "5m"
AggLayerURL = "http://zkevm-agglayer"
SequencerPrivateKey = {Path = "/pk/sequencer.keystore", Password = "testonly"}
[DataAvailability]
NubitRpcURL = "http://127.0.0.1:26658"
NubitAuthKey = ""
NubitNamespace = "xlayer"
NubitGetProofMaxRetry = "10"
NubitGetProofWaitPeriod = "5s"
[L2GasPriceSuggester]
Type = "follower"
UpdatePeriod = "10s"
Expand Down
3 changes: 2 additions & 1 deletion dataavailability/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ type DABackendType string
const (
// DataAvailabilityCommittee is the DAC protocol backend
DataAvailabilityCommittee DABackendType = "DataAvailabilityCommittee"
Nubit DABackendType = "Nubit"
// DataAvailabilityNubitDA is the NubitDA protocol backend
DataAvailabilityNubitDA DABackendType = "NubitDA"
)
6 changes: 3 additions & 3 deletions dataavailability/dataavailability.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func New(

// PostSequence sends the sequence data to the data availability backend, and returns the dataAvailabilityMessage
// as expected by the contract
func (d *DataAvailability) PostSequence(ctx context.Context, sequences []types.Sequence) ([]byte, []byte, error) {
func (d *DataAvailability) PostSequence(ctx context.Context, sequences []types.Sequence) ([]byte, error) {
batchesData := [][]byte{}
for _, batch := range sequences {
// Do not send to the DA backend data that will be stored to L1
Expand Down Expand Up @@ -113,7 +113,7 @@ func (d *DataAvailability) trustedSequencerData(batchNums []uint64, expectedHash
return nil, fmt.Errorf("invalid arguments, len of batch numbers does not equal length of expected hashes: %d != %d",
len(batchNums), len(expectedHashes))
}
nums := make([]*big.Int, 0, len(batchNums))
var nums []*big.Int
for _, n := range batchNums {
nums = append(nums, new(big.Int).SetUint64(n))
}
Expand All @@ -124,7 +124,7 @@ func (d *DataAvailability) trustedSequencerData(batchNums []uint64, expectedHash
if len(batchData) != len(batchNums) {
return nil, fmt.Errorf("missing batch data, expected %d, got %d", len(batchNums), len(batchData))
}
result := make([][]byte, 0, len(batchNums))
var result [][]byte
for i := 0; i < len(batchNums); i++ {
number := batchNums[i]
batch := batchData[i]
Expand Down
10 changes: 5 additions & 5 deletions dataavailability/datacommittee/datacommittee.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,11 +152,11 @@ type signatureMsg struct {

// PostSequence sends the sequence data to the data availability backend, and returns the dataAvailabilityMessage
// as expected by the contract
func (s *DataCommitteeBackend) PostSequence(ctx context.Context, batchesData [][]byte) ([]byte, []byte, error) {
func (s *DataCommitteeBackend) PostSequence(ctx context.Context, batchesData [][]byte) ([]byte, error) {
// Get current committee
committee, err := s.getCurrentDataCommittee()
if err != nil {
return nil, nil, err
return nil, err
}

// Authenticate as trusted sequencer by signing the sequences
Expand All @@ -166,7 +166,7 @@ func (s *DataCommitteeBackend) PostSequence(ctx context.Context, batchesData [][
}
signedSequence, err := sequence.Sign(s.privKey)
if err != nil {
return nil, nil, err
return nil, err
}

// Request signatures to all members in parallel
Expand All @@ -189,7 +189,7 @@ func (s *DataCommitteeBackend) PostSequence(ctx context.Context, batchesData [][
failedToCollect++
if len(committee.Members)-int(failedToCollect) < int(committee.RequiredSignatures) {
cancelSignatureCollection()
return nil, nil, errors.New("too many members failed to send their signature")
return nil, errors.New("too many members failed to send their signature")
}
} else {
log.Infof("received signature from %s", msg.addr)
Expand All @@ -201,7 +201,7 @@ func (s *DataCommitteeBackend) PostSequence(ctx context.Context, batchesData [][
// Stop requesting as soon as we have N valid signatures
cancelSignatureCollection()

return buildSignaturesAndAddrs(signatureMsgs(msgs), committee.Members), nil, nil
return buildSignaturesAndAddrs(signatureMsgs(msgs), committee.Members), nil
}

func requestSignatureFromMember(ctx context.Context, signedSequence daTypes.SignedSequence, member DataCommitteeMember, ch chan signatureMsg) {
Expand Down
2 changes: 1 addition & 1 deletion dataavailability/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ type DABackender interface {
type SequenceSender interface {
// PostSequence sends the sequence data to the data availability backend, and returns the dataAvailabilityMessage
// as expected by the contract
PostSequence(ctx context.Context, batchesData [][]byte) ([]byte, []byte, error)
PostSequence(ctx context.Context, batchesData [][]byte) ([]byte, error)
}

// SequenceRetriever is used to retrieve batch data
Expand Down
28 changes: 28 additions & 0 deletions dataavailability/nubit/abi.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package nubit

const blobDataABI = `[
{
"type": "function",
"name": "BlobData",
"inputs": [
{
"name": "blobData",
"type": "tuple",
"internalType": "struct NubitDAVerifier.BlobData",
"components": [
{
"name": "blobID",
"type": "bytes",
"internalType": "bytes"
},
{
"name": "signature",
"type": "bytes",
"internalType": "bytes"
}
]
}
],
"stateMutability": "pure"
}
]`
Loading

0 comments on commit 0ec372c

Please sign in to comment.