Skip to content

Authenticated RawDB calls for Accessors Chain File#2

Open
Sneh1999 wants to merge 15 commits into
integrationfrom
authenticated-rawdb-calls
Open

Authenticated RawDB calls for Accessors Chain File#2
Sneh1999 wants to merge 15 commits into
integrationfrom
authenticated-rawdb-calls

Conversation

@Sneh1999
Copy link
Copy Markdown
Collaborator

@Sneh1999 Sneh1999 commented Sep 30, 2025

Desciption

This is the first PR in geth to add authenticated storage. It updates the first file in rawdb to make some of the rawdb calls authenticated. It adds utility functions to verify merkle proofs over the transaction, receipts and bloom filters

Testing

go test -timeout 10m github.com/ethereum/go-ethereum/core/rawdb

Important places to review

  • Please review core/rawdb/accessors_chain.go file carefully and check I am verifying everything correctly 🙏

@Sneh1999 Sneh1999 changed the title Initial commit for authenticated rawdb calls Authenticated RawDB calls Sep 30, 2025
@Sneh1999 Sneh1999 marked this pull request as ready for review October 1, 2025 23:50
@Sneh1999 Sneh1999 force-pushed the authenticated-rawdb-calls branch from a1edc4a to 7e6ff52 Compare October 2, 2025 23:53
@Sneh1999 Sneh1999 force-pushed the authenticated-rawdb-calls branch from 7e6ff52 to a1dc0a0 Compare October 2, 2025 23:55
@Sneh1999 Sneh1999 requested review from alxiong and zacshowa October 3, 2025 19:30
@Sneh1999 Sneh1999 changed the title Authenticated RawDB calls Authenticated RawDB calls for Accessors Chain File Oct 3, 2025
@Sneh1999 Sneh1999 changed the base branch from integration to master October 3, 2025 19:43
@Sneh1999 Sneh1999 changed the base branch from master to integration October 3, 2025 19:43
Copy link
Copy Markdown

@alxiong alxiong left a comment

Choose a reason for hiding this comment

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

(take a grain of salt, I've never touch geth codebase, so my comments might be off due to lack of understanding)

Currently I see two big issues:

  1. ambiguous data types. Hash type erase what kind of hash we are expecting, body hash (via common.BytesToHash(bodybytes) or block hash (which is the hash of the body via body.Header().Hash() or block.Hash()). We should make it explicitly clear either in function name or in argument name.
  2. there's lots of duplication in verifying the same block many times because we add VerifyBlockSignature() in many rawdb functions which has inter-dependency. I think we should map out the call graph of all rawdb functions in accessors_chain.go and only add verify at the lowest/root level in the call graph.

Comment thread core/rawdb/accessors_chain.go Outdated
Comment thread core/rawdb/espresso_rawdb_utils.go Outdated
Comment on lines +50 to +62
err = StoreBlockSignatureForTests(db, h, signature)
if err != nil {
return fmt.Errorf("failed to store signature: %v", err)
}
}
return nil
}

func StoreBlockSignatureForTests(db ethdb.KeyValueWriter, blockHash common.Hash, blockSignature []byte) error {
blockNumber := binary.BigEndian.Uint64(blockHash.Bytes())
key := dbKey(BlockSignaturePrefix, (blockNumber))
return db.Put(key, blockSignature)
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

  • StoreBlockSignatureForTests seems only internal use, make it private?
  • can you explain the design rationale for the db key derivation? why do i have to convert the blockHash to a number first, what's wrong with using it directly as bytes?
func GetBlockSignature(db ethdb.KeyValueReader, blockHash common.Hash) ([]byte, error) {
    key := append(BlockSignaturePrefix, blockHash.Bytes()...)
    return db.Get(key)
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Comment thread core/rawdb/espresso_rawdb_utils.go Outdated
Comment thread core/rawdb/accessors_chain.go Outdated
Comment thread core/rawdb/accessors_chain.go Outdated

// VerifyBodyMatchesBlockHashProof verifies that the given body matches the block hash which
// the enclave has signed over.
func VerifyBodyMatchesBlockHashProof(db ethdb.Reader, number uint64, hash common.Hash, body *types.Body) error {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

so, this function name and what it does doesn't match (? imo)

I thought there should be at least GetBlockSignature, and then verify the proof? but there's no proof involved at all in the body of this func.

a clear evidence is: why would you try to get SNAPSHOT_ADDRESS but never use it, but only testing if it's non-empty?

same thing for VerifyReceiptsInBlock() and VerifyLogsInBlock().

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I was just checking if SNAPSHOT_ADDRESS is set to see if its running in TEE or not because the same code needs to work outside the TEE as well.

The proof is actually happening here because we are verifying the body of the block is indeed part of the canonical header whose hash we have signed

return nil
}

func VerifyBlockNumber(db ethdb.Reader, number uint64, hash common.Hash) error {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

this is never used

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

its used in HasBody

Comment thread core/rawdb/espresso_rawdb_utils.go Outdated
Comment thread core/rawdb/accessors_chain.go Outdated
Comment thread core/rawdb/accessors_chain.go Outdated
@alxiong
Copy link
Copy Markdown

alxiong commented Oct 8, 2025

Ah! another thing I forgot to mention is: should we use MAC or signature?
Message Authentication Code (somewhat like a signature, except with symmetric keys) are usually more efficient than a signatures.
such as https://pkg.go.dev/crypto/hmac

i'm sure KMS also support HMAC algorithm and managing MAC key.

@jbearer @Sneh1999

@Sneh1999
Copy link
Copy Markdown
Collaborator Author

Sneh1999 commented Oct 8, 2025

i'm sure KMS also support HMAC algorithm and managing MAC key.

Ah! another thing I forgot to mention is: should we use MAC or signature? Message Authentication Code (somewhat like a signature, except with symmetric keys) are usually more efficient than a signatures. such as https://pkg.go.dev/crypto/hmac

i'm sure KMS also support HMAC algorithm and managing MAC key.

@jbearer @Sneh1999

I dont know much about this so cant comment a lot all I can say is that because geth heavily uses ECDSA signatures so maybe we should also use that but I am no cryptography expert so @alxiong whatever you think is the best let me know!

@alxiong
Copy link
Copy Markdown

alxiong commented Oct 9, 2025

imo, we should definitely use HMAC over signature, this is the definition usage of MAC, and much more efficient than signature, HMAC is basically bunch of hashes which is super fast, no expensive curve operations.

Also KMS's HMAC is RFC standard, so compatible with go/crypto's impl: https://docs.aws.amazon.com/kms/latest/developerguide/hmac.html

let me demonstrate in my next PR.

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.

2 participants