-
Notifications
You must be signed in to change notification settings - Fork 197
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
add verifyPow #315
base: master
Are you sure you want to change the base?
add verifyPow #315
Conversation
i did not change getPow as it's used in minePow, and also don't want this to break any current nip13 implementations. |
I don't understand this. This is the function you want: function verifyPow(event: Event, difficulty: number): boolean {
return getPow(event.id) >= difficulty;
} |
does this make sense. /** Verify POW difficulty for a NOSTR event. */
function verifiedPow(event: Event): number {
let count = getPow(event.id)
// Extract the target difficulty level from the tags
const nonceTag = event.tags.find(tag => tag[0] === 'nonce');
if (!nonceTag || nonceTag.length < 3) {
return 0 // Without specifying target difficulty, there is no PROOF of work
}
const targetDifficulty = parseInt(nonceTag[2], 10);
// The proof-of-work is the minimum of actual hash result and target
return Math.min(count, targetDifficulty)
} good explanation from nip13.md
|
Maybe add this function: /** Get the target difficulty from the nonce tag, or 0 if no tag exists. */
function getTargetDifficulty(event: Event): number This will simplify function verifyPow(event: Event, difficulty: number): boolean I can't imagine any case where you don't want to set a lower bound for the difficulty. Why verify POW at all if there's no lower bound? |
hmm not sure, i've chosen this implementation because i currently use it in a similar way to getPow for sorting too, and assume future PoW clients would use it for it's 'number' result. const eventsSortedByPow = [...events].sort((a, b) => verifyPow(b) - verifyPow(a)); i don't mind tho. we could leave this PR open until there are a couple more PoW implementations on nostr and see how ppl deal with it. function verifyPow(event: Event): number {
const hash = getEventHash(event)
const count = getPow(hash)
// Extract the target difficulty level from the tags
const nonceTag = event.tags.find(tag => tag[0] === 'nonce');
if (!nonceTag || nonceTag.length < 3) {
return 0 // Without specifying target difficulty, there is no PROOF of work
}
const targetDifficulty = parseInt(nonceTag[2], 10);
// The proof-of-work is the minimum of actual hash result and target
return Math.min(count, targetDifficulty)
} |
4d4b83e
to
bf0c4d4
Compare
think this may be worth adding.
for my app get-tao.app, we use PoW filtering and also PoW sorting.
technically the proof side depends on what the user was targeting in the first place.
it's a minor issue at the moment, but ive noticed some notes get onto my high PoW feed while actually targeting a lower difficulty, which indicates the work they've actually put in.
you can see the basic idea with the bottom test.