Skip to content

Commit b7c8526

Browse files
committed
fix: update eip types based on new contract requirements
1 parent 154924f commit b7c8526

File tree

3 files changed

+18
-11
lines changed

3 files changed

+18
-11
lines changed

go/eip712/extradata.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,9 @@ func (e *ExtraDataEncoder) EncodeCreateDataSetExtraData(
8282
}
8383

8484
// EncodeAddPiecesExtraData encodes the extraData for piecesAdded callback
85-
// Format matches: abi.decode(extraData, (bytes, string[][], string[][]))
85+
// Format matches: abi.decode(extraData, (uint256, string[][], string[][], bytes))
8686
func (e *ExtraDataEncoder) EncodeAddPiecesExtraData(
87+
nonce *big.Int,
8788
signature *AuthSignature,
8889
metadata [][]MetadataEntry,
8990
) ([]byte, error) {
@@ -107,12 +108,13 @@ func (e *ExtraDataEncoder) EncodeAddPiecesExtraData(
107108
}
108109

109110
arguments := abi.Arguments{
110-
{Type: bytesType}, // signature
111+
{Type: uint256Type}, // nonce
111112
{Type: stringDoubleArrayType}, // metadataKeys[][]
112113
{Type: stringDoubleArrayType}, // metadataValues[][]
114+
{Type: bytesType}, // signature
113115
}
114116

115-
return arguments.Pack(signatureBytes, keysArray, valuesArray)
117+
return arguments.Pack(nonce, keysArray, valuesArray, signatureBytes)
116118
}
117119

118120
// EncodeSchedulePieceRemovalsExtraData encodes the extraData for piecesScheduledRemove callback

go/eip712/extradata_test.go

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,31 +49,36 @@ func TestEncodingMatchesContractDecoding(t *testing.T) {
4949

5050
// Test AddPieces encoding
5151
t.Run("AddPieces", func(t *testing.T) {
52+
nonce := big.NewInt(7)
5253
signature := &AuthSignature{V: 27, R: [32]byte{1}, S: [32]byte{2}}
5354
metadata := [][]MetadataEntry{
5455
{{Key: "piece1", Value: "value1"}},
5556
{{Key: "piece2", Value: "value2"}},
5657
}
5758

58-
encoded, err := encoder.EncodeAddPiecesExtraData(signature, metadata)
59+
encoded, err := encoder.EncodeAddPiecesExtraData(nonce, signature, metadata)
5960
require.NoError(t, err)
6061

6162
// Decode using the contract's expected format
6263
arguments := abi.Arguments{
63-
{Type: bytesType},
64+
{Type: uint256Type},
6465
{Type: stringDoubleArrayType},
6566
{Type: stringDoubleArrayType},
67+
{Type: bytesType},
6668
}
6769

6870
unpacked, err := arguments.Unpack(encoded)
6971
require.NoError(t, err)
70-
require.Len(t, unpacked, 3)
72+
require.Len(t, unpacked, 4)
73+
74+
// Verify nonce
75+
require.Equal(t, nonce, unpacked[0].(*big.Int))
7176

7277
// Verify signature
73-
require.NotEmpty(t, unpacked[0].([]byte))
78+
require.NotEmpty(t, unpacked[3].([]byte))
7479

7580
// Verify metadata keys
76-
keys := unpacked[1].([][]string)
81+
keys := unpacked[1].([][]string) // wt operations preserve order
7782
require.Len(t, keys, 2)
7883
require.Equal(t, []string{"piece1"}, keys[0])
7984
require.Equal(t, []string{"piece2"}, keys[1])
@@ -188,4 +193,4 @@ func TestEncodingBreakageDetection(t *testing.T) {
188193
_, exists := serviceContractABI.Methods[methodName]
189194
require.True(t, exists, "Required method %s must exist in contract ABI", methodName)
190195
}
191-
}
196+
}

go/eip712/types.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ type PieceMetadata struct {
3737

3838
type AddPieces struct {
3939
ClientDataSetId *big.Int `json:"clientDataSetId"`
40-
FirstAdded *big.Int `json:"firstAdded"`
40+
Nonce *big.Int `json:"nonce"`
4141
PieceData []Cid `json:"pieceData"`
4242
PieceMetadata []PieceMetadata `json:"pieceMetadata"`
4343
}
@@ -77,7 +77,7 @@ var EIP712Types = apitypes.Types{
7777
},
7878
"AddPieces": {
7979
{Name: "clientDataSetId", Type: "uint256"},
80-
{Name: "firstAdded", Type: "uint256"},
80+
{Name: "nonce", Type: "uint256"},
8181
{Name: "pieceData", Type: "Cid[]"},
8282
{Name: "pieceMetadata", Type: "PieceMetadata[]"},
8383
},

0 commit comments

Comments
 (0)