Skip to content

Commit

Permalink
feat: append sig to da message
Browse files Browse the repository at this point in the history
  • Loading branch information
x-wagmi committed May 11, 2024
1 parent fae3cf9 commit 3da553a
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 4 deletions.
26 changes: 23 additions & 3 deletions dataavailability/ethda/ethda.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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) {
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down

0 comments on commit 3da553a

Please sign in to comment.