Skip to content

Commit b25f8df

Browse files
committed
tapgarden: enforce matching anchor meta
With this commit we make sure that a new seedling that attempts to mint into the same group as a previous mint has the same meta fields.
1 parent da8bba4 commit b25f8df

File tree

2 files changed

+38
-17
lines changed

2 files changed

+38
-17
lines changed

tapgarden/batch.go

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -146,19 +146,7 @@ func (m *MintingBatch) validateGroupAnchor(s *Seedling) error {
146146
*s.GroupAnchor)
147147
}
148148

149-
// The decimal display of the seedling must match that of the group
150-
// anchor. We already validated the seedling metadata, so we don't care
151-
// if the value is explicit or if the metadata is JSON, but we must
152-
// compute the same value for both assets.
153-
_, seedlingDecDisplay, _ := s.Meta.GetDecDisplay()
154-
_, anchorDecDisplay, _ := anchor.Meta.GetDecDisplay()
155-
if seedlingDecDisplay != anchorDecDisplay {
156-
return fmt.Errorf("seedling decimal display does not match "+
157-
"group anchor: %d, %d", seedlingDecDisplay,
158-
anchorDecDisplay)
159-
}
160-
161-
return nil
149+
return validateAnchorMeta(s.Meta, anchor.Meta)
162150
}
163151

164152
// MintingOutputKey derives the output key that once mined, will commit to the

tapgarden/seedling.go

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,14 @@ func (c Seedling) validateGroupKey(group asset.AssetGroup,
181181
"group asset type %v", group.Genesis.Type)
182182
}
183183

184+
return validateAnchorMeta(c.Meta, anchorMeta)
185+
}
186+
187+
// validateAnchorMeta checks that the metadata of the seedling matches that of
188+
// the group anchor, if there is a group anchor.
189+
func validateAnchorMeta(seedlingMeta *proof.MetaReveal,
190+
anchorMeta *proof.MetaReveal) error {
191+
184192
// The decimal display of the seedling must match that of the group
185193
// anchor. We already validated the seedling metadata, so we don't care
186194
// if the value is explicit or if the metadata is JSON, but we must
@@ -189,11 +197,9 @@ func (c Seedling) validateGroupKey(group asset.AssetGroup,
189197
seedlingDecDisplay uint32
190198
anchorDecDisplay uint32
191199
)
192-
193-
if c.Meta != nil {
194-
_, seedlingDecDisplay, _ = c.Meta.GetDecDisplay()
200+
if seedlingMeta != nil {
201+
_, seedlingDecDisplay, _ = seedlingMeta.GetDecDisplay()
195202
}
196-
197203
if anchorMeta != nil {
198204
_, anchorDecDisplay, _ = anchorMeta.GetDecDisplay()
199205
}
@@ -204,6 +210,33 @@ func (c Seedling) validateGroupKey(group asset.AssetGroup,
204210
anchorDecDisplay)
205211
}
206212

213+
// If the anchor asset had universe commitments turned on, then the
214+
// seedling must also have them.
215+
var (
216+
seedlingUniverseCommitments bool
217+
anchorUniverseCommitments bool
218+
)
219+
if seedlingMeta != nil && seedlingMeta.UniverseCommitments {
220+
seedlingUniverseCommitments = true
221+
}
222+
if anchorMeta != nil && anchorMeta.UniverseCommitments {
223+
anchorUniverseCommitments = true
224+
}
225+
226+
if seedlingUniverseCommitments != anchorUniverseCommitments {
227+
return fmt.Errorf("seedling universe commitments flag does "+
228+
"not match group anchor: %v, %v",
229+
seedlingUniverseCommitments, anchorUniverseCommitments)
230+
}
231+
232+
// For now, we simply require a delegation key to be set when universe
233+
// commitments are turned on. In the future, we could allow this to be
234+
// empty and the group internal key to be used for signing.
235+
if seedlingUniverseCommitments && seedlingMeta.DelegationKey.IsNone() {
236+
return fmt.Errorf("delegation key must be set for universe " +
237+
"commitments flag")
238+
}
239+
207240
return nil
208241
}
209242

0 commit comments

Comments
 (0)