Skip to content

Commit 8960aa8

Browse files
authored
Proposer: add validation of the proposal returned from op-enclave (#73)
1 parent 1c658fc commit 8960aa8

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

op-enclave/enclave/server.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -272,8 +272,8 @@ func (s *Server) ExecuteStateless(
272272
return nil, err
273273
}
274274

275-
prevOutputRoot := outputRootV0(previousBlockHeader, prevMessageAccountHash)
276-
outputRoot := outputRootV0(blockHeader, messageAccount.StorageHash)
275+
prevOutputRoot := OutputRootV0(previousBlockHeader, prevMessageAccountHash)
276+
outputRoot := OutputRootV0(blockHeader, messageAccount.StorageHash)
277277
configHash := config.Hash()
278278
l2BlockNumber := common.BytesToHash(blockHeader.Number.Bytes())
279279

@@ -338,7 +338,7 @@ func (s *Server) Aggregate(ctx context.Context, configHash common.Hash, prevOutp
338338
}, nil
339339
}
340340

341-
func outputRootV0(header *types.Header, storageRoot common.Hash) common.Hash {
341+
func OutputRootV0(header *types.Header, storageRoot common.Hash) common.Hash {
342342
hash := header.Hash()
343343
var buf [128]byte
344344
copy(buf[32:], header.Root[:])

op-proposer/proposer/prover.go

+10
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,16 @@ func (o *Prover) Generate(ctx context.Context, block *types.Block) (*Proposal, e
156156
if err != nil {
157157
return nil, fmt.Errorf("failed to execute enclave state transition: %w", err)
158158
}
159+
if output.L1OriginHash != blockRef.L1Origin.Hash {
160+
return nil, fmt.Errorf("output L1 origin hash does not match expected: %s != %s", output.L1OriginHash, blockRef.L1Origin.Hash)
161+
}
162+
if output.L2BlockNumber.ToInt().Cmp(block.Number()) != 0 {
163+
return nil, fmt.Errorf("output L2 block number does not match expected: %s != %s", output.L2BlockNumber, block.Number())
164+
}
165+
outputRoot := enclave.OutputRootV0(block.Header(), block.Root())
166+
if output.OutputRoot != outputRoot {
167+
return nil, fmt.Errorf("output root does not match expected: %s != %s", output.OutputRoot, outputRoot)
168+
}
159169
return &Proposal{
160170
Output: output,
161171
From: blockRef,

0 commit comments

Comments
 (0)