Skip to content

Commit

Permalink
chore: add test vectors dos protection validator (#1711)
Browse files Browse the repository at this point in the history
  • Loading branch information
alrevuelta authored May 4, 2023
1 parent 3e14686 commit eaa162e
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
2 changes: 1 addition & 1 deletion apps/wakunode2/wakunode2_validator_signed.nim
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import

declarePublicCounter waku_msg_validator_signed_outcome, "number of messages for each validation outcome", ["result"]

# Application level message hash
# Application level message hash
proc msgHash*(pubSubTopic: string, msg: WakuMessage): array[32, byte] =
var ctx: sha256
ctx.init()
Expand Down
32 changes: 32 additions & 0 deletions tests/wakunode2/test_validators.nim
Original file line number Diff line number Diff line change
Expand Up @@ -263,3 +263,35 @@ suite "WakuNode2 - Validators":

# Stop all nodes
await allFutures(nodes.mapIt(it.stop()))

asyncTest "Tests vectors":
# keys
let privateKey = "5526a8990317c9b7b58d07843d270f9cd1d9aaee129294c1c478abf7261dd9e6"
let publicKey = "049c5fac802da41e07e6cdf51c3b9a6351ad5e65921527f2df5b7d59fd9b56ab02bab736cdcfc37f25095e78127500da371947217a8cd5186ab890ea866211c3f6"

# message
let contentTopic = "content-topic"
let pubsubTopic = "pubsub-topic"
let payload = "1A12E077D0E89F9CAC11FBBB6A676C86120B5AD3E248B1F180E98F15EE43D2DFCF62F00C92737B2FF6F59B3ABA02773314B991C41DC19ADB0AD8C17C8E26757B"

# expected values
let expectedMsgAppHash = "0914369D6D0C13783A8E86409FE42C68D8E8296456B9A9468C845006BCE5B9B2"
let expectedSignature = "B139487797A242291E0DD3F689777E559FB749D565D55FF202C18E24F21312A555043437B4F808BB0D21D542D703873DC712D76A3BAF1C5C8FF754210D894AD4"

let secretKey = SkSecretKey.fromHex(privateKey).expect("valid key")

check:
secretKey.toPublicKey().toHex() == publicKey
secretKey.toHex() == privateKey

var msg = WakuMessage(
payload: payload.fromHex(), contentTopic: contentTopic,
version: 2, timestamp: now(), ephemeral: true)

let msgAppHash = pubsubTopic.msgHash(msg)
let signature = secretKey.sign(SkMessage(msgAppHash)).toRaw()

check:
msgAppHash.toHex() == expectedMsgAppHash
signature.toHex() == expectedSignature

0 comments on commit eaa162e

Please sign in to comment.