Skip to content

Commit a6d5cc5

Browse files
committed
proof: allow empty bytes in asset meta data
In this commit, we modify our main assertion to allow no meta bytes. We need this, as otherwise we force a user to always provide an asset meta if they don't need to, or only care about the decimal display.
1 parent 4594d84 commit a6d5cc5

File tree

2 files changed

+4
-13
lines changed

2 files changed

+4
-13
lines changed

proof/meta.go

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -271,17 +271,11 @@ func IsValidMetaType[T SizableInteger](num T) (MetaType, error) {
271271
// IsValidMetaSize checks if the passed data is non-empty and below the maximum
272272
// size.
273273
func IsValidMetaSize(mBytes []byte, maxSize int) error {
274-
mSize := len(mBytes)
275-
switch {
276-
case mSize == 0:
277-
return ErrMetaDataMissing
278-
279-
case mSize > maxSize:
274+
if len(mBytes) > maxSize {
280275
return ErrMetaDataTooLarge
281-
282-
default:
283-
return nil
284276
}
277+
278+
return nil
285279
}
286280

287281
// IsValidDecDisplay checks if the decimal display value is below the maximum.
@@ -295,15 +289,13 @@ func IsValidDecDisplay(decDisplay uint32) error {
295289

296290
// DecodeMetaJSON decodes bytes as a JSON object, after checking that the bytes
297291
// could be valid metadata.
298-
//
299-
// TODO(ffranr): Add unit test for `jBytes := []byte{}`.
300292
func DecodeMetaJSON(jBytes []byte) (map[string]interface{}, error) {
301293
jMeta := make(map[string]interface{})
302294

303295
// These bytes must match our metadata size constraints.
304296
err := IsValidMetaSize(jBytes, MetaDataMaxSizeBytes)
305297
if err != nil {
306-
return nil, fmt.Errorf("%w: %s", ErrInvalidJSON, err.Error())
298+
return nil, fmt.Errorf("%w: %w", ErrInvalidJSON, err)
307299
}
308300

309301
// Unmarshal checks internally if the JSON is valid.

proof/meta_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ func TestValidateMetaReveal(t *testing.T) {
7171
Type: MetaOpaque,
7272
Data: nil,
7373
},
74-
expectedErr: ErrMetaDataMissing,
7574
},
7675
{
7776
name: "too much data",

0 commit comments

Comments
 (0)