Skip to content

Store Public Keys in tiles coordinate-matched to Entry tiles. - #8958

Open
ezekiel wants to merge 7 commits into
mainfrom
ezekiel/pubkeys-as-tiles
Open

Store Public Keys in tiles coordinate-matched to Entry tiles.#8958
ezekiel wants to merge 7 commits into
mainfrom
ezekiel/pubkeys-as-tiles

Conversation

@ezekiel

@ezekiel ezekiel commented Aug 19, 2026

Copy link
Copy Markdown
Member

This changes the MTCA to include the public key in the pendingEntries submitted for sequencing. Upon sequencing, the subjectPublicKeyInfo structure is bundled just like Entries are bundled, and stored in tiles with the same coordinates as the Entry tiles, but at a different layer (-2).

For writing the public key tiles, we introduce Bundling and Marshaling functions specific to a new MTCPublicKey structure which wraps subjectPublicKeyInfo and facilitates null pubkey placeholders in the tile information tracked in the Frontier.

Fixes #8913

@ezekiel ezekiel changed the title Store corresponding Public Keys when Entries are appended to Tiles. Store Public Keys in tiles coordinate-matched to Entry tiles. Aug 19, 2026
@ezekiel ezekiel self-assigned this Aug 20, 2026
@ezekiel
ezekiel marked this pull request as ready for review August 21, 2026 16:00
@ezekiel
ezekiel requested a review from a team as a code owner August 21, 2026 16:00
@ezekiel
ezekiel requested a review from jsha August 21, 2026 16:00
Comment thread mtca/mtca.go
nullEntry := &entry.MTCLogEntry{}
err := candidate.AppendEntry(nullEntry)
nullPubkey := &pubkey.MTCPublicKey{}
err := candidate.AppendEntry(nullEntry, nullPubkey)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: no need to create standalone variables for these when they're only used once.

Suggested change
err := candidate.AppendEntry(nullEntry, nullPubkey)
err := candidate.AppendEntry(&entry.MTCLogEntry{}, &pubkey.MTCPublicKey)

Comment thread trees/tiles/tiles.go
Comment on lines +42 to +43
const entriesTileLayer int = -1
const pubkeysTileLayer int = -2

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hyper naming nit, feel free to ignore, I just find these names to be easier to think about and say in my head:

Suggested change
const entriesTileLayer int = -1
const pubkeysTileLayer int = -2
const entryTilesLayer int = -1
const pubkeyTilesLayer int = -2

Comment thread trees/tiles/tiles.go
Comment on lines +418 to +419

bundleBytes, err := mtcleBuilder.Bytes()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

two nits:

  • no empty line here, since we didn't just have an if err stanza; and
  • no point in calling this a "bundle", since it's a bundle of just one entry.
Suggested change
bundleBytes, err := mtcleBuilder.Bytes()
entryBytes, err := mtcleBuilder.Bytes()

Comment thread trees/tiles/tiles.go
Comment on lines +435 to +436

pkBundleBytes, err := mtcpkBuilder.Bytes()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same nit here:

Suggested change
pkBundleBytes, err := mtcpkBuilder.Bytes()
pubkeyBytes, err := mtcpkBuilder.Bytes()

Comment thread trees/tiles/tiles.go
// Tile Layer representation constants
const entriesTileLayer int = -1
const pubkeysTileLayer int = -2

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, consider having an additional constant here representing the "lowest level", so we don't have to have -2 as a magic number when working with the dirty level.

Suggested change
const lowestLayer int = pubkeyTilesLayer

Comment thread trees/pubkey/pubkey.go
Comment on lines +61 to +65
pkBytes, err := x509.MarshalPKIXPublicKey(mtcpk.pub)
// MarshalPKIXPublicKey returns an error on nil pubkey, but we want to be able to have nil tiles
if err != nil && err.Error() != "x509: unsupported public key type: <nil>" {
return nil, err
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move this code inside the case typeMTCPubkey, and then you don't need the error string special casing.

Comment thread trees/pubkey/pubkey.go
// pkBytes is a crypto.x509 SubjectPublicKeyInfo structure
builder.AddBytes(pkBytes)
case typeNilPubkey:
if len(pkBytes) != 0 {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alongside the suggestions above that mtcpk.pub just become a byte slice, this check nicely becomes if len(mtcpk.pub) != 0.

Comment thread trees/pubkey/pubkey.go

// FromCryptoPubkey feeds a crypto.PublicKey into position in an MTCPublicKey
// struct, setting the struct "typ" to nil if the input public key is nil
func FromCryptoPubkey(in crypto.PublicKey) (*MTCPublicKey, error) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's make this more like entry.FromX509, namely: error out on a nil input, marshal the pubkey, and store those marshaled bytes as MTCPublicKey.pub.

Comment thread trees/pubkey/pubkey.go
Comment on lines +16 to +17
typ uint16
pub crypto.PublicKey // a SubjectPublicKeyInfo structure

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's make this bytes, matching entry.MTCLogEntry.value. Then marshal can just do the cryptobyte bits of smashing together the type and this value.

Comment thread trees/pubkey/pubkey.go
Comment on lines +109 to +112
spki, err := x509.ParsePKIXPublicKey([]byte(val))
if err != nil {
return nil, err
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to parse here once mtcpk.pub is just bytes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

tiles: store pubkeys as a tile layer

2 participants