diff --git a/dataavailability/ethda/ethda.go b/dataavailability/ethda/ethda.go index 056ebc4760..b704183047 100644 --- a/dataavailability/ethda/ethda.go +++ b/dataavailability/ethda/ethda.go @@ -6,6 +6,8 @@ import ( "fmt" blobutils "github.com/crustio/blob-utils" "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/crypto" + solsha3 "github.com/miguelmota/go-solidity-sha3" "math/big" ) @@ -55,7 +57,25 @@ func (d *EthdaBackend) PostSequence(ctx context.Context, batchesData [][]byte) ( hashes = append(hashes, hash.Bytes()...) } - return hashes, nil + currentHash := common.Hash{}.Bytes() + for _, batchData := range batchesData { + types := []string{ + "bytes32", + "bytes32", + } + values := []interface{}{ + currentHash, + crypto.Keccak256(batchData), + } + currentHash = solsha3.SoliditySHA3(types, values) + } + + sig, err := d.ethdaClient.SignBatchHash(common.BytesToHash(currentHash)) + if err != nil { + return nil, err + } + + return append(sig, hashes...), nil } func (d *EthdaBackend) GetSequence(ctx context.Context, batchHashes []common.Hash, dataAvailabilityMessage []byte) ([][]byte, error) { @@ -64,8 +84,8 @@ func (d *EthdaBackend) GetSequence(ctx context.Context, batchHashes []common.Has } var data [][]byte - for i := 0; i < len(dataAvailabilityMessage)/common.HashLength; i++ { - start := common.HashLength * i + for i := 0; i < (len(dataAvailabilityMessage)-crypto.SignatureLength)/common.HashLength; i++ { + start := common.HashLength*i + crypto.SignatureLength hash := common.BytesToHash(dataAvailabilityMessage[start : start+common.HashLength]) r, err := d.ethdaClient.GetBlob(hash) diff --git a/go.mod b/go.mod index 094a2e1e4d..bf68ccc9a6 100644 --- a/go.mod +++ b/go.mod @@ -60,7 +60,7 @@ require ( github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect github.com/crate-crypto/go-ipa v0.0.0-20231025140028-3c0104f4b233 // indirect github.com/crate-crypto/go-kzg-4844 v0.7.0 // indirect - github.com/crustio/blob-utils v0.2.1 // indirect + github.com/crustio/blob-utils v0.3.1 // indirect github.com/cyphar/filepath-securejoin v0.2.4 // indirect github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect github.com/deckarep/golang-set/v2 v2.1.0 // indirect diff --git a/go.sum b/go.sum index c1ff481707..cb96ee05d0 100644 --- a/go.sum +++ b/go.sum @@ -167,6 +167,10 @@ github.com/crustio/blob-utils v0.2.0 h1:cDBcKSbo160Ty6rX+jafCwK3Bhh7wfpjyKcE/c+E github.com/crustio/blob-utils v0.2.0/go.mod h1:7BcdCxXDgJ2xPNRLgVxlBXQ3eWZ0oFTcwZ+h3dpj58g= github.com/crustio/blob-utils v0.2.1 h1:kDiV8kPjyyjzIk64ezB6VN+H6fbtK9eAUcSmF94RJ5M= github.com/crustio/blob-utils v0.2.1/go.mod h1:d0x/5NSSocyvkRXkVJUnRGsB3EkZ0YuI/Nn8wN4l44g= +github.com/crustio/blob-utils v0.3.0 h1:7Uh7FmZQLZFcacfmqZhV2Z5J6P88CeLoSwtoBcLRvsE= +github.com/crustio/blob-utils v0.3.0/go.mod h1:d0x/5NSSocyvkRXkVJUnRGsB3EkZ0YuI/Nn8wN4l44g= +github.com/crustio/blob-utils v0.3.1 h1:T++x9rKRqB7mlQp9nZpfadQd0UvKH6zMgV1695EvkUE= +github.com/crustio/blob-utils v0.3.1/go.mod h1:d0x/5NSSocyvkRXkVJUnRGsB3EkZ0YuI/Nn8wN4l44g= github.com/cyphar/filepath-securejoin v0.2.4 h1:Ugdm7cg7i6ZK6x3xDF1oEu1nfkyfH53EtKeQYTC3kyg= github.com/cyphar/filepath-securejoin v0.2.4/go.mod h1:aPGpWjXOXUn2NCNjFvBE6aRxGGx79pTxQpKOJNYHHl4= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=