diff --git a/api/test/mining.go b/api/test/mining.go index b190954501..0402b81f85 100644 --- a/api/test/mining.go +++ b/api/test/mining.go @@ -153,6 +153,10 @@ func TestDealMining(t *testing.T, b APIBuilder, blocktime time.Duration, carExpo expect += <-wait time.Sleep(blocktime) + if expect == 0 { + // null block + continue + } for { n := 0 diff --git a/chain/gen/gen.go b/chain/gen/gen.go index 89d4f32bf5..99ac2f1092 100644 --- a/chain/gen/gen.go +++ b/chain/gen/gen.go @@ -558,12 +558,14 @@ func IsRoundWinner(ctx context.Context, ts *types.TipSet, round abi.ChainEpoch, return nil, xerrors.Errorf("failed to compute VRF: %w", err) } - // TODO: wire in real power - if !types.IsTicketWinner(vrfout, mbi.MinerPower, mbi.NetworkPower) { + ep := &types.ElectionProof{VRFProof: vrfout} + j := ep.ComputeWinCount(mbi.MinerPower, mbi.NetworkPower) + ep.WinCount = j + if j < 1 { return nil, nil } - return &types.ElectionProof{VRFProof: vrfout}, nil + return ep, nil } type SignFunc func(context.Context, address.Address, []byte) (*crypto.Signature, error) diff --git a/chain/stmgr/stmgr.go b/chain/stmgr/stmgr.go index 917b5ca26d..a4e6064855 100644 --- a/chain/stmgr/stmgr.go +++ b/chain/stmgr/stmgr.go @@ -143,7 +143,7 @@ type BlockMessages struct { Miner address.Address BlsMessages []types.ChainMsg SecpkMessages []types.ChainMsg - TicketCount int64 + WinCount int64 } type ExecCallback func(cid.Cid, *types.Message, *vm.ApplyRet) error @@ -311,7 +311,7 @@ func (sm *StateManager) computeTipSetState(ctx context.Context, blks []*types.Bl Miner: b.Miner, BlsMessages: make([]types.ChainMsg, 0, len(bms)), SecpkMessages: make([]types.ChainMsg, 0, len(sms)), - TicketCount: 1, //int64(len(b.EPostProof.Proofs)), // TODO fix this + WinCount: b.ElectionProof.WinCount, } for _, m := range bms { diff --git a/chain/store/weight.go b/chain/store/weight.go index c92f1a74da..eb385f816e 100644 --- a/chain/store/weight.go +++ b/chain/store/weight.go @@ -21,11 +21,11 @@ func (cs *ChainStore) Weight(ctx context.Context, ts *types.TipSet) (types.BigIn if ts == nil { return types.NewInt(0), nil } - // >>> w[r] <<< + wFunction(totalPowerAtTipset(ts)) * 2^8 + (wFunction(totalPowerAtTipset(ts)) * len(ts.blocks) * wRatio_num * 2^8) / (e * wRatio_den) + // >>> w[r] <<< + wFunction(totalPowerAtTipset(ts)) * 2^8 + (wFunction(totalPowerAtTipset(ts)) * sum(ts.blocks[].ElectionProof.WinCount) * wRatio_num * 2^8) / (e * wRatio_den) var out = new(big.Int).Set(ts.Blocks()[0].ParentWeight.Int) - // >>> wFunction(totalPowerAtTipset(ts)) * 2^8 <<< + (wFunction(totalPowerAtTipset(ts)) * len(ts.blocks) * wRatio_num * 2^8) / (e * wRatio_den) + // >>> wFunction(totalPowerAtTipset(ts)) * 2^8 <<< + (wFunction(totalPowerAtTipset(ts)) * sum(ts.blocks[].ElectionProof.WinCount) * wRatio_num * 2^8) / (e * wRatio_den) tpow := big2.Zero() { @@ -57,11 +57,19 @@ func (cs *ChainStore) Weight(ctx context.Context, ts *types.TipSet) (types.BigIn out.Add(out, big.NewInt(log2P<<8)) - // (wFunction(totalPowerAtTipset(ts)) * len(ts.blocks) * wRatio_num * 2^8) / (e * wRatio_den) + // (wFunction(totalPowerAtTipset(ts)) * sum(ts.blocks[].ElectionProof.WinCount) * wRatio_num * 2^8) / (e * wRatio_den) - eWeight := big.NewInt((log2P * int64(len(ts.Blocks())) * build.WRatioNum) << 8) - eWeight.Div(eWeight, big.NewInt(int64(build.BlocksPerEpoch*build.WRatioDen))) - out.Add(out, eWeight) + totalJ := int64(0) + for _, b := range ts.Blocks() { + totalJ += b.ElectionProof.WinCount + } + + eWeight := big.NewInt((log2P * build.WRatioNum)) + eWeight = eWeight.Lsh(eWeight, 8) + eWeight = eWeight.Mul(eWeight, new(big.Int).SetInt64(totalJ)) + eWeight = eWeight.Div(eWeight, big.NewInt(int64(build.BlocksPerEpoch*build.WRatioDen))) + + out = out.Add(out, eWeight) return types.BigInt{Int: out}, nil } diff --git a/chain/sub/incoming.go b/chain/sub/incoming.go index ba61dc5c56..0c4350d039 100644 --- a/chain/sub/incoming.go +++ b/chain/sub/incoming.go @@ -210,6 +210,12 @@ func (bv *BlockValidator) Validate(ctx context.Context, pid peer.ID, msg *pubsub return pubsub.ValidationReject } + if blk.Header.ElectionProof.WinCount < 1 { + log.Errorf("block is not claiming to be winning") + recordFailure("not_winning") + return pubsub.ValidationReject + } + // it's a good block! make sure we've only seen it once if bv.recvBlocks.add(blk.Header.Cid()) > 0 { // TODO: once these changes propagate to the network, we can consider diff --git a/chain/sync.go b/chain/sync.go index 26f30d95bb..b190dc449c 100644 --- a/chain/sync.go +++ b/chain/sync.go @@ -651,6 +651,10 @@ func (syncer *Syncer) ValidateBlock(ctx context.Context, b *types.FullBlock) (er } winnerCheck := async.Err(func() error { + if h.ElectionProof.WinCount < 1 { + return xerrors.Errorf("block is not claiming to be a winner") + } + rBeacon := *prevBeacon if len(h.BeaconEntries) != 0 { rBeacon = h.BeaconEntries[len(h.BeaconEntries)-1] @@ -660,7 +664,6 @@ func (syncer *Syncer) ValidateBlock(ctx context.Context, b *types.FullBlock) (er return xerrors.Errorf("failed to marshal miner address to cbor: %w", err) } - //TODO: DST from spec actors when it is there vrfBase, err := store.DrawRandomness(rBeacon.Data, crypto.DomainSeparationTag_ElectionProofProduction, h.Height, buf.Bytes()) if err != nil { return xerrors.Errorf("could not draw randomness: %w", err) @@ -684,8 +687,9 @@ func (syncer *Syncer) ValidateBlock(ctx context.Context, b *types.FullBlock) (er return xerrors.Errorf("failed getting power: %w", err) } - if !types.IsTicketWinner(h.ElectionProof.VRFProof, mpow.QualityAdjPower, tpow.QualityAdjPower) { - return xerrors.Errorf("miner created a block but was not a winner") + j := h.ElectionProof.ComputeWinCount(mpow.QualityAdjPower, tpow.QualityAdjPower) + if h.ElectionProof.WinCount != j { + return xerrors.Errorf("miner claims wrong number of wins: miner: %d, computed: %d", h.ElectionProof.WinCount, j) } return nil diff --git a/chain/types/bigint_test.go b/chain/types/bigint_test.go index 43e5633b2a..d337bfc85f 100644 --- a/chain/types/bigint_test.go +++ b/chain/types/bigint_test.go @@ -82,7 +82,7 @@ func TestSizeStrUnitsSymmetry(t *testing.T) { s := rand.NewSource(time.Now().UnixNano()) r := rand.New(s) - for i := 0; i < 1000000; i++ { + for i := 0; i < 10000; i++ { n := r.Uint64() l := strings.ReplaceAll(units.BytesSize(float64(n)), " ", "") r := strings.ReplaceAll(SizeStr(NewInt(n)), " ", "") diff --git a/chain/types/blockheader.go b/chain/types/blockheader.go index e238b3e5e6..4bdc00180b 100644 --- a/chain/types/blockheader.go +++ b/chain/types/blockheader.go @@ -23,10 +23,6 @@ type Ticket struct { VRFProof []byte } -type ElectionProof struct { - VRFProof []byte -} - type BeaconEntry struct { Round uint64 Data []byte diff --git a/chain/types/blockheader_test.go b/chain/types/blockheader_test.go index a1ece308ad..4cd46bde14 100644 --- a/chain/types/blockheader_test.go +++ b/chain/types/blockheader_test.go @@ -4,11 +4,11 @@ import ( "bytes" "encoding/hex" "fmt" - "github.com/stretchr/testify/require" "reflect" "testing" cid "github.com/ipfs/go-cid" + "github.com/stretchr/testify/require" "github.com/filecoin-project/go-address" "github.com/filecoin-project/specs-actors/actors/abi" @@ -86,7 +86,7 @@ func TestInteropBH(t *testing.T) { bh := &BlockHeader{ Miner: newAddr, Ticket: &Ticket{[]byte{0x01, 0x02, 0x03}}, - ElectionProof: &ElectionProof{[]byte{0x0a, 0x0b}}, + ElectionProof: &ElectionProof{0, []byte{0x0a, 0x0b}}, BeaconEntries: []BeaconEntry{ { Round: 5, @@ -116,8 +116,7 @@ func TestInteropBH(t *testing.T) { t.Fatal(err) } - // acquired from go-filecoin - gfc := "8f5501d04cb15021bf6bd003073d79e2238d4e61f1ad22814301020381420a0b818205410c818200410781d82a5827000171a0e402202f84fef0d7cc2d7f9f00d22445f7bf7539fdd685fd9f284aa37f3822b57619cc430003e802d82a5827000171a0e402202f84fef0d7cc2d7f9f00d22445f7bf7539fdd685fd9f284aa37f3822b57619ccd82a5827000171a0e402202f84fef0d7cc2d7f9f00d22445f7bf7539fdd685fd9f284aa37f3822b57619ccd82a5827000171a0e402202f84fef0d7cc2d7f9f00d22445f7bf7539fdd685fd9f284aa37f3822b57619cc410001f603" + gfc := "8f5501d04cb15021bf6bd003073d79e2238d4e61f1ad2281430102038200420a0b818205410c818200410781d82a5827000171a0e402202f84fef0d7cc2d7f9f00d22445f7bf7539fdd685fd9f284aa37f3822b57619cc430003e802d82a5827000171a0e402202f84fef0d7cc2d7f9f00d22445f7bf7539fdd685fd9f284aa37f3822b57619ccd82a5827000171a0e402202f84fef0d7cc2d7f9f00d22445f7bf7539fdd685fd9f284aa37f3822b57619ccd82a5827000171a0e402202f84fef0d7cc2d7f9f00d22445f7bf7539fdd685fd9f284aa37f3822b57619cc410001f603" require.Equal(t, gfc, hex.EncodeToString(bhsb)) } diff --git a/chain/types/cbor_gen.go b/chain/types/cbor_gen.go index b521717975..9932b18638 100644 --- a/chain/types/cbor_gen.go +++ b/chain/types/cbor_gen.go @@ -505,7 +505,7 @@ func (t *Ticket) UnmarshalCBOR(r io.Reader) error { return nil } -var lengthBufElectionProof = []byte{129} +var lengthBufElectionProof = []byte{130} func (t *ElectionProof) MarshalCBOR(w io.Writer) error { if t == nil { @@ -518,6 +518,17 @@ func (t *ElectionProof) MarshalCBOR(w io.Writer) error { scratch := make([]byte, 9) + // t.WinCount (int64) (int64) + if t.WinCount >= 0 { + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajUnsignedInt, uint64(t.WinCount)); err != nil { + return err + } + } else { + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajNegativeInt, uint64(-t.WinCount-1)); err != nil { + return err + } + } + // t.VRFProof ([]uint8) (slice) if len(t.VRFProof) > cbg.ByteArrayMaxLen { return xerrors.Errorf("Byte array in field t.VRFProof was too long") @@ -545,10 +556,35 @@ func (t *ElectionProof) UnmarshalCBOR(r io.Reader) error { return fmt.Errorf("cbor input should be of type array") } - if extra != 1 { + if extra != 2 { return fmt.Errorf("cbor input had wrong number of fields") } + // t.WinCount (int64) (int64) + { + maj, extra, err := cbg.CborReadHeaderBuf(br, scratch) + var extraI int64 + if err != nil { + return err + } + switch maj { + case cbg.MajUnsignedInt: + extraI = int64(extra) + if extraI < 0 { + return fmt.Errorf("int64 positive overflow") + } + case cbg.MajNegativeInt: + extraI = int64(extra) + if extraI < 0 { + return fmt.Errorf("int64 negative oveflow") + } + extraI = -1 - extraI + default: + return fmt.Errorf("wrong type for int64 field: %d", maj) + } + + t.WinCount = int64(extraI) + } // t.VRFProof ([]uint8) (slice) maj, extra, err = cbg.CborReadHeaderBuf(br, scratch) diff --git a/chain/types/electionproof.go b/chain/types/electionproof.go new file mode 100644 index 0000000000..b8879b27c8 --- /dev/null +++ b/chain/types/electionproof.go @@ -0,0 +1,205 @@ +package types + +import ( + "math/big" + + "github.com/filecoin-project/lotus/build" + "github.com/minio/blake2b-simd" +) + +type ElectionProof struct { + WinCount int64 + VRFProof []byte +} + +const precision = 256 + +var ( + expNumCoef []*big.Int + expDenoCoef []*big.Int +) + +func init() { + parse := func(coefs []string) []*big.Int { + out := make([]*big.Int, len(coefs)) + for i, coef := range coefs { + c, ok := new(big.Int).SetString(coef, 10) + if !ok { + panic("could not parse exp paramemter") + } + // << 256 (Q.0 to Q.256), >> 128 to transform integer params to coefficients + c = c.Lsh(c, precision-128) + out[i] = c + } + return out + } + + // parameters are in integer format, + // coefficients are *2^-128 of that + num := []string{ + "-648770010757830093818553637600", + "67469480939593786226847644286976", + "-3197587544499098424029388939001856", + "89244641121992890118377641805348864", + "-1579656163641440567800982336819953664", + "17685496037279256458459817590917169152", + "-115682590513835356866803355398940131328", + "340282366920938463463374607431768211456", + } + expNumCoef = parse(num) + + deno := []string{ + "1225524182432722209606361", + "114095592300906098243859450", + "5665570424063336070530214243", + "194450132448609991765137938448", + "5068267641632683791026134915072", + "104716890604972796896895427629056", + "1748338658439454459487681798864896", + "23704654329841312470660182937960448", + "259380097567996910282699886670381056", + "2250336698853390384720606936038375424", + "14978272436876548034486263159246028800", + "72144088983913131323343765784380833792", + "224599776407103106596571252037123047424", + "340282366920938463463374607431768211456", + } + expDenoCoef = parse(deno) +} + +// expneg accepts x in Q.256 format and computes e^-x. +// It is most precise within [0, 1.725) range, where error is less than 3.4e-30. +// Over the [0, 5) range its error is less than 4.6e-15. +// Output is in Q.256 format. +func expneg(x *big.Int) *big.Int { + // exp is approximated by rational function + // polynomials of the rational function are evaluated using Horner's method + num := polyval(expNumCoef, x) // Q.256 + deno := polyval(expDenoCoef, x) // Q.256 + + num = num.Lsh(num, precision) // Q.512 + return num.Div(num, deno) // Q.512 / Q.256 => Q.256 +} + +// polyval evaluates a polynomial given by coefficients `p` in Q.256 format +// at point `x` in Q.256 format. Output is in Q.256. +// Coefficients should be ordered from the highest order coefficient to the lowest. +func polyval(p []*big.Int, x *big.Int) *big.Int { + // evaluation using Horner's method + res := new(big.Int).Set(p[0]) // Q.256 + tmp := new(big.Int) // big.Int.Mul doesn't like when input is reused as output + for _, c := range p[1:] { + tmp = tmp.Mul(res, x) // Q.256 * Q.256 => Q.512 + res = res.Rsh(tmp, precision) // Q.512 >> 256 => Q.256 + res = res.Add(res, c) + } + + return res +} + +// computes lambda in Q.256 +func lambda(power, totalPower *big.Int) *big.Int { + lam := new(big.Int).Mul(power, blocksPerEpoch.Int) // Q.0 + lam = lam.Lsh(lam, precision) // Q.256 + lam = lam.Div(lam /* Q.256 */, totalPower /* Q.0 */) // Q.256 + return lam +} + +var MaxWinCount = 3 * int64(build.BlocksPerEpoch) + +type poiss struct { + lam *big.Int + pmf *big.Int + icdf *big.Int + + tmp *big.Int // temporary variable for optimization + + k uint64 +} + +// newPoiss starts poisson inverted CDF +// lambda is in Q.256 format +// returns (instance, `1-poisscdf(0, lambda)`) +// CDF value returend is reused when calling `next` +func newPoiss(lambda *big.Int) (*poiss, *big.Int) { + + // pmf(k) = (lambda^k)*(e^lambda) / k! + // k = 0 here, so it simplifies to just e^-lambda + elam := expneg(lambda) // Q.256 + pmf := new(big.Int).Set(elam) + + // icdf(k) = 1 - ∑ᵏᵢ₌₀ pmf(i) + // icdf(0) = 1 - pmf(0) + icdf := big.NewInt(1) + icdf = icdf.Lsh(icdf, precision) // Q.256 + icdf = icdf.Sub(icdf, pmf) // Q.256 + + k := uint64(0) + + p := &poiss{ + lam: lambda, + pmf: pmf, + + tmp: elam, + icdf: icdf, + + k: k, + } + + return p, icdf +} + +// next computes `k++, 1-poisscdf(k, lam)` +// return is in Q.256 format +func (p *poiss) next() *big.Int { + // incrementally compute next pmf and icdf + + // pmf(k) = (lambda^k)*(e^lambda) / k! + // so pmf(k) = pmf(k-1) * lambda / k + p.k++ + p.tmp.SetUint64(p.k) // Q.0 + + // calculate pmf for k + p.pmf = p.pmf.Div(p.pmf, p.tmp) // Q.256 / Q.0 => Q.256 + // we are using `tmp` as target for multiplication as using an input as output + // for Int.Mul causes allocations + p.tmp = p.tmp.Mul(p.pmf, p.lam) // Q.256 * Q.256 => Q.512 + p.pmf = p.pmf.Rsh(p.tmp, precision) // Q.512 >> 256 => Q.256 + + // calculate output + // icdf(k) = icdf(k-1) - pmf(k) + p.icdf = p.icdf.Sub(p.icdf, p.pmf) // Q.256 + return p.icdf +} + +// ComputeWinCount uses VRFProof to compute number of wins +// The algorithm is based on Algorand's Sortition with Binomial distribution +// replaced by Poisson distribution. +func (ep *ElectionProof) ComputeWinCount(power BigInt, totalPower BigInt) int64 { + h := blake2b.Sum256(ep.VRFProof) + + lhs := BigFromBytes(h[:]).Int // 256bits, assume Q.256 so [0, 1) + + // We are calculating upside-down CDF of Poisson distribution with + // rate λ=power*E/totalPower + // Steps: + // 1. calculate λ=power*E/totalPower + // 2. calculate elam = exp(-λ) + // 3. Check how many times we win: + // j = 0 + // pmf = elam + // rhs = 1 - pmf + // for h(vrf) < rhs: j++; pmf = pmf * lam / j; rhs = rhs - pmf + + lam := lambda(power.Int, totalPower.Int) // Q.256 + + p, rhs := newPoiss(lam) + + var j int64 + for lhs.Cmp(rhs) < 0 && j < MaxWinCount { + rhs = p.next() + j++ + } + + return j +} diff --git a/chain/types/electionproof_test.go b/chain/types/electionproof_test.go new file mode 100644 index 0000000000..9344ff6a68 --- /dev/null +++ b/chain/types/electionproof_test.go @@ -0,0 +1,145 @@ +package types + +import ( + "bytes" + "fmt" + "math/big" + "os" + "testing" + + "github.com/stretchr/testify/assert" + "github.com/xorcare/golden" +) + +func TestPoissonFunction(t *testing.T) { + tests := []struct { + lambdaBase uint64 + lambdaShift uint + }{ + {10, 10}, // 0.0097 + {209714, 20}, // 0.19999885 + {1036915, 20}, // 0.9888792038 + {1706, 10}, // 1.6660 + {2, 0}, // 2 + {5242879, 20}, //4.9999990 + {5, 0}, // 5 + } + + for _, test := range tests { + test := test + t.Run(fmt.Sprintf("lam-%d-%d", test.lambdaBase, test.lambdaShift), func(t *testing.T) { + b := &bytes.Buffer{} + b.WriteString("icdf\n") + + lam := new(big.Int).SetUint64(test.lambdaBase) + lam = lam.Lsh(lam, precision-test.lambdaShift) + p, icdf := newPoiss(lam) + + b.WriteString(icdf.String()) + b.WriteRune('\n') + + for i := 0; i < 15; i++ { + b.WriteString(p.next().String()) + b.WriteRune('\n') + } + golden.Assert(t, []byte(b.String())) + }) + } +} + +func TestLambdaFunction(t *testing.T) { + tests := []struct { + power string + totalPower string + target float64 + }{ + {"10", "100", .1 * 5.}, + {"1024", "2048", 0.5 * 5.}, + {"2000000000000000", "100000000000000000", 0.02 * 5.}, + } + + for _, test := range tests { + test := test + t.Run(fmt.Sprintf("%s-%s", test.power, test.totalPower), func(t *testing.T) { + pow, ok := new(big.Int).SetString(test.power, 10) + assert.True(t, ok) + total, ok := new(big.Int).SetString(test.totalPower, 10) + assert.True(t, ok) + lam := lambda(pow, total) + assert.Equal(t, test.target, q256ToF(lam)) + golden.Assert(t, []byte(lam.String())) + }) + } +} + +func TestExpFunction(t *testing.T) { + const N = 256 + + step := big.NewInt(5) + step = step.Lsh(step, 256) // Q.256 + step = step.Div(step, big.NewInt(N-1)) + + x := big.NewInt(0) + b := &bytes.Buffer{} + + b.WriteString("x, y\n") + for i := 0; i < N; i++ { + y := expneg(x) + fmt.Fprintf(b, "%s,%s\n", x, y) + x = x.Add(x, step) + } + + golden.Assert(t, b.Bytes()) +} + +func q256ToF(x *big.Int) float64 { + deno := big.NewInt(1) + deno = deno.Lsh(deno, 256) + rat := new(big.Rat).SetFrac(x, deno) + f, _ := rat.Float64() + return f +} + +func TestElectionLam(t *testing.T) { + p := big.NewInt(64) + tot := big.NewInt(128) + lam := lambda(p, tot) + target := 64. * 5. / 128. + if q256ToF(lam) != target { + t.Fatalf("wrong lambda: %f, should be: %f", q256ToF(lam), target) + } +} + +var Res int64 + +func BenchmarkWinCounts(b *testing.B) { + totalPower := NewInt(100) + power := NewInt(100) + ep := &ElectionProof{VRFProof: nil} + var res int64 + + b.ResetTimer() + b.ReportAllocs() + for i := 0; i < b.N; i++ { + ep.VRFProof = []byte{byte(i), byte(i >> 8), byte(i >> 16), byte(i >> 24), byte(i >> 32)} + j := ep.ComputeWinCount(power, totalPower) + res += j + } + Res += res +} + +func TestWinCounts(t *testing.T) { + t.SkipNow() + totalPower := NewInt(100) + power := NewInt(30) + + f, _ := os.Create("output.wins") + fmt.Fprintf(f, "wins\n") + ep := &ElectionProof{VRFProof: nil} + for i := uint64(0); i < 1000000; i++ { + i := i + 1000000 + ep.VRFProof = []byte{byte(i), byte(i >> 8), byte(i >> 16), byte(i >> 24), byte(i >> 32)} + j := ep.ComputeWinCount(power, totalPower) + fmt.Fprintf(f, "%d\n", j) + } +} diff --git a/chain/types/testdata/TestExpFunction.golden b/chain/types/testdata/TestExpFunction.golden new file mode 100644 index 0000000000..1fb9318747 --- /dev/null +++ b/chain/types/testdata/TestExpFunction.golden @@ -0,0 +1,257 @@ +x, y +0,115792089237316195423570985008687907853269984665640564039457584007913129639936 +2270433122300317557324921274680155055946470287561579687048187921723786855685,113543770489016942962237377411819033281128847358465443152965692667674515268459 +4540866244600635114649842549360310111892940575123159374096375843447573711370,111339107030360092669625707586928312989271150877369072427721155459215537208890 +6811299366900952671974763824040465167839410862684739061144563765171360567055,109177251212712547631698034978205369781807498766451007885527881500477232021682 +9081732489201270229299685098720620223785881150246318748192751686895147422740,107057371846115774238270822835274977319670170085938012474442950429894883628816 +11352165611501587786624606373400775279732351437807898435240939608618934278425,104978653879710027736182386389791146063108246474333192437116903221506365793784 +13622598733801905343949527648080930335678821725369478122289127530342721134110,102940298088363735750708779071187005425195044826988440514290336074628648838684 +15893031856102222901274448922761085391625292012931057809337315452066507989795,100941520765387555093691898043462296359944447036680097792913901290457279892923 +18163464978402540458599370197441240447571762300492637496385503373790294845480,98981553421214956610998073555828635758296463224923810238433739306701915887016 +20433898100702858015924291472121395503518232588054217183433691295514081701165,97059642487933486831615191223039105587754475193940197594806835165639555904556 +22704331223003175573249212746801550559464702875615796870481879217237868556850,95175049029553104647921939291264669504212075519331704270982994731418832879574 +24974764345303493130574134021481705615411173163177376557530067138961655412535,93327048457900197046298852001610623840008858609979636336358094295509875743050 +27245197467603810687899055296161860671357643450738956244578255060685442268220,91514930254028040867379060937212497464993417057199803702713818093495592131219 +29515630589904128245223976570842015727304113738300535931626442982409229123905,89737997695036598537471612414728492361735134837457880776578397164411259714034 +31786063712204445802548897845522170783250584025862115618674630904133015979590,87995567586196615492499061341239298336716207707733388009305962491415997438251 +34056496834504763359873819120202325839197054313423695305722818825856802835275,86286969998275026412807199079440137158468693464163642116594809068619896392941 +36326929956805080917198740394882480895143524600985274992771006747580589690960,84611548009960677185535234025783667242734659094160158991843756961639811974930 +38597363079105398474523661669562635951089994888546854679819194669304376546645,82968657455291330479761642121918798999912566007436555574905312488221049770642 +40867796201405716031848582944242791007036465176108434366867382591028163402330,81357666675984845712317087407692885985045766475399018683682465654293317561467 +43138229323706033589173504218922946062982935463670014053915570512751950258015,79777956278579309738294730369672998880873563557913118175337099978291132200541 +45408662446006351146498425493603101118929405751231593740963758434475737113700,78228918896288743544848199105491032646200262796326433813989850094529077282776 +47679095568306668703823346768283256174875876038793173428011946356199523969385,76709958955482823270730386397827358293917115388940737122493792142598409249118 +49949528690606986261148268042963411230822346326354753115060134277923310825070,75220492446700831714270851931718222334181221472926734650894450187207587804959 +52219961812907303818473189317643566286768816613916332802108322199647097680755,73759946700111799812659669164881767734266809389910877226542646506513000978489 +54490394935207621375798110592323721342715286901477912489156510121370884536440,72327760165334507045772504425420867449416167380982855532448913178137554210923 +56760828057507938933123031867003876398661757189039492176204698043094671392125,70923382195532685995592428750934431740132395987623204573329785474158712116147 +59031261179808256490447953141684031454608227476601071863252885964818458247810,69546272835702420022053453330708655397369524375477499739230911030535808540657 +61301694302108574047772874416364186510554697764162651550301073886542245103495,68195902615070334829829990481057773300819373544625447529491837404705895284329 +63572127424408891605097795691044341566501168051724231237349261808266031959180,66871752343522765217935231891690355471651496064655471661919663456330328641288 +65842560546709209162422716965724496622447638339285810924397449729989818814865,65573312911987628132646843093927406319425698793733957333572673848799954239855 +68112993669009526719747638240404651678394108626847390611445637651713605670550,64300085096692252880128256597394188085029084300287019159255155536716536636582 +70383426791309844277072559515084806734340578914408970298493825573437392526235,63051579367221909582465988028351521656270181701866074076641181901174457665557 +72653859913610161834397480789764961790287049201970549985542013495161179381920,61827315698305238252660159775306665170268657207834096298284442133031571582783 +74924293035910479391722402064445116846233519489532129672590201416884966237605,60626823385254213782224025259478780989246898268785251219150451819890211607196 +77194726158210796949047323339125271902179989777093709359638389338608753093290,59449640862987687230396859494036983576366375788559345059199710577555290424321 +79465159280511114506372244613805426958126460064655289046686577260332539948975,58295315528568921616783939661658889268848452171972763039788768615558483626267 +81735592402811432063697165888485582014072930352216868733734765182056326804660,57163403567188891479248718554448273836403260979137552976694337187145017476501 +84006025525111749621022087163165737070019400639778448420782953103780113660345,56053469781528440285551018178364674618486430618035927413379628478874266581878 +86276458647412067178347008437845892125965870927340028107831141025503900516030,54965087424433688889920273781092319643978134551542030239286748341146003208614 +88546891769712384735671929712526047181912341214901607794879328947227687371715,53897838034840362103953324191045652555242797708181047223345801682385818568835 +90817324892012702292996850987206202237858811502463187481927516868951474227400,52851311276883949594712447365930530107052884187291818795931120263968492084774 +93087758014313019850321772261886357293805281790024767168975704790675261083085,51825104782133842211941756402475821837684219892038783449941692633646927028868 +95358191136613337407646693536566512349751752077586346856023892712399047938770,50818823994890785951863832476942579771969130641977742986737254850253840075592 +97628624258913654964971614811246667405698222365147926543072080634122834794455,49832082020488173548864433257316990617151231489408392527154422207621203727615 +99899057381213972522296536085926822461644692652709506230120268555846621650140,48864499476538848601355411822273410550321020146722594189563317351144555102308 +102169490503514290079621457360606977517591162940271085917168456477570408505825,47915704347070229628266128780655102907390977725210624641985610920484495320871 +104439923625814607636946378635287132573537633227832665604216644399294195361510,46985331839491671953371264029121450743887309752499067780940162596021543960818 +106710356748114925194271299909967287629484103515394245291264832321017982217195,46073024244339074252983177578294403714924665379395655719184742489399140111119 +108980789870415242751596221184647442685430573802955824978313020242741769072880,45178430797742804397094652011443390009353450908460410593202993111115176300509 +111251222992715560308921142459327597741377044090517404665361208164465555928565,44301207546566066275398443059622984529245531090835413454138285364317904357889 +113521656115015877866246063734007752797323514378078984352409396086189342784250,43441017216161856030307536334277824451020867870703344545581645152489753618625 +115792089237316195423570985008687907853269984665640564039457584007913129639935,42597529080697662913911602080197270017224605406643086589378214572018159359656 +118062522359616512980895906283368062909216454953202143726505771929636916495620,41770418835998057231823154500906296232954940017107200954896529163626836852806 +120332955481916830538220827558048217965162925240763723413553959851360703351305,40959368474856275913667539524102962047053738936489506227266772182693729839202 +122603388604217148095545748832728373021109395528325303100602147773084490206990,40164066164766865529760099118055626254866338159841829407810028308443332329921 +124873821726517465652870670107408528077055865815886882787650335694808277062675,39384206128032373421270623986368325593061645265273820139765067969067422649415 +127144254848817783210195591382088683133002336103448462474698523616532063918360,38619488524197990384791697485732970600503064875453399931120765038045198401265 +129414687971118100767520512656768838188948806391010042161746711538255850774045,37869619334768943402646797366590078932213917335501796767692394741802326454228 +131685121093418418324845433931448993244895276678571621848794899459979637629730,37134310250166314581624891999905972285593140562157169782497980837053288139911 +133955554215718735882170355206129148300841746966133201535843087381703424485415,36413278558877823092557676422579316779501436559193491643756131394023796062011 +136225987338019053439495276480809303356788217253694781222891275303427211341100,35706247038760950822158313374858241516488865748339595127547394046982094249410 +138496420460319370996820197755489458412734687541256360909939463225150998196785,35012943850456619981286410714734531636271581473914516202135729910546566402779 +140766853582619688554145119030169613468681157828817940596987651146874785052470,34333102432872442378462629116615524982524168457316936505909372845805604900401 +143037286704920006111470040304849768524627628116379520284035839068598571908155,33666461400695355776019567288676251030810566791286359575983902200864972469996 +145307719827220323668794961579529923580574098403941099971084026990322358763840,33012764443894243004677309675463059806544657868579375264515822376830510918451 +147578152949520641226119882854210078636520568691502679658132214912046145619525,32371760229173894620565861867718452819385944209047587245952825283707541232161 +149848586071820958783444804128890233692467038979064259345180402833769932475210,31743202303342426140951325851524709564919796135818066107980273521807047228205 +152119019194121276340769725403570388748413509266625839032228590755493719330895,31126848998554996579614932864397941484844825641744252641191173459915093805187 +154389452316421593898094646678250543804359979554187418719276778677217506186580,30522463339397396402839881838375473280428264227964104623768547140174704396628 +156659885438721911455419567952930698860306449841748998406324966598941293042265,29929812951773780419644078230146692062203486832083285970050129935848796157421 +158930318561022229012744489227610853916252920129310578093373154520665079897950,29348669973563514777235550444240282773251884769510008252819331832439494645079 +161200751683322546570069410502291008972199390416872157780421342442388866753635,28778810967012787421358795112757003059950944596369120909715112149169964220370 +163471184805622864127394331776971164028145860704433737467469530364112653609320,28220016832827298362763401072714572174637391915333615996330037256359689152007 +165741617927923181684719253051651319084092330991995317154517718285836440465005,27672072725933000121901983367925347694111025283271589335038719296229849510185 +168012051050223499242044174326331474140038801279556896841565906207560227320690,27134767972872500055614403280459447260039099989714465645168626995212978266528 +170282484172523816799369095601011629195985271567118476528614094129284014176375,26607895990805365148558542391218752327077936735384764869356894955189244136002 +172552917294824134356694016875691784251931741854680056215662282051007801032060,26091254208081186520295830628576992670321075391182679321065607327265313932322 +174823350417124451914018938150371939307878212142241635902710469972731587887745,25584643986354865593328765236833491064966760582438881050282097633879965205565 +177093783539424769471343859425052094363824682429803215589758657894455374743430,25087870544214176820510595839294024971107825899184642127021233999936247081507 +179364216661725087028668780699732249419771152717364795276806845816179161599115,24600742882290243310082706540466488496131563143845631581983311961047083061256 +181634649784025404585993701974412404475717623004926374963855033737902948454800,24123073709822131836694888705209306323992339748006300420231840208502026712055 +183905082906325722143318623249092559531664093292487954650903221659626735310485,23654679372647332806338881400061315566868133427664662629105489367609937695646 +186175516028626039700643544523772714587610563580049534337951409581350522166170,23195379782590438967131080837393236404679360225477050241221440433306491390529 +188445949150926357257968465798452869643557033867611114024999597503074309021855,22744998348222874237097258296963376819397584603868543116623643157984253142510 +190716382273226674815293387073133024699503504155172693712047785424798095877540,22303361906967051161228844170125488556352938430940411562982254002868044311034 +192986815395526992372618308347813179755449974442734273399095973346521882733225,21870300658518852415771961233241780589753603014109439052609181643134330131200 +195257248517827309929943229622493334811396444730295853086144161268245669588910,21445648099562838646716735757033316057251336889853858375428467187815522927837 +197527681640127627487268150897173489867342915017857432773192349189969456444595,21029240959755081956656390289742251499446416407847034496990361844628688581109 +199798114762427945044593072171853644923289385305419012460240537111693243300280,20620919138949011730680161329173099008306763464882403634448661640684501661866 +202068547884728262601917993446533799979235855592980592147288725033417030155965,20220525645640137405137620676980023532901299004381393279093890751532452054423 +204338981007028580159242914721213955035182325880542171834336912955140817011650,19827906536605981416712487046651644994469849037549721389552871270682788176368 +206609414129328897716567835995894110091128796168103751521385100876864603867335,19442910857718015103451661807495877546362994006807802531582187045985408388323 +208879847251629215273892757270574265147075266455665331208433288798588390723020,19065390585902840940891643898043637774181614198870274451246241331546097600612 +211150280373929532831217678545254420203021736743226910895481476720312177578705,18695200572230306358460705740514292808692490977651168538902708783481421680348 +213420713496229850388542599819934575258968207030788490582529664642035964434390,18332198486106667663798285266862799262530724876828607112610697476363307765699 +215691146618530167945867521094614730314914677318350070269577852563759751290075,17976244760551347472111336927386090359808454572176186089250363261529225698797 +217961579740830485503192442369294885370861147605911649956626040485483538145760,17627202538536245657534631830721579840416279034844169182844082749512022955880 +220232012863130803060517363643975040426807617893473229643674228407207325001445,17284937620366972373860132250248373607831381821348510576523341628979456457899 +222502445985431120617842284918655195482754088181034809330722416328931111857130,16949318412085772290021286893087219332537721900597190962614965688689436470898 +224772879107731438175167206193335350538700558468596389017770604250654898712815,16620215874876302005383259706474512944760516297587146250989332554945114509504 +227043312230031755732492127468015505594647028756157968704818792172378685568500,16297503475450807802230954908656139014943597886328184429574709348911081384486 +229313745352332073289817048742695660650593499043719548391866980094102472424185,15981057137400628605961920332938849374838761847812884031059653371884698227732 +231584178474632390847141970017375815706539969331281128078915168015826259279870,15670755193491319402603874616100339746216923922257041729716527735529769853650 +233854611596932708404466891292055970762486439618842707765963355937550046135555,15366478338884053550790009737665512422829259009202431332168817628656130747976 +236125044719233025961791812566736125818432909906404287453011543859273832991240,15068109585265318560877642552077774766432262308314225827173090425609387180236 +238395477841533343519116733841416280874379380193965867140059731780997619846925,14775534215867269134414164114591717654313758765518045957328319974951247947864 +240665910963833661076441655116096435930325850481527446827107919702721406702610,14488639741361443696906809527925407527798326175077538816130520515576676432536 +242936344086133978633766576390776590986272320769089026514156107624445193558295,14207315856608886447500721787929418266891341269962575206208292606790558927738 +245206777208434296191091497665456746042218791056650606201204295546168980413980,13931454398250046219817842121237250069017319717552215812396900410729316780042 +247477210330734613748416418940136901098165261344212185888252483467892767269665,13660949303118146325455249570700165024364040604752663984462703166489664742339 +249747643453034931305741340214817056154111731631773765575300671389616554125350,13395696567460036159625482974163434950873419335747629798807509358843043114747 +252018076575335248863066261489497211210058201919335345262348859311340340981035,13135594206948845808872493016734991140070074672980170698797842470835657746355 +254288509697635566420391182764177366266004672206896924949397047233064127836720,12880542217473069333080972366140272174677497922483630681691757178031836728636 +256558942819935883977716104038857521321951142494458504636445235154787914692405,12630442536687000915161971042648362535726831652623366360951945091372138829073 +258829375942236201535041025313537676377897612782020084323493423076511701548090,12385199006307740796619289137869014505391917569864233277491827537392271272526 +261099809064536519092365946588217831433844083069581664010541610998235488403775,12144717335144274958225939593470301902208893969091913127900701796820969916276 +263370242186836836649690867862897986489790553357143243697589798919959275259460,11908905062844413972629474569782724684547574705479145661987238841262047512889 +265640675309137154207015789137578141545737023644704823384637986841683062115145,11677671524345652458077781103683012746985203951843087585351200546458450234583 +267911108431437471764340710412258296601683493932266403071686174763406848970830,11450927815016281205730420816822769656276856651451425159655410140798486590368 +270181541553737789321665631686938451657629964219827982758734362685130635826515,11228586756473349441251594323339849390046255944661352162796836657552528120100 +272451974676038106878990552961618606713576434507389562445782550606854422682200,11010562863064334916605775798811477728189133603960442457397758272811779333449 +274722407798338424436315474236298761769522904794951142132830738528578209537885,10796772308999634710251182117797466377054234368136632046647040836884880709149 +276992840920638741993640395510978916825469375082512721819878926450301996393570,10587132896123239841361951569073852197393979276538146129343090522801499481360 +279263274042939059550965316785659071881415845370074301506927114372025783249255,10381564022309202172514611506897394878877748812065679452742065418299049556809 +281533707165239377108290238060339226937362315657635881193975302293749570104940,10179986650471742679787468858482358928499942961441493648347660820939932354037 +283804140287539694665615159335019381993308785945197460881023490215473356960625,9982323278177086101950544601003257424140532557067992549916807460469069141662 +286074573409840012222940080609699537049255256232759040568071678137197143816310,9788497907845338332079968817743865213174453409259845129758908478094549262272 +288345006532140329780265001884379692105201726520320620255119866058920930671995,9598436017530949774464402361919053565881937627109257874972510208401009770963 +290615439654440647337589923159059847161148196807882199942168053980644717527680,9412064532270530344304969563638312480198627803597895883581869229790285361030 +292885872776740964894914844433740002217094667095443779629216241902368504383365,9229311795986999922973693773512111376663242782368889508055395732551288322377 +295156305899041282452239765708420157273041137383005359316264429824092291239050,9050107543939271981357133004643947981886610395815063538792001543567721697353 +297426739021341600009564686983100312328987607670566939003312617745816078094735,8874382875706877830311960657026508969290082662731915199950324279800475201683 +299697172143641917566889608257780467384934077958128518690360805667539864950420,8702070228699144631140925089885492819072907992531772224458410703022324971560 +301967605265942235124214529532460622440880548245690098377408993589263651806105,8533103352178741979338410836757093105256375792397040329065630149508413086135 +304238038388242552681539450807140777496827018533251678064457181510987438661790,8367417281789609639196736794874998402544481231388500060346139012236641543825 +306508471510542870238864372081820932552773488820813257751505369432711225517475,8204948314579472931243763439936896182045474760835882712220942160049717189792 +308778904632843187796189293356501087608719959108374837438553557354435012373160,8045633984507342433459354572450622071501444572221358150888492135726910593613 +311049337755143505353514214631181242664666429395936417125601745276158799228845,7889413038426581123905040544325858121069927256074308557819634343914244175953 +313319770877443822910839135905861397720612899683497996812649933197882586084530,7736225412534304938490539495998345262722685569683811485718517851478118074806 +315590203999744140468164057180541552776559369971059576499698121119606372940215,7586012209278062013393244296606783131019725342345569324815264018948034488407 +317860637122044458025488978455221707832505840258621156186746309041330159795900,7438715674710911696077991529315597910182131547815478256768516102178053147428 +320131070244344775582813899729901862888452310546182735873794496963053946651585,7294279176286196809531497726711149751773109079006438039328871808860505208647 +322401503366645093140138821004582017944398780833744315560842684884777733507270,7152647181083471707513356405012353952405611456310792512957976292047901188617 +324671936488945410697463742279262173000345251121305895247890872806501520362955,7013765234457214429330978163948031181884804665874684563234080173204818792192 +326942369611245728254788663553942328056291721408867474934939060728225307218640,6877579939100113814604817973991912882261222190269087624747098477473070920910 +329212802733546045812113584828622483112238191696429054621987248649949094074325,6744038934512881834200618407209402738374726406854013386327229734819886355209 +331483235855846363369438506103302638168184661983990634309035436571672880930010,6613090876872697694251640706911864470257281520044099539344107417605448847522 +333753668978146680926763427377982793224131132271552213996083624493396667785695,6484685419292543536070441670407899002441885350144223913319492393155843996609 +336024102100446998484088348652662948280077602559113793683131812415120454641380,6358773192463841844684321602472961808036370534710746466420213566001948927453 +338294535222747316041413269927343103336024072846675373370180000336844241497065,6235305785674952050504565665502249112334426989789636398933745643420892537805 +340564968345047633598738191202023258391970543134236953057228188258568028352750,6114235728198228318918503273647009044057809740115762935228605445446011541536 +342835401467347951156063112476703413447917013421798532744276376180291815208435,5995516471038482226936505302234614253048545365172641788639745380038847011850 +345105834589648268713388033751383568503863483709360112431324564102015602064120,5879102369035832978915788636227029754149990028304128445154065521569679896299 +347376267711948586270712955026063723559809953996921692118372752023739388919805,5764948663316064068243885471976803898564123312018636117461200936317441104963 +349646700834248903828037876300743878615756424284483271805420939945463175775490,5653011464081738901084106683312765416762298565331902697873676865978153014007 +351917133956549221385362797575424033671702894572044851492469127867186962631175,5543247733737458913233334532284737157076797625887278020789776292123991283042 +354187567078849538942687718850104188727649364859606431179517315788910749486860,5435615270342776182191625059155814516167449877265043810529451526313401440000 +356458000201149856500012640124784343783595835147168010866565503710634536342545,5330072691386398513087911834712869898427723411257226595273064182550426763859 +358728433323450174057337561399464498839542305434729590553613691632358323198230,5226579417875448507582021006206716342354483979921442218144570774799799153756 +360998866445750491614662482674144653895488775722291170240661879554082110053915,5125095658733659256765209168041122238133229257032719961413509211200048248333 +363269299568050809171987403948824808951435246009852749927710067475805896909600,5025582395502508078982293698284693835284469532255851267477746214208169030829 +365539732690351126729312325223504964007381716297414329614758255397529683765285,4928001367339406197066635979466804208185522234029567523625554767402211661565 +367810165812651444286637246498185119063328186584975909301806443319253470620970,4832315056307176461496499130904489365080602372384889128573871476885084197963 +370080598934951761843962167772865274119274656872537488988854631240977257476655,4738486672949163220359850565587517062963871431792713253071282139856533845449 +372351032057252079401287089047545429175221127160099068675902819162701044332340,4646480142144428256814095536419820031461458638508982355406532908762559366752 +374621465179552396958612010322225584231167597447660648362951007084424831188025,4556260089237594402171008726677813775125098076724227743627974892272588327070 +376891898301852714515936931596905739287114067735222228049999195006148618043710,4467791826438004029228927006814200361630588836617618519025510750743109199997 +379162331424153032073261852871585894343060538022783807737047382927872404899395,4381041339482963176613798998129770586400722046177381492207741626501677387270 +381432764546453349630586774146266049399007008310345387424095570849596191755080,4295975274559943590489358236239541053798654812625189402565013609912762502063 +383703197668753667187911695420946204454953478597906967111143758771319978610765,4212560925482714534092886286689429135772883215331118745250144375204860994258 +385973630791053984745236616695626359510899948885468546798191946693043765466450,4130766221116473846427146968171682243610648632762217464220432443306744076356 +388244063913354302302561537970306514566846419173030126485240134614767552322135,4050559713047143466628204822445172093558799258185730849489440714923595198306 +390514497035654619859886459244986669622792889460591706172288322536491339177820,3971910563490088516841239430057423861561699540314803552309386818215754652836 +392784930157954937417211380519666824678739359748153285859336510458215126033505,3894788533433611089965680791375046317061917745510095607652825551910399528715 +395055363280255254974536301794346979734685830035714865546384698379938912889190,3819163971012660154769745087149569914465567827492977553371176365210754983049 +397325796402555572531861223069027134790632300323276445233432886301662699744875,3745007800108287504328254434609249402710340257581916107575424870725436120735 +399596229524855890089186144343707289846578770610838024920481074223386486600560,3672291509168466468538116483953888412415082359790291319830667248103068617726 +401866662647156207646511065618387444902525240898399604607529262145110273456245,3600987140245975220983870041875004895679551495743211205866825798183240723922 +404137095769456525203835986893067599958471711185961184294577450066834060311930,3531067278249129967384164433549615728055232151532910541204821495878913836970 +406407528891756842761160908167747755014418181473522763981625637988557847167615,3462505040401235139336450269559039606157745830970264242579700439549733102016 +408677962014057160318485829442427910070364651761084343668673825910281634023300,3395274065904697964555996096535291493010779102468849709076001181212499029926 +410948395136357477875810750717108065126311122048645923355722013832005420878985,3329348505805833474130146144622500207015802447060544079287034222519730000801 +413218828258657795433135671991788220182257592336207503042770201753729207734670,3264703013056463168733957305768762048671220120100675556528510459350361442934 +415489261380958112990460593266468375238204062623769082729818389675452994590355,3201312732768486228946010278262122858837369338972372870253840600423809756146 +417759694503258430547785514541148530294150532911330662416866577597176781446040,3139153292657676348854251985374092135837494969951169782173776159644176534423 +420030127625558748105110435815828685350097003198892242103914765518900568301725,3078200793673030025577310098607138197203259951148621910059374341071023253667 +422300560747859065662435357090508840406043473486453821790962953440624355157410,3018431800808063478119054352864365216599069977484266467250325895140520117178 +424570993870159383219760278365188995461989943774015401478011141362348142013095,2959823334090525324552359078463176696893036195521598690559604864862321028159 +426841426992459700777085199639869150517936414061576981165059329284071928868780,2902352859747060743788555836574429934024784962979281619588506007014730754443 +429111860114760018334410120914549305573882884349138560852107517205795715724465,2845998281539430113506217335511024116647561786738955796723957128032460028562 +431382293237060335891735042189229460629829354636700140539155705127519502580150,2790737932268951075048841664512779579965827455433050874470612581492493796612 +433652726359360653449059963463909615685775824924261720226203893049243289435835,2736550565445897654615705160581380392035754504074875922703396122219838983601 +435923159481660971006384884738589770741722295211823299913252080970967076291520,2683415347120653492731207292836793547250299699949146040965909097366506826314 +438193592603961288563709806013269925797668765499384879600300268892690863147205,2631311847873478425170175781779819578108906286445566029098739049466961949804 +440464025726261606121034727287950080853615235786946459287348456814414650002890,2580220034959808642151093783793953402129918191024990104539947286476194870361 +442734458848561923678359648562630235909561706074508038974396644736138436858575,2530120264608070452133030819123365918858694576649021314235932359705643943273 +445004891970862241235684569837310390965508176362069618661444832657862223714260,2480993274467046314956915988152178555256121842686531405628524104350927660746 +447275325093162558793009491111990546021454646649631198348493020579586010569945,2432820176199889308902969867700028980919093407680036321083074765251991144298 +449545758215462876350334412386670701077401116937192778035541208501309797425630,2385582448221938579601135652712703469128873722647430092259396421200608174744 +451816191337763193907659333661350856133347587224754357722589396423033584281315,2339261928579543607308487238103279986560541266662742536344201858542715699027 +454086624460063511464984254936031011189294057512315937409637584344757371137000,2293840807967159344114184788286120867801944082584440628149280631165005320951 +456357057582363829022309176210711166245240527799877517096685772266481157992685,2249301622880027434993188844156208157845130306302793141117411709623435670173 +458627490704664146579634097485391321301186998087439096783733960188204944848370,2205627248899810866744487578412286757829514684708503434368069205255340039839 +460897923826964464136959018760071476357133468375000676470782148109928731704055,2162800894110600506761016035372877280458113909309651595222790899580498073682 +463168356949264781694283940034751631413079938662562256157830336031652518559740,2120806092642762118940557002260420725877403403643132375546681834433562628493 +465438790071565099251608861309431786469026408950123835844878523953376305415425,2079626698342141596131901285086838588831365589656553686857278748333033108659 +467709223193865416808933782584111941524972879237685415531926711875100092271110,2039246878562194346216395910444043784690021169116503952080024996424232086889 +469979656316165734366258703858792096580919349525246995218974899796823879126795,1999651108076652030782767922491430088269301331012688651267426380085596201366 +472250089438466051923583625133472251636865819812808574906023087718547665982480,1960824163110386199534010054524334089541753293394021687030939529972846447262 +474520522560766369480908546408152406692812290100370154593071275640271452838165,1922751115486173807887555445320207063113604718628558999245364537712059659787 +476790955683066687038233467682832561748758760387931734280119463561995239693850,1885417326885114167166377133451693487795698974827428621915772121522296322640 +479061388805367004595558388957512716804705230675493313967167651483719026549535,1848808443218490573462190057395600374688639714455162176619470154537224426642 +481331821927667322152883310232192871860651700963054893654215839405442813405220,1812910389108912709483102199711379114048329569523931425832014763952606023142 +483602255049967639710208231506873026916598171250616473341264027327166600260905,1777709362478617929951137999560857523114698493464640463314567998578763375930 +485872688172267957267533152781553181972544641538178053028312215248890387116590,1743191829242850741544443083382012278950030439838258806090307410195511152367 +488143121294568274824858074056233337028491111825739632715360403170614173972275,1709344518106280188825408838548340945706907890570414138312511052040629403114 +490413554416868592382182995330913492084437582113301212402408591092337960827960,1676154415460454473592585178001481888630499860343530369736761941087841137938 +492683987539168909939507916605593647140384052400862792089456779014061747683645,1643608760380330981872631688029464454202113613160652114812004614315882448607 +494954420661469227496832837880273802196330522688424371776504966935785534539330,1611695039717957985264493988118541627646396847164138227584506579980006189593 +497224853783769545054157759154953957252276992975985951463553154857509321395015,1580400983291421636207279946257561145576531467125488184028701658324803392105 +499495286906069862611482680429634112308223463263547531150601342779233108250700,1549714559167208504327370397252359435900676480118217197526808984667322295656 +501765720028370180168807601704314267364169933551109110837649530700956895106385,1519623969034169817411698521182954716530148741935550434876916238707975489825 +504036153150670497726132522978994422420116403838670690524697718622680681962070,1490117643667308789561999136522296289524839311469606144758176235295035574077 +506306586272970815283457444253674577476062874126232270211745906544404468817755,1461184238479646954250162028027864509672389242493414237027164373310873876617 +508577019395271132840782365528354732532009344413793849898794094466128255673440,1432812629160459284595696582392048709701342884089101780789506016757983545698 +510847452517571450398107286803034887587955814701355429585842282387852042529125,1404991907398201090242984454401886460001256486743771644647644675643019397120 +513117885639871767955432208077715042643902284988917009272890470309575829384810,1377711376686482242495906258989351428318340736703325118283502743772525420186 +515388318762172085512757129352395197699848755276478588959938658231299616240495,1350960548211476209390117246928289328516166528957389393408566548846213309144 +517658751884472403070082050627075352755795225564040168646986846153023403096180,1324729136819182692425165292411394327407511934209655077877674460464300121300 +519929185006772720627406971901755507811741695851601748334035034074747189951865,1299007057060993358777871916475898081725576133192311731321945268374304875079 +522199618129073038184731893176435662867688166139163328021083221996470976807550,1273784419316040268779271406014391437821438711132700913654395176336120357812 +524470051251373355742056814451115817923634636426724907708131409918194763663235,1249051525988836119835059106151604655038913776255529646900786453845629450261 +526740484373673673299381735725795972979581106714286487395179597839918550518920,1224798867780744376154319639656429438292590596449478554800662259883398133550 +529010917495973990856706657000476128035527577001848067082227785761642337374605,1201017120033845739753282342628997286268151802300216872136210819143441303664 +531281350618274308414031578275156283091474047289409646769275973683366124230290,1177697139145795253133868286972489045105718361046528878527448066379668652133 +533551783740574625971356499549836438147420517576971226456324161605089911085975,1154829959054291618502821225483149900650534431243083949245642604820923646588 +535822216862874943528681420824516593203366987864532806143372349526813697941660,1132406787789807082890425327211328755183700827007270235992079331829362643852 +538092649985175261086006342099196748259313458152094385830420537448537484797345,1110419004095252483338613492946986193747814242216914544087253927761374702549 +540363083107475578643331263373876903315259928439655965517468725370261271653030,1088858154111277781547261772857694251337802353360681665028106984738120501199 +542633516229775896200656184648557058371206398727217545204516913291985058508715,1067715948125933652889320598100629627595490376276215626206049496855639908739 +544903949352076213757981105923237213427152869014779124891565101213708845364400,1046984257387444440232701363407888596891997329416358164537461237895052190493 +547174382474376531315306027197917368483099339302340704578613289135432632220085,1026655110978867048053673500561104502292891906760695382551282292885769647385 +549444815596676848872630948472597523539045809589902284265661477057156419075770,1006720692753434146222353671415953866113533147281398201361542821926894368710 +551715248718977166429955869747277678594992279877463863952709664978880205931455,987173338329403384733958131783829533009147622988398599380784122106977308530 +553985681841277483987280791021957833650938750165025443639757852900603992787140,968005532143257199520483988560220733582298517120243540446994347402239110174 +556256114963577801544605712296637988706885220452587023326806040822327779642825,949209904560120224102845604039392059367322323910424009332173176480678795959 +558526548085878119101930633571318143762831690740148603013854228744051566498510,930779229040283320858879764591061717606873826779909083197312274038703255036 +560796981208178436659255554845998298818778161027710182700902416665775353354195,912706419360744817546225148870963828076628869100719699856881194145713586169 +563067414330478754216580476120678453874724631315271762387950604587499140209880,894984526890700687724824577161411173596658532863246109848772040565011872478 +565337847452779071773905397395358608930671101602833342074998792509222927065565,877606737919936156004596577686776039865420267809390448859339117903023609116 +567608280575079389331230318670038763986617571890394921762046980430946713921250,860566371039091548574664590528726362251021703804112434559419129682978794632 +569878713697379706888555239944718919042564042177956501449095168352670500776935,843856874570795154071557033366442926236979708804975971538286570121216914411 +572149146819680024445880161219399074098510512465518081136143356274394287632620,827471824050675417183296315424741971779066957250062452852260880325027656529 +574419579941980342003205082494079229154456982753079660823191544196118074488305,811404919757283964983682303379036253598800697102332643556476037720459831748 +576690013064280659560530003768759384210403453040641240510239732117841861343990,795649984289979771219745127738174910086802387263030261900019674061458963150 +578960446186580977117854925043439539266349923328202820197287920039565648199675,780200960193843203865524721501305631184795994974723658032277935470179306730 diff --git a/chain/types/testdata/TestLambdaFunction/10-100.golden b/chain/types/testdata/TestLambdaFunction/10-100.golden new file mode 100644 index 0000000000..adb7eaf5e9 --- /dev/null +++ b/chain/types/testdata/TestLambdaFunction/10-100.golden @@ -0,0 +1 @@ +57896044618658097711785492504343953926634992332820282019728792003956564819968 \ No newline at end of file diff --git a/chain/types/testdata/TestLambdaFunction/1024-2048.golden b/chain/types/testdata/TestLambdaFunction/1024-2048.golden new file mode 100644 index 0000000000..d449e4eaba --- /dev/null +++ b/chain/types/testdata/TestLambdaFunction/1024-2048.golden @@ -0,0 +1 @@ +289480223093290488558927462521719769633174961664101410098643960019782824099840 \ No newline at end of file diff --git a/chain/types/testdata/TestLambdaFunction/2000000000000000-100000000000000000.golden b/chain/types/testdata/TestLambdaFunction/2000000000000000-100000000000000000.golden new file mode 100644 index 0000000000..76d1403ac2 --- /dev/null +++ b/chain/types/testdata/TestLambdaFunction/2000000000000000-100000000000000000.golden @@ -0,0 +1 @@ +11579208923731619542357098500868790785326998466564056403945758400791312963993 \ No newline at end of file diff --git a/chain/types/testdata/TestPoissonFunction/lam-10-10.golden b/chain/types/testdata/TestPoissonFunction/lam-10-10.golden new file mode 100644 index 0000000000..fbe59115fa --- /dev/null +++ b/chain/types/testdata/TestPoissonFunction/lam-10-10.golden @@ -0,0 +1,17 @@ +icdf +1125278653883954157340515998824199281259686237023612910954531537010133365568 +5485581780123676224984074899749002236148166431650497590243915223971292577 +17842170241691453912141677461647358103546946338181118738604570718548080 +43538699106868068808561503680708109912117284430088557923220935824303 +85008817354919776986513548953593326094752560579206896166859206326 +138328508214407784218646352510285887677303021571444942144212932 +192946940473264032619492808002293590266469557064324916486706 +235498963868775663540157747991701194152938740691242898919 +255504995002156513848360474242833468958493714151012216 +249505772801580009049072856702435230216536441494110 +232834101038081471620316286291642591265760137159 +11533551765583311484083562200606025547302501012 +11353456917542541496993529059255898133794641608 +11353321629946357024346977051186975261639061786 +11353321535577219060847642123725989684858819334 +11353321535515780819985988910882590605707269697 diff --git a/chain/types/testdata/TestPoissonFunction/lam-1036915-20.golden b/chain/types/testdata/TestPoissonFunction/lam-1036915-20.golden new file mode 100644 index 0000000000..45444615d6 --- /dev/null +++ b/chain/types/testdata/TestPoissonFunction/lam-1036915-20.golden @@ -0,0 +1,17 @@ +icdf +72718197862321603787957847055188249408647877796280116987586082825356498974798 +30123322455004902866096392147720313525979066051167804713805891738863284666878 +9062729215708086547397523150443475826195010851218953471088727298493148732956 +2120601657722952965249404258310617497861606438105371150448777320082300909521 +404370264674629622846679825118378024155401061236248117877372450081489268106 +64941157977031699837280219244596630364570458903895153606060064374226923144 +8998760514291795062091202215054973561658841304177095664084807386711484044 +1095864305518189121413406860322570887693509822868614985675874891701983877 +118988091690998292615838041961723734187855286032350465668217096980526413 +11653361409102593830837021393444274321721937984503223867724441309766994 +1039253147016500070761515827557061937775360855994320103804816785188376 +85064880905559492020902336338153555957806293407638915883403930221828 +6433469833589351070633969345898155559842007456615136652210720692299 +452164666340411064711833496915674079929092772106312520794348036629 +29679788379529243880483477334855509673275091060271619731000625321 +1827354397264548824373139406487609602015834650190678153972930556 diff --git a/chain/types/testdata/TestPoissonFunction/lam-1706-10.golden b/chain/types/testdata/TestPoissonFunction/lam-1706-10.golden new file mode 100644 index 0000000000..fb6689a486 --- /dev/null +++ b/chain/types/testdata/TestPoissonFunction/lam-1706-10.golden @@ -0,0 +1,17 @@ +icdf +93907545465879218275260347624273708225148723352890415890955745471328115138024 +57447553596668785643406883388130520172829512611140657354486862128150346836988 +27076095525930017054568011324233899656590951319429188573619716140132147265911 +10209654292635635800479757502291310268341281539592025246744927385067352842651 +3184715634432458451975226003210729824895496226017269232182332263939291493510 +843984120585852874524302031056145794325474791455055607017530061469667926785 +194034907919461416983404196340045475941285897027461784665454449911533518447 +39345544525367691179167072173518251727638261160626536209449847049064587000 +7131182470884793691126479665205819536661348710819293305892247868965466268 +1167890189531948301087715470416213490892402026859749426392544722128541359 +174396377814374645286335419995210764907848995332895729280582459579342738 +23925812935985027317838050852967276757134553590636105055350959232313899 +3035286920153916620063269622769735189335169019323041991528942663951986 +358060554242868329017312833503133182524340437692927389149107908421231 +39467628723598770945019147503633808666969235107758896427288845018926 +4082242594961149456000070139366495398696105445630156285138889148853 diff --git a/chain/types/testdata/TestPoissonFunction/lam-2-0.golden b/chain/types/testdata/TestPoissonFunction/lam-2-0.golden new file mode 100644 index 0000000000..c64994bd93 --- /dev/null +++ b/chain/types/testdata/TestPoissonFunction/lam-2-0.golden @@ -0,0 +1,17 @@ +icdf +100121334043824876020967110392587568107053060743383522309741056272383359786578 +68779823656842237215759361160386888614619212898869438850308000801323820079862 +37438313269859598410551611928186209122185365054355355390874945330264280373146 +16543973011871172540413112440052422793896133158012633084586241682891253902002 +6096802882876959605343862695985529629751517209841271931441889859204740666430 +1917934831279274431316162798358772364093670830572727470184149129730135372202 +524978814080046039973596165816519942207722037483212649764902219905266940794 +126991380594552213875719985090162107383165239457636986787974531383875960392 +27494522223178757351250939908572648677026039951243071043742609253528215292 +5384109251762433679146707645997213408995106727599978656135515446784271938 +962026657479168944725861193482126355388920082871360178614096685435483268 +158011640336757174831161838479383254733249783829793182701111456099339874 +24009137479688546515378612645592737957304733989532016715613917876649310 +3393367809370296005258116363471119991774726321799529640921988919312302 +448257856467688789526616894596603139556153797837745773108856211121302 +55576529414007827429083632080000892593677461309507924067105183362502 diff --git a/chain/types/testdata/TestPoissonFunction/lam-209714-20.golden b/chain/types/testdata/TestPoissonFunction/lam-209714-20.golden new file mode 100644 index 0000000000..3a5a7bd466 --- /dev/null +++ b/chain/types/testdata/TestPoissonFunction/lam-209714-20.golden @@ -0,0 +1,17 @@ +icdf +20989436322611254574979389012727393136091537312055593688180077279147576363096 +2029014232696520721523332453453803636238058967796600089005757967894658844577 +132982872945592560215194824292206599698851338836977427578620974467337246296 +6581505574095040906286115477587166321018484661524779791358182693980706360 +261473369241451189291715224208035992983406808190620756138506410631265448 +8673527587881831627652027122245179992541421812500366598395022980519170 +246914417172755020716947338861248744263385116558896234139925344965714 +6155418508705151241339695503211918565434455355693098789916851059631 +136477982954924943101944815709613669983383501630000081908122878386 +2724514397229876659600187515561464490237868059330199615762951760 +49460332945698577716770256622916953121860884014393828193908634 +823264627479642334265449493920662550930201158945634649498769 +12651460568281449375957051928671501418597070452648092732548 +180560129118157986659345179422379755776654969450793746138 +2405427973892505908363489341734991530618943133521671600 +30045550760659097055494870911555042207154242485930695 diff --git a/chain/types/testdata/TestPoissonFunction/lam-5-0.golden b/chain/types/testdata/TestPoissonFunction/lam-5-0.golden new file mode 100644 index 0000000000..e7df148c9c --- /dev/null +++ b/chain/types/testdata/TestPoissonFunction/lam-5-0.golden @@ -0,0 +1,17 @@ +icdf +115011888277122352219705460287186602222085188670665840381425306072442950421456 +111110883476153136200377836679680074066161208695792222091263916395092054329056 +101358371473730096152058777660913753676351258758608176365860442201714814098056 +85104184803025029404860345962969886360001342196634766823521318546086080379726 +64786451464643695970862306340540052214563946494168004895597413976550163231816 +44468718126262362536864266718110218069126550791701242967673509407014246083906 +27537273677611251341865900366085356281262054372978941361070255599067648460651 +15443384785717600488295638686067597861358842645320154499210788593391507301186 +7884704228284068704814225136056498848919335315533412710548621714843919076521 +3685437251932106602880106497161443842008497910096333939069640115650814507266 +1585803763756125551913047177713916338553079207377794553330149316054262222641 +631424905494315983291656577965040200618797978869367559812198952601283911451 +233767047885228663032743828069675143146180800324189645846386301162542948456 +80821718035579693702392770417611659502866500883736602013381435224565655001 +26198385946419347512981678399017558201682822512146229215879697389573764486 +7990608583365898783177981059486191101288263054949438283379118111243134316 diff --git a/chain/types/testdata/TestPoissonFunction/lam-5242879-20.golden b/chain/types/testdata/TestPoissonFunction/lam-5242879-20.golden new file mode 100644 index 0000000000..367cf4a6d3 --- /dev/null +++ b/chain/types/testdata/TestPoissonFunction/lam-5242879-20.golden @@ -0,0 +1,17 @@ +icdf +115011887533064380050215202002871794783671664388541274939039184893270600703151 +111110879755863630144777547269452207577572562543679248972859798819416242535921 +101358362173007217989878395557465593373392010546833825352856759707561945139525 +85104169301821710755220628061805234978705652326202881500299286939503312327242 +64786432088141395502693562453332343133008530920262028792733819517798429528997 +44468698749761909885846743680008378684637277300179598543979674797636862943384 +27537257530529080605729671834720742022613060678716434560927439906969908575619 +15443373252088578337713549627194971124753642243467082552611819728291522561946 +7884697019766617162458477655388623015603913245952633503615157778326861227793 +3685433247200570820185174890022164698361097802621279879954268046011715772231 +1585801761390548420193995297013958176769177427873274589439743405082427147382 +631423995328231141553650878972791975288890578033071631113620389859816342901 +233766668649395912353875000216328335294367462954196928187468994385755448892 +80821572175657684536655650469711580587115741420816601432036447172153463116 +26198333853594769407667441209847842642730676168975225661522405972966431948 +7990591219092428810606628986022697269060757693982546042792694706871429282 diff --git a/chain/validation/applier.go b/chain/validation/applier.go index 6c16291042..153c8ca717 100644 --- a/chain/validation/applier.go +++ b/chain/validation/applier.go @@ -2,6 +2,7 @@ package validation import ( "context" + "golang.org/x/xerrors" "github.com/filecoin-project/specs-actors/actors/abi" @@ -72,8 +73,8 @@ func (a *Applier) ApplyTipSetMessages(epoch abi.ChainEpoch, blocks []vtypes.Bloc var bms []stmgr.BlockMessages for _, b := range blocks { bm := stmgr.BlockMessages{ - Miner: b.Miner, - TicketCount: 1, + Miner: b.Miner, + WinCount: 1, } for _, m := range b.BLSMessages { diff --git a/cmd/lotus/debug_advance.go b/cmd/lotus/debug_advance.go index 2782ea0741..2607f0c999 100644 --- a/cmd/lotus/debug_advance.go +++ b/cmd/lotus/debug_advance.go @@ -3,6 +3,9 @@ package main import ( + "encoding/binary" + "time" + "github.com/filecoin-project/go-address" lapi "github.com/filecoin-project/lotus/api" "github.com/filecoin-project/lotus/build" @@ -68,11 +71,21 @@ func init() { } // TODO: beacon + ep := &types.ElectionProof{} + ep.WinCount = ep.ComputeWinCount(types.NewInt(1), types.NewInt(1)) + for ep.WinCount == 0 { + fakeVrf := make([]byte, 8) + unixNow := uint64(time.Now().UnixNano()) + binary.LittleEndian.PutUint64(fakeVrf, unixNow) + + ep.VRFProof = fakeVrf + ep.WinCount = ep.ComputeWinCount(types.NewInt(1), types.NewInt(1)) + } uts := head.MinTimestamp() + uint64(build.BlockDelay) nheight := head.Height() + 1 blk, err := api.MinerCreateBlock(ctx, &lapi.BlockTemplate{ - addr, head.Key(), ticket, &types.ElectionProof{}, nil, msgs, nheight, uts, gen.ValidWpostForTesting, + addr, head.Key(), ticket, ep, nil, msgs, nheight, uts, gen.ValidWpostForTesting, }) if err != nil { return xerrors.Errorf("creating block: %w", err) diff --git a/go.mod b/go.mod index 655f402c92..146e01b2a9 100644 --- a/go.mod +++ b/go.mod @@ -111,6 +111,7 @@ require ( github.com/whyrusleeping/cbor-gen v0.0.0-20200504204219-64967432584d github.com/whyrusleeping/multiaddr-filter v0.0.0-20160516205228-e903e4adabd7 github.com/whyrusleeping/pubsub v0.0.0-20131020042734-02de8aa2db3d + github.com/xorcare/golden v0.6.1-0.20191112154924-b87f686d7542 go.opencensus.io v0.22.3 go.uber.org/dig v1.8.0 // indirect go.uber.org/fx v1.9.0 diff --git a/go.sum b/go.sum index 113c73c535..c8199601a8 100644 --- a/go.sum +++ b/go.sum @@ -1373,6 +1373,8 @@ github.com/whyrusleeping/timecache v0.0.0-20160911033111-cfcb2f1abfee/go.mod h1: github.com/whyrusleeping/yamux v1.1.5/go.mod h1:E8LnQQ8HKx5KD29HZFUwM1PxCOdPRzGwur1mcYhXcD8= github.com/x-cray/logrus-prefixed-formatter v0.5.2/go.mod h1:2duySbKsL6M18s5GU7VPsoEPHyzalCE06qoARUCeBBE= github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU= +github.com/xorcare/golden v0.6.1-0.20191112154924-b87f686d7542 h1:oWgZJmC1DorFZDpfMfWg7xk29yEOZiXmo/wZl+utTI8= +github.com/xorcare/golden v0.6.1-0.20191112154924-b87f686d7542/go.mod h1:7T39/ZMvaSEZlBPoYfVFmsBLmUl3uz9IuzWj/U6FtvQ= github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q= github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= go.dedis.ch/fixbuf v1.0.3 h1:hGcV9Cd/znUxlusJ64eAlExS+5cJDIyTyEG+otu5wQs=