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

Proposer: add validation of the proposal returned from op-enclave #73

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
6 changes: 3 additions & 3 deletions op-enclave/enclave/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,8 +272,8 @@ func (s *Server) ExecuteStateless(
return nil, err
}

prevOutputRoot := outputRootV0(previousBlockHeader, prevMessageAccountHash)
outputRoot := outputRootV0(blockHeader, messageAccount.StorageHash)
prevOutputRoot := OutputRootV0(previousBlockHeader, prevMessageAccountHash)
outputRoot := OutputRootV0(blockHeader, messageAccount.StorageHash)
configHash := config.Hash()
l2BlockNumber := common.BytesToHash(blockHeader.Number.Bytes())

Expand Down Expand Up @@ -338,7 +338,7 @@ func (s *Server) Aggregate(ctx context.Context, configHash common.Hash, prevOutp
}, nil
}

func outputRootV0(header *types.Header, storageRoot common.Hash) common.Hash {
func OutputRootV0(header *types.Header, storageRoot common.Hash) common.Hash {
hash := header.Hash()
var buf [128]byte
copy(buf[32:], header.Root[:])
Expand Down
10 changes: 10 additions & 0 deletions op-proposer/proposer/prover.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,16 @@ func (o *Prover) Generate(ctx context.Context, block *types.Block) (*Proposal, e
if err != nil {
return nil, fmt.Errorf("failed to execute enclave state transition: %w", err)
}
if output.L1OriginHash != blockRef.L1Origin.Hash {
return nil, fmt.Errorf("output L1 origin hash does not match expected: %s != %s", output.L1OriginHash, blockRef.L1Origin.Hash)
}
if output.L2BlockNumber.ToInt().Cmp(block.Number()) != 0 {
return nil, fmt.Errorf("output L2 block number does not match expected: %s != %s", output.L2BlockNumber, block.Number())
}
outputRoot := enclave.OutputRootV0(block.Header(), block.Root())
if output.OutputRoot != outputRoot {
return nil, fmt.Errorf("output root does not match expected: %s != %s", output.OutputRoot, outputRoot)
}
return &Proposal{
Output: output,
From: blockRef,
Expand Down
Loading