-
Notifications
You must be signed in to change notification settings - Fork 644
Add proof enhancer system with customda enhancers #3750
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
base: master
Are you sure you want to change the base?
Changes from 1 commit
25e2c61
d25d882
274cfec
b99f026
905bc0e
25da751
51ad714
b89fe9d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
// Copyright 2025, Offchain Labs, Inc. | ||
// For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE.md | ||
package server_arb | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/offchainlabs/nitro/arbutil" | ||
) | ||
|
||
const ( | ||
// Enhancement flag in machine status byte | ||
ProofEnhancementFlag = 0x80 | ||
|
||
// Marker bytes for different enhancement types | ||
MarkerCustomDAReadPreimage = 0xDA | ||
MarkerCustomDAValidateCertificate = 0xDB | ||
) | ||
|
||
// ProofEnhancer enhances one-step proofs with additional data | ||
|
||
type ProofEnhancer interface { | ||
// EnhanceProof checks if enhancement is needed and applies it | ||
// Returns the enhanced proof or the original if no enhancement needed | ||
EnhanceProof(ctx context.Context, messageNum arbutil.MessageIndex, proof []byte) ([]byte, error) | ||
} | ||
|
||
// ProofEnhancementManager manages multiple proof enhancers by marker type | ||
type ProofEnhancementManager struct { | ||
enhancers map[byte]ProofEnhancer | ||
|
||
} | ||
|
||
// NewProofEnhancementManager creates a new proof enhancement manager | ||
func NewProofEnhancementManager() *ProofEnhancementManager { | ||
return &ProofEnhancementManager{ | ||
enhancers: make(map[byte]ProofEnhancer), | ||
} | ||
} | ||
|
||
// RegisterEnhancer registers an enhancer for a specific marker byte | ||
func (m *ProofEnhancementManager) RegisterEnhancer(marker byte, enhancer ProofEnhancer) { | ||
m.enhancers[marker] = enhancer | ||
} | ||
|
||
// EnhanceProof implements ProofEnhancer interface | ||
func (m *ProofEnhancementManager) EnhanceProof(ctx context.Context, messageNum arbutil.MessageIndex, proof []byte) ([]byte, error) { | ||
if len(proof) == 0 { | ||
return proof, nil | ||
} | ||
|
||
// Check if enhancement flag is set | ||
if proof[0]&ProofEnhancementFlag == 0 { | ||
return proof, nil // No enhancement needed | ||
} | ||
|
||
// Find marker at end of proof | ||
if len(proof) < 1 { // Need at least the marker byte | ||
|
||
return nil, fmt.Errorf("proof too short for enhancement: %d bytes", len(proof)) | ||
} | ||
|
||
marker := proof[len(proof)-1] | ||
enhancer, exists := m.enhancers[marker] | ||
if !exists { | ||
return nil, fmt.Errorf("unknown enhancement marker: 0x%02x", marker) | ||
} | ||
|
||
// Remove enhancement flag from machine status | ||
enhancedProof := make([]byte, len(proof)) | ||
copy(enhancedProof, proof) | ||
enhancedProof[0] &= ^byte(ProofEnhancementFlag) | ||
|
||
// Let specific enhancer handle the proof | ||
return enhancer.EnhanceProof(ctx, messageNum, enhancedProof) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
one thing that's not really apparent yet is how you'll use this interface.
Having it in server_arb suggests the intention is to have the execution client connect to the custom_da proof enhancer directly.
I think (not sure) a better option would be that the arbitrator will keep working as it is (almost stateless, responds to requests without making them), and have the consensus side so all the custom-da communication, including enhancing proofs (after it got the response from arbitrator and before it sends it to a one-step-proof).
In that case server_arb will be left unaffected.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, I put it in the wrong place. I'll move it to
validator/proofenhancement/