Commit e1f8f6a0 authored by Andreas Bigger's avatar Andreas Bigger

Fix small issues

parent 9393fc75
...@@ -110,7 +110,7 @@ func (s *claimSolver) AttemptStep(ctx context.Context, game types.Game, claim ty ...@@ -110,7 +110,7 @@ func (s *claimSolver) AttemptStep(ctx context.Context, game types.Game, claim ty
} else { } else {
// We agree with the claim so Defend and use this claim as the starting point to // We agree with the claim so Defend and use this claim as the starting point to
// execute the step after. Thus we need the pre-state of the next step. // execute the step after. Thus we need the pre-state of the next step.
preState, proofData, oracleData, err = s.trace.GetStepData(ctx, claim.NextStepPosition(s.gameDepth)) preState, proofData, oracleData, err = s.trace.GetStepData(ctx, claim.MoveRight())
if err != nil { if err != nil {
return StepData{}, err return StepData{}, err
} }
......
...@@ -31,14 +31,6 @@ func (c *ClaimBuilder) CorrectTraceProvider() types.TraceProvider { ...@@ -31,14 +31,6 @@ func (c *ClaimBuilder) CorrectTraceProvider() types.TraceProvider {
return c.correct return c.correct
} }
// CorrectClaim returns the canonical claim at a specified trace index
func (c *ClaimBuilder) CorrectClaim(idx uint64) common.Hash {
pos := types.NewPosition(c.maxDepth, int(idx))
value, err := c.correct.Get(context.Background(), pos)
c.require.NoError(err)
return value
}
// CorrectClaimAtPosition returns the canonical claim at a specified position // CorrectClaimAtPosition returns the canonical claim at a specified position
func (c *ClaimBuilder) CorrectClaimAtPosition(pos types.Position) common.Hash { func (c *ClaimBuilder) CorrectClaimAtPosition(pos types.Position) common.Hash {
value, err := c.correct.Get(context.Background(), pos) value, err := c.correct.Get(context.Background(), pos)
...@@ -69,20 +61,20 @@ func (c *ClaimBuilder) CorrectOracleData(idx uint64) *types.PreimageOracleData { ...@@ -69,20 +61,20 @@ func (c *ClaimBuilder) CorrectOracleData(idx uint64) *types.PreimageOracleData {
return data return data
} }
func (c *ClaimBuilder) incorrectClaim(idx uint64) common.Hash { func (c *ClaimBuilder) incorrectClaim(pos types.Position) common.Hash {
return common.BigToHash(new(big.Int).SetUint64(idx)) return common.BigToHash(new(big.Int).SetUint64(pos.TraceIndex(c.maxDepth)))
} }
func (c *ClaimBuilder) claim(idx uint64, correct bool) common.Hash { func (c *ClaimBuilder) claim(pos types.Position, correct bool) common.Hash {
if correct { if correct {
return c.CorrectClaim(idx) return c.CorrectClaimAtPosition(pos)
} else { } else {
return c.incorrectClaim(idx) return c.incorrectClaim(pos)
} }
} }
func (c *ClaimBuilder) CreateRootClaim(correct bool) types.Claim { func (c *ClaimBuilder) CreateRootClaim(correct bool) types.Claim {
value := c.claim((1<<c.maxDepth)-1, correct) value := c.claim(types.NewPositionFromGIndex((1<<c.maxDepth)-1), correct)
claim := types.Claim{ claim := types.Claim{
ClaimData: types.ClaimData{ ClaimData: types.ClaimData{
Value: value, Value: value,
...@@ -97,11 +89,11 @@ func (c *ClaimBuilder) CreateLeafClaim(traceIndex uint64, correct bool) types.Cl ...@@ -97,11 +89,11 @@ func (c *ClaimBuilder) CreateLeafClaim(traceIndex uint64, correct bool) types.Cl
pos := types.NewPosition(c.maxDepth, int(traceIndex)) pos := types.NewPosition(c.maxDepth, int(traceIndex))
return types.Claim{ return types.Claim{
ClaimData: types.ClaimData{ ClaimData: types.ClaimData{
Value: c.claim(pos.TraceIndex(c.maxDepth), correct), Value: c.claim(pos, correct),
Position: pos, Position: pos,
}, },
Parent: types.ClaimData{ Parent: types.ClaimData{
Value: c.claim(parentPos.TraceIndex(c.maxDepth), !correct), Value: c.claim(parentPos, !correct),
Position: parentPos, Position: parentPos,
}, },
} }
...@@ -111,7 +103,7 @@ func (c *ClaimBuilder) AttackClaim(claim types.Claim, correct bool) types.Claim ...@@ -111,7 +103,7 @@ func (c *ClaimBuilder) AttackClaim(claim types.Claim, correct bool) types.Claim
pos := claim.Position.Attack() pos := claim.Position.Attack()
return types.Claim{ return types.Claim{
ClaimData: types.ClaimData{ ClaimData: types.ClaimData{
Value: c.claim(pos.TraceIndex(c.maxDepth), correct), Value: c.claim(pos, correct),
Position: pos, Position: pos,
}, },
Parent: claim.ClaimData, Parent: claim.ClaimData,
...@@ -135,7 +127,7 @@ func (c *ClaimBuilder) DefendClaim(claim types.Claim, correct bool) types.Claim ...@@ -135,7 +127,7 @@ func (c *ClaimBuilder) DefendClaim(claim types.Claim, correct bool) types.Claim
pos := claim.Position.Defend() pos := claim.Position.Defend()
return types.Claim{ return types.Claim{
ClaimData: types.ClaimData{ ClaimData: types.ClaimData{
Value: c.claim(pos.TraceIndex(c.maxDepth), correct), Value: c.claim(pos, correct),
Position: pos, Position: pos,
}, },
Parent: claim.ClaimData, Parent: claim.ClaimData,
......
...@@ -18,10 +18,10 @@ func NewPositionFromGIndex(x uint64) Position { ...@@ -18,10 +18,10 @@ func NewPositionFromGIndex(x uint64) Position {
return NewPosition(depth, int(indexAtDepth)) return NewPosition(depth, int(indexAtDepth))
} }
func (p Position) NextStepPosition(gameDepth int) Position { func (p Position) MoveRight() Position {
return Position{ return Position{
depth: gameDepth, depth: p.depth,
indexAtDepth: int(p.TraceIndex(gameDepth) + 1), indexAtDepth: int(p.indexAtDepth + 1),
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment