forked from ethereum-optimism/optimism
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(op-challenger):add findAncestorProofAtDepth2 func
- Loading branch information
Showing
17 changed files
with
516 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package solver | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/ethereum-optimism/optimism/op-challenger/game/fault/types" | ||
) | ||
|
||
// AttemptStep determines what step, if any, should occur for a given leaf claim. | ||
// An error will be returned if the claim is not at the max depth. | ||
// Returns nil, nil if no step should be performed. | ||
func (s *claimSolver) AttemptStep2(ctx context.Context, game types.Game, claim types.Claim, honestClaims *honestClaimTracker) (*StepData, error) { | ||
if claim.Depth() != s.gameDepth { | ||
return nil, ErrStepNonLeafNode | ||
} | ||
|
||
if counter, err := s.shouldCounter(game, claim, honestClaims); err != nil { | ||
return nil, fmt.Errorf("failed to determine if claim should be countered: %w", err) | ||
} else if !counter { | ||
return nil, nil | ||
} | ||
|
||
claimCorrect, err := s.agreeWithClaim(ctx, game, claim) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
// prestateItem | ||
// postStateItem | ||
|
||
var position types.Position | ||
if !claimCorrect { | ||
// Attack the claim by executing step index, so we need to get the pre-state of that index | ||
position = claim.Position | ||
} else { | ||
// Defend and use this claim as the starting point to execute the step after. | ||
// Thus, we need the pre-state of the next step. | ||
position = claim.Position.MoveRight() | ||
} | ||
|
||
preState, proofData, oracleData, err := s.trace.GetStepData(ctx, game, claim, position) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &StepData{ | ||
LeafClaim: claim, | ||
IsAttack: !claimCorrect, | ||
PreState: preState, | ||
ProofData: proofData, | ||
OracleData: oracleData, | ||
}, nil | ||
} | ||
|
||
|
||
func findPrestateItem() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/ethereum/go-ethereum/common" | ||
"github.com/ethereum/go-ethereum/crypto" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestGetClaimsHash(t *testing.T) { | ||
claims := []common.Hash{{0x01}, {0x02}, {0x03}} | ||
rootHash := GetClaimsHash(claims) | ||
expectedHash := crypto.Keccak256Hash(claims[0][:], claims[1][:]) | ||
expectedHash = crypto.Keccak256Hash(expectedHash[:], claims[2][:]) | ||
require.Equal(t, expectedHash, rootHash) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package trace | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/ethereum-optimism/optimism/op-challenger/game/fault/types" | ||
) | ||
|
||
func (t *Accessor) GetStepData2(ctx context.Context, game types.Game, ref types.Claim, pos types.Position) (prestate []byte, proofData []byte, preimageData *types.PreimageOracleData, err error) { | ||
provider, err := t.selector(ctx, game, ref, pos) | ||
if err != nil { | ||
return nil, nil, nil, err | ||
} | ||
parentPos, err := game.GetParent(ref) | ||
if err != nil { | ||
return nil, nil, nil, err | ||
} | ||
return provider.GetStepData2(ctx, pos, parentPos.Position) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package alphabet | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"math/big" | ||
|
||
"github.com/ethereum-optimism/optimism/op-challenger/game/fault/types" | ||
preimage "github.com/ethereum-optimism/optimism/op-preimage" | ||
"github.com/ethereum/go-ethereum/common" | ||
) | ||
|
||
func (ap *AlphabetTraceProvider) GetStepData2(ctx context.Context, pos types.Position, parentPos types.Position) ([]byte, []byte, *types.PreimageOracleData, error) { | ||
traceIndex := pos.TraceIndex(ap.depth) | ||
key := preimage.LocalIndexKey(L2ClaimBlockNumberLocalIndex).PreimageKey() | ||
preimageData := types.NewPreimageOracleData(key[:], ap.startingBlockNumber.Bytes(), 0) | ||
if traceIndex.Cmp(common.Big0) == 0 { | ||
return absolutePrestate, []byte{}, preimageData, nil | ||
} | ||
if traceIndex.Cmp(new(big.Int).SetUint64(ap.maxLen)) > 0 { | ||
return nil, nil, nil, fmt.Errorf("%w depth: %v index: %v max: %v", ErrIndexTooLarge, ap.depth, traceIndex, ap.maxLen) | ||
} | ||
initialTraceIndex := new(big.Int).Lsh(ap.startingBlockNumber, uint(ap.splitDepth)) | ||
initialClaim := new(big.Int).Add(absolutePrestateInt, initialTraceIndex) | ||
newTraceIndex := new(big.Int).Add(initialTraceIndex, traceIndex) | ||
// newClaim is always, otherwise we would counter the first false subClaim | ||
newClaim := new(big.Int).Add(initialClaim, traceIndex) | ||
return BuildAlphabetPreimage(newTraceIndex, newClaim), []byte{}, preimageData, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package asterisc | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"fmt" | ||
|
||
"github.com/ethereum-optimism/optimism/op-challenger/game/fault/types" | ||
) | ||
|
||
func (p *AsteriscTraceProvider) GetStepData2(ctx context.Context, pos types.Position, parentPos types.Position) ([]byte, []byte, *types.PreimageOracleData, error) { | ||
traceIndex := pos.TraceIndex(p.gameDepth) | ||
if !traceIndex.IsUint64() { | ||
return nil, nil, nil, errors.New("trace index out of bounds") | ||
} | ||
proof, err := p.loadProof(ctx, traceIndex.Uint64()) | ||
if err != nil { | ||
return nil, nil, nil, err | ||
} | ||
value := ([]byte)(proof.StateData) | ||
if len(value) == 0 { | ||
return nil, nil, nil, errors.New("proof missing state data") | ||
} | ||
data := ([]byte)(proof.ProofData) | ||
if data == nil { | ||
return nil, nil, nil, errors.New("proof missing proof data") | ||
} | ||
oracleData, err := p.preimageLoader.LoadPreimage(proof) | ||
if err != nil { | ||
return nil, nil, nil, fmt.Errorf("failed to load preimage: %w", err) | ||
} | ||
return value, data, oracleData, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package cannon | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"fmt" | ||
|
||
"github.com/ethereum-optimism/optimism/op-challenger/game/fault/types" | ||
) | ||
|
||
func (p *CannonTraceProvider) GetStepData2(ctx context.Context, pos types.Position, parentPos types.Position) ([]byte, []byte, *types.PreimageOracleData, error) { | ||
traceIndex := pos.TraceIndex(p.gameDepth) | ||
if !traceIndex.IsUint64() { | ||
return nil, nil, nil, errors.New("trace index out of bounds") | ||
} | ||
proof, err := p.loadProof(ctx, traceIndex.Uint64()) | ||
if err != nil { | ||
return nil, nil, nil, err | ||
} | ||
value := ([]byte)(proof.StateData) | ||
if len(value) == 0 { | ||
return nil, nil, nil, errors.New("proof missing state data") | ||
} | ||
data := ([]byte)(proof.ProofData) | ||
if data == nil { | ||
return nil, nil, nil, errors.New("proof missing proof data") | ||
} | ||
oracleData, err := p.preimageLoader.LoadPreimage(proof) | ||
if err != nil { | ||
return nil, nil, nil, fmt.Errorf("failed to load preimage: %w", err) | ||
} | ||
return value, data, oracleData, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.