Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merkle proof verification #25

Open
wants to merge 4 commits into
base: integration
Choose a base branch
from
Open

Merkle proof verification #25

wants to merge 4 commits into from

Conversation

QuentinI
Copy link
Collaborator

@QuentinI QuentinI commented Feb 4, 2025

Closes #11

This PR:

  • Modifies batcher build process to link to espresso-sequencer-go's rust library
  • Moves most of espresso-related code from batcher to a separate file, espresso.go
  • After submitting transaction to HotShot and waiting for it to appear on query service, we now fetch and verify merkle proof and namespace proofs

This PR does not:

Key places to review:

How to test this PR:

Running devnet as usual should suffice

@QuentinI QuentinI changed the title [WIP] Merkle proof verification Merkle proof verification Feb 4, 2025
@QuentinI QuentinI marked this pull request as ready for review February 4, 2025 20:49
Copy link
Member

@shenkeyao shenkeyao left a comment

Choose a reason for hiding this comment

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

I haven't run the devnet to test this yet, but it looks good! Mostly nit comments.

@@ -189,9 +189,16 @@ var (
EspressoUrlFlag = &cli.StringFlag{
Name: "espresso-url",
Usage: "",
Value: "", // should be larger than the builder's max-l2-tx-size to prevent endlessly throttling some txs
Copy link
Member

Choose a reason for hiding this comment

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

Just for my understanding, is this comment no longer applicable?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It wasn't actually applicable in the first place, it was a copy-paste artifact

EnvVars: prefixEnvVars("ESPRESSO_URL"),
}

EspressoLCAddrFlag = &cli.StringFlag{
Copy link
Member

Choose a reason for hiding this comment

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

Nit: Not sure about Go naming conventions, but if it's similar to Rust, maybe it's better to use Lc rather than LC.

Copy link
Member

Choose a reason for hiding this comment

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

Another nit: Can we pick either address or url for both the Espresso URL above and the light client URL here, for naming consistency?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Nit: Not sure about Go naming conventions, but if it's similar to Rust, maybe it's better to use Lc rather than LC.

Go actually does the opposite, i.e. either "lc" or "LC" but never "Lc": https://go.dev/wiki/CodeReviewComments#initialisms

Another nit: Can we pick either address or url for both the Espresso URL above and the light client URL here, for naming consistency?

Those refer to different things though, one is an URL of an HTTP endpoint and another one is address of a contract on L1

Copy link
Member

Choose a reason for hiding this comment

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

Go actually does the opposite, i.e. either "lc" or "LC" but never "Lc": https://go.dev/wiki/CodeReviewComments#initialisms

TIL!

}

if snapshot.Height <= height {
return fmt.Errorf("snapshot height is less than or equal to the requested height")
Copy link
Member

Choose a reason for hiding this comment

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

I was wondering whether this could be a warning or info rather than an error. Should we wait for a snapshot with a larger height in this case?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We explicitly requested snapshot for this height though, so this would indicate a malicious/bugged lc contract.


blockMerkleTreeRoot := nextHeader.Header.GetBlockMerkleTreeRoot()

log.Info("Verifying merkle proof", "height", height)
Copy link
Member

Choose a reason for hiding this comment

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

Here we log height, but in most function calls we use snapshot.Height. Should we check whether they are the same?

Copy link
Member

Choose a reason for hiding this comment

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

Follow-up question: If they are not the same, i.e., snapshot.Height is larger (since the smaller case has been checked), what should we do?

I was thinking we should make sure each finalized height is properly handled without skipping. If so, we may need extra handling here.

Comment on lines +101 to +105
transaction := Transaction{
Namespace: 42,
TeeAttn: []byte{1, 2, 3, 4},
CallData: txdata.CallData(),
}.toEspresso()
Copy link
Member

Choose a reason for hiding this comment

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

Nit: It's fine as a proof of concept, but could we define this transaction somewhere at the beginning of this file and make it a const like TestTransaction? Just so we know we are going to replace it.

Comment on lines +113 to +117
timer := time.NewTimer(2 * time.Minute)
defer timer.Stop()

ticker := time.NewTicker(100 * time.Millisecond)
defer ticker.Stop()
Copy link
Member

Choose a reason for hiding this comment

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

Nit: Similar to the comment above, can we make timer and ticker consts too?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Not really, they're started at the moment of creation
The durations indeed should be declared as separate consts though, I'll address that

@dailinsubjam
Copy link
Collaborator

Devnet could run smoothly with this branch.

Copy link
Collaborator

@dailinsubjam dailinsubjam left a comment

Choose a reason for hiding this comment

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

This is cool! I left some questions for checking my understanding.

Comment on lines +154 to +155
// TODO: Generate a real attestation
teeAttestation := []byte{1, 2, 3, 4}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Here is the attestation we want to send to L1 right? Am I understanding correctly that: by this step, we know the transaction we sent to Espresso is finalized, and we'll use the espComm to form the data we sent to L1 later. ?

Copy link
Collaborator

@dailinsubjam dailinsubjam Feb 6, 2025

Choose a reason for hiding this comment

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

Wait a sec, we only want to send out attestation once to L1 iiuc, and later it will be signature on signing this TxHash(?) using the same key. I might raise up a discussion on this in zullip.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I'll go with this if that also sounds reasonable for you: Ignore the teeAttestation here and generate it right before sending a transaction to espresso (line 103 where you have TeeAttn: []byte{1, 2, 3, 4},). And I'll do the initial attestation for signer registration somewhere else.

func (l *BatchSubmitter) submitToEspresso(txdata txData) (*EspressoCommitment, error) {
transaction := Transaction{
Namespace: 42,
TeeAttn: []byte{1, 2, 3, 4},
Copy link
Collaborator

@dailinsubjam dailinsubjam Feb 6, 2025

Choose a reason for hiding this comment

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

Here is the attestation we want to send to Espresso right? This is related to one of my another comment.

EspressoLCAddrFlag = &cli.StringFlag{
Name: "espresso-light-client-addr",
Usage: "",
Value: "0x422a3492e218383753d8006c7bfa97815b44373f",
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this the real light client address? Does that mean when running kurtosis devnet, it's already connected to real lightclient, send real tx to hotshot and verify real merkleproof? If so, that's amazing! If not, I'm wondering how does it pass the merkle proof verification when running a virtual light client.

Copy link
Collaborator

@dailinsubjam dailinsubjam Feb 6, 2025

Choose a reason for hiding this comment

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

A separate thing: IIUC, Escape Hatch Functionality has been automatically served with using light client, is that correct?

@dailinsubjam
Copy link
Collaborator

dailinsubjam commented Feb 7, 2025

Got this when running just locally in optimism-espresso-integration/op-batcher, I'm on x86-64 based Linux 2023, might be a system mismatch, will take a look tomorrow.
/usr/lib/golang/pkg/tool/linux_amd64/link: running gcc failed: exit status 1 /usr/bin/ld: cannot find -lespresso_crypto_helper-x86_64-unknown-linux-gnu: No such file or directory collect2: error: ld returned 1 exit status

Upd: The error message is fine actually. I see there's some new things need to be installed from the dockerfile change: gcc, espresso-sequencer-go etc. if we want to do it locally, would be good if @QuentinI already had instructions on that, but also fine if you don't. As these Dockerfiles should suffice.

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.

Integrate with Rust library for verification
3 participants