-
-
Notifications
You must be signed in to change notification settings - Fork 5
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: add previous period hash to proofs and roots if present #166
Conversation
lib/period.spec.js
Outdated
block = new Block(i).addTx(Tx.deposit(i, value, ADDR, color)); | ||
blocks.push(block); | ||
} else { | ||
blocks.push(new Block(i)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what's the purpose to add empty blocks? 🤔
lib/period.spec.js
Outdated
const period = new Period("'0x8b04de057fe524a3118eb7c8e14a2e55323c67fd7b6080583d1047b700b2d674'", blocks); | ||
period.setValidatorData(slotId, ADDR); | ||
const proof = period.proof(transfer); | ||
expect(proof).to.eql([ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this test is not checking that prevHash is included in the proof, no?
How about that:
- period = new Period(prevHash, blocks)
- const proof1 = period.proof(transfer)
- period = new Period(someOtherPrevHash, blocks)
- const proof2 = period.proof(transfer)
- expect(proof1).not.equal(proof2)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or better check for prevHash inclusion?
lib/period.spec.js
Outdated
block = new Block(31).addTx(transfer); | ||
blocks.push(block); | ||
|
||
const period = new Period("'0x8b04de057fe524a3118eb7c8e14a2e55323c67fd7b6080583d1047b700b2d674'", blocks); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
extra quotes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
implementation looks good 👍
Left some questions about tests
…nd fix backwards compatibility issue.
Suggesting the following change for this PR: #167 |
lib/period.spec.js
Outdated
periodAfter.usePrevPeriod(); | ||
|
||
const proof = periodAfter.prevPeriodProof(); | ||
expect(Period.verifyPrevPeriodProof(proof)).to.eql(periodAfter.periodRoot()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this isn't really checking that period.periodRoot()
was used in proof
, no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See below.
lib/period.js
Outdated
} | ||
|
||
// returns current period | ||
static verifyPrevPeriodProof(proof) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the name is misleading IMO. It is not verifying anything, but rather calculating period root for the proof
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes this is because in solidity the verify method just computes the edges if the walk and verifies they reference one another. See new commit for clarification.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
left couple of questions
+
suggesting to add this change to make API better: #167
* chore: rework Period object constructor 1. Set `usePrev` by default. BREAKING change 2. Accept optional third arguments of `PeriodOptions` type: allows to set validator data and set `usePrev` to false for legacy proofs. * docs: add period hashing schema
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
Resolves: #165