Skip to content

Commit

Permalink
Add jam marshal to state transition
Browse files Browse the repository at this point in the history
  • Loading branch information
bamzedev committed Nov 19, 2024
1 parent 5680cfc commit 07b0c73
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 11 deletions.
3 changes: 1 addition & 2 deletions internal/block/guarantee.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package block

import (
"encoding/json"
"fmt"

"github.com/eigerco/strawberry/internal/crypto"
Expand Down Expand Up @@ -163,7 +162,7 @@ func (w *WorkReport) Hash() (crypto.Hash, error) {
if w == nil {
return crypto.Hash{}, nil
}
jsonData, err := json.Marshal(w)
jsonData, err := jam.Marshal(w)
if err != nil {
return crypto.Hash{}, err
}
Expand Down
5 changes: 2 additions & 3 deletions internal/statetransition/state_transition.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package statetransition
import (
"bytes"
"crypto/ed25519"
"encoding/json"
"errors"
"fmt"
"log"
Expand Down Expand Up @@ -318,7 +317,7 @@ func calculateNewRecentBlocks(header block.Header, guarantees block.GuaranteesEx
workPackageMapping := buildWorkPackageMapping(guarantees.Guarantees)

// Equation 83: let n = {p, h ▸▸ H(H), b, s ▸▸ H_0}
headerBytes, err := json.Marshal(header)
headerBytes, err := jam.Marshal(header)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -729,7 +728,7 @@ func verifyGuaranteeCredentials(
return false
}

reportBytes, err := json.Marshal(guarantee.WorkReport)
reportBytes, err := jam.Marshal(guarantee.WorkReport)
if err != nil {
return false
}
Expand Down
13 changes: 7 additions & 6 deletions internal/statetransition/state_transition_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ package statetransition

import (
"crypto/ed25519"
"encoding/json"
"github.com/eigerco/strawberry/internal/safrole"
"testing"

"github.com/eigerco/strawberry/internal/safrole"
"github.com/eigerco/strawberry/pkg/serialization/codec/jam"

"github.com/eigerco/strawberry/internal/block"
"github.com/eigerco/strawberry/internal/common"
"github.com/eigerco/strawberry/internal/crypto"
Expand Down Expand Up @@ -601,7 +602,7 @@ func TestCalculateNewCoreAssignments(t *testing.T) {
}

// Marshal and hash the work report for signing
reportBytes, err := json.Marshal(workReport)
reportBytes, err := jam.Marshal(workReport)
require.NoError(t, err)
reportHash := crypto.HashData(reportBytes)
message := append([]byte(signatureContextGuarantee), reportHash[:]...)
Expand Down Expand Up @@ -670,7 +671,7 @@ func TestCalculateNewCoreAssignments(t *testing.T) {
CoreIndex: 0,
}

reportBytes, err := json.Marshal(workReport)
reportBytes, err := jam.Marshal(workReport)
require.NoError(t, err)
reportHash := crypto.HashData(reportBytes)
message := append([]byte(signatureContextGuarantee), reportHash[:]...)
Expand Down Expand Up @@ -736,7 +737,7 @@ func TestCalculateNewCoreAssignments(t *testing.T) {
CoreIndex: 0,
}

reportBytes, err := json.Marshal(workReport)
reportBytes, err := jam.Marshal(workReport)
require.NoError(t, err)
reportHash := crypto.HashData(reportBytes)
message := append([]byte(signatureContextGuarantee), reportHash[:]...)
Expand Down Expand Up @@ -804,7 +805,7 @@ func TestCalculateNewCoreAssignments(t *testing.T) {
CoreIndex: 0,
}

reportBytes, err := json.Marshal(workReport)
reportBytes, err := jam.Marshal(workReport)
require.NoError(t, err)
reportHash := crypto.HashData(reportBytes)
message := append([]byte(signatureContextGuarantee), reportHash[:]...)
Expand Down

0 comments on commit 07b0c73

Please sign in to comment.