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

Add proof validation to batch poster #301

Merged
merged 6 commits into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 33 additions & 1 deletion arbnode/batch_poster.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"context"
"encoding/binary"
"encoding/hex"
"encoding/json"
"errors"
"fmt"
"math"
Expand Down Expand Up @@ -36,6 +37,7 @@ import (

hotshotClient "github.com/EspressoSystems/espresso-sequencer-go/client"
lightclient "github.com/EspressoSystems/espresso-sequencer-go/light-client"
"github.com/offchainlabs/nitro/espressocrypto"

"github.com/offchainlabs/nitro/arbnode/dataposter"
"github.com/offchainlabs/nitro/arbnode/dataposter/storage"
Expand Down Expand Up @@ -608,7 +610,37 @@ func (b *BatchPoster) addEspressoBlockMerkleProof(
} else {
newMsg, err = arbos.MessageFromEspresso(msg.Message.Header, txs, jst)
if err != nil {
return err
return fmt.Errorf("error fetching the block merkle proof for validated height %v and leaf height %v. Request failed with error %w", snapshot.Height, jst.Header.Header.GetBlockHeight(), err)
}
jst.BlockMerkleJustification = &arbostypes.BlockMerkleJustification{BlockMerkleProof: &proof, BlockMerkleComm: nextHeader.Header.GetBlockMerkleTreeRoot()}

log.Info("About to validate merkle and namespace proofs for msg count with batch relevant to l1 height", "msg count", b.building.msgCount, "l1 height", msg.Message.Header.BlockNumber)

// Validate espresso proofs.
json_header, err := json.Marshal(jst.Header)
if err != nil {
return fmt.Errorf("Failed to Marshal the jst Header")
}

valid_proof := espressocrypto.VerifyMerkleProof(proof.Proof, json_header, *jst.BlockMerkleJustification.BlockMerkleComm, snapshot.Root)
valid_namespace := espressocrypto.VerifyNamespace(arbOSConfig.ChainID.Uint64(), *jst.Proof, *jst.Header.Header.GetPayloadCommitment(), *jst.Header.Header.GetNsTable(), txs, *jst.VidCommon)
if !(valid_proof && valid_namespace) {
return fmt.Errorf("Cannot add Espresso block merkle proof as it is not valid")
}

log.Info("Espresso proofs have been validated!", "msg count", b.building.msgCount, "l1 height", msg.Message.Header.BlockNumber)

if arbos.IsEspressoSovereignMsg(msg.Message) {
// Passing an empty byte slice as payloadSignature because txs[0] already contains the payloadSignature here
newMsg, err = arbos.MessageFromEspressoSovereignTx(txs[0], jst, []byte{}, msg.Message.Header)
if err != nil {
return err
}
} else {
newMsg, err = arbos.MessageFromEspresso(msg.Message.Header, txs, jst)
if err != nil {
return err
}
}
}
msg.Message = &newMsg
Expand Down
Loading
Loading