Commit 4fb534ab authored by zhiqiangxu's avatar zhiqiangxu Committed by GitHub

`Position.TraceIndex`: panic when `maxDepth < p.depth` happens (#10007)

* ensure "maxDepth < p.depth" never happens

* add more log
parent b2fb246b
......@@ -82,9 +82,13 @@ func (p Position) lshIndex(amount Depth) *big.Int {
// TraceIndex calculates the what the index of the claim value would be inside the trace.
// It is equivalent to going right until the final depth has been reached.
// Note: this method will panic if maxDepth < p.depth
func (p Position) TraceIndex(maxDepth Depth) *big.Int {
// When we go right, we do a shift left and set the bottom bit to be 1.
// To do this in a single step, do all the shifts at once & or in all 1s for the bottom bits.
if maxDepth < p.depth {
panic(fmt.Sprintf("maxDepth(%d) < p.depth(%d)", maxDepth, p.depth))
}
rd := maxDepth - p.depth
rhs := new(big.Int).Sub(new(big.Int).Lsh(big.NewInt(1), uint(rd)), big.NewInt(1))
ti := new(big.Int).Or(p.lshIndex(rd), rhs)
......
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