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 12, 2024
1 parent fae3cf9 commit 5e79ab7
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 7 deletions.
32 changes: 27 additions & 5 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,17 +57,37 @@ 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) {
if len(dataAvailabilityMessage)%common.HashLength != 0 {
return nil, fmt.Errorf("wrong da message length: %d", len(dataAvailabilityMessage))
msgLen := len(dataAvailabilityMessage)

if msgLen < crypto.SignatureLength || (msgLen-crypto.SignatureLength)%common.HashLength != 0 {
return nil, fmt.Errorf("wrong da message length: %d", msgLen)
}

var data [][]byte
for i := 0; i < len(dataAvailabilityMessage)/common.HashLength; i++ {
start := common.HashLength * i
for i := 0; i < (msgLen-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
3 changes: 2 additions & 1 deletion dataavailability/ethda/ethda_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ func TestPostSequence(t *testing.T) {
}

func TestGetSequence(t *testing.T) {
daMessage := "b1e79a75baadbd688f97213920a01980e37e4fbf464cf9ffc94e6d10be2ee69253f1acb077c8355d30f4d8046ccbe4eb5f4eb05643ef31c4fe6e531c0ca7dc8e1bdb919f0ef6ffe754f3dfdfdfc4d1789b0bf2aee713567b550d330527eab00522"
rpcUrl := "https://rpc-devnet2.ethda.io"

// test key
Expand All @@ -40,7 +41,7 @@ func TestGetSequence(t *testing.T) {
err = da.Init()
require.NoError(t, err)

data, err := da.GetSequence(context.Background(), nil, common.Hex2Bytes("76b56f65beab1cfe55242eb97eebfe2f32aacd957f202122835026bffb3ba282"))
data, err := da.GetSequence(context.Background(), nil, common.Hex2Bytes(daMessage))
require.NoError(t, err)
require.Equal(t, "ethda", string(data[0]))
}
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 5e79ab7

Please sign in to comment.