Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ph4): inclusion proofs #4059

Closed
wants to merge 17 commits into from
Closed

feat(ph4): inclusion proofs #4059

wants to merge 17 commits into from

Conversation

vladopajic
Copy link
Contributor

@vladopajic vladopajic commented May 10, 2023

Checklist

  • I have read the coding guide.
  • My change requires a documentation update, and I have done it.
  • I have added tests to cover my changes.
  • I have filled out the description and linked the related issues.

Description

This PR implements inclusion proofs for claim method of phase 4 redistribution smart contract.

Note: in code there is // TODO_PH4 which should be handled before PR is merged to master, please go through these markers in code and handle them accordingly.

Closes: #3800

@vladopajic vladopajic requested review from a team, mrekucci, istae, aloknerurkar, notanatol, acha-bill and nugaon and removed request for a team May 10, 2023 10:59
@vladopajic vladopajic mentioned this pull request May 10, 2023
4 tasks
@vladopajic vladopajic force-pushed the ph4-proof branch 2 times, most recently from 10f9644 to 0a492d4 Compare May 12, 2023 08:45
@vladopajic vladopajic closed this May 12, 2023
@vladopajic vladopajic reopened this May 12, 2023
@vladopajic vladopajic added the ready for review The PR is ready to be reviewed label May 12, 2023
Copy link
Contributor

@mrekucci mrekucci left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would also be good to include a meaningful description of all public structures/functions/methods/types...

pkg/storageincentives/proof.go Outdated Show resolved Hide resolved
pkg/storageincentives/proof.go Outdated Show resolved Hide resolved
pkg/storageincentives/proof.go Outdated Show resolved Hide resolved
pkg/storageincentives/proof.go Show resolved Hide resolved
@vladopajic vladopajic force-pushed the ph4-proof branch 3 times, most recently from 0bfbdff to d7c93a7 Compare May 17, 2023 11:17
@mrekucci mrekucci force-pushed the localstorev2.0 branch 2 times, most recently from e012d95 to 54d8bdf Compare May 17, 2023 14:29
pkg/storageincentives/redistribution/inclusion_proof.go Outdated Show resolved Hide resolved
pkg/storageincentives/proof.go Show resolved Hide resolved
pkg/storageincentives/proof.go Outdated Show resolved Hide resolved
pkg/soc/soc.go Outdated Show resolved Hide resolved
@vladopajic vladopajic force-pushed the ph4-proof branch 2 times, most recently from ffde79e to 94f2d3f Compare May 23, 2023 07:51
@vladopajic vladopajic closed this May 24, 2023
@vladopajic vladopajic reopened this May 24, 2023
@vladopajic vladopajic force-pushed the ph4-proof branch 4 times, most recently from dc4f540 to 03cf689 Compare June 20, 2023 15:04
@notanatol notanatol requested review from nugaon and removed request for notanatol August 2, 2023 10:50
@notanatol notanatol self-assigned this Aug 3, 2023
Copy link
Member

@zelig zelig left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this needs serious redesign.

Also note. The proofs do not seems to allow proving the virtual 0-s, so bmt package needs update and test short chunks with out of range segment proofs

if err != nil {
a.logger.Info("failed getting anchor after second reveal", "err", err)
} else {
sample.Anchor2 = anchor2
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

anchor 2 cannot be known at this point

return fmt.Errorf("sample not found")
}

proofs, err := makeInclusionProofs(sampleData.ReserveSampleItems, sampleData.Anchor1, sampleData.Anchor2)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here sampleData.Anchor2 cannot be taken as it was set in reveal
proof creation needds to be delayed to claim phase
only then the reveal anchor (for seed determmines tuth selection and winner selectoin

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the claim period is long and doing the computation of the proofs is fast compare to the witness filtering.
Nevertheless, the anchor should be available for the witness proofs after the first reveal on the SC API.


return true, nil
}

func (a *Agent) makeSample(ctx context.Context, storageRadius uint8) (SampleData, error) {
salt, err := a.contract.ReserveSalt(ctx)
anchor, err := a.contract.ReserveSalt(ctx)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is salt not good?

}

func (a *Agent) SampleWithProofs(
ctx context.Context,
anchor1 []byte,
anchor2 []byte,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

who sets this ad when?

return SampleWithProofs{}, fmt.Errorf("sample hash: %w", err)
}

proofs, err := makeInclusionProofs(rSample.Items, anchor1, anchor2)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

surely impossible to know here

for i := 0; i < workers; i++ {
g.Go(func() error {
wstat := SampleStats{}
hasher := bmt.NewTrHasher(anchor)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for each routine you can get a tr hasher and defer put back to pool.

hasher := bmt.NewTrHasher(anchor)

items := make([]SampleItem, len(chunks))
for i, ch := range chunks {
tr, err := transformedAddress(hasher, ch, swarm.ChunkTypeContentAddressed)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the sample should remember the chunk and the transformed address. no need to calculate it again.

}

// MakeSampleUsingChunks returns Sample constructed using supplied chunks.
func MakeSampleUsingChunks(chunks []swarm.Chunk, anchor []byte) (Sample, error) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is not needed the iterator should just create a SampleItem
which should be just

struct  {
  transformedAddress
  chunk
}

@@ -17,41 +16,62 @@ import (
"time"

"github.com/ethersphere/bee/pkg/bmt"
"github.com/ethersphere/bee/pkg/cac"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this file under storer and not under storage incentives

hasher, trHasher := bmtpool.Get(), bmt.NewTrHasher(anchor1)
defer bmtpool.Put(hasher)

anchor2Big := new(big.Int).SetBytes(anchor2)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so here you are using the wrong anchor

@nugaon nugaon mentioned this pull request Sep 19, 2023
6 tasks
@istae
Copy link
Member

istae commented Oct 4, 2023

closing as this is taken care of in #4373

@istae istae closed this Oct 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pull-request ready for review The PR is ready to be reviewed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Claim interface changes: creation of proofs
8 participants