From 12f220524317d87d002caf4801357f640ac4f5f2 Mon Sep 17 00:00:00 2001 From: darosior Date: Mon, 2 Sep 2019 20:37:49 +0200 Subject: [PATCH] BOLT #3: Use space to indent in key derivation algorithms NIT but it rendered poorly when tabs where used (whereas spaces were previously used) --- 03-transactions.md | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/03-transactions.md b/03-transactions.md index 5f9105c7c..805e6983d 100644 --- a/03-transactions.md +++ b/03-transactions.md @@ -552,40 +552,40 @@ secret is stored: # a.k.a. count trailing 0s where_to_put_secret(I): - for B in 0 to 47: - if testbit(I) in B == 1: - return B + for B in 0 to 47: + if testbit(I) in B == 1: + return B # I = 0, this is the seed. - return 48 + return 48 A double-check, that all previous secrets derive correctly, is needed; if this check fails, the secrets were not generated from the same seed: insert_secret(secret, I): - B = where_to_put_secret(secret, I) + B = where_to_put_secret(secret, I) # This tracks the index of the secret in each bucket across the traversal. - for b in 0 to B: - if derive_secret(secret, B, known[b].index) != known[b].secret: - error The secret for I is incorrect - return + for b in 0 to B: + if derive_secret(secret, B, known[b].index) != known[b].secret: + error The secret for I is incorrect + return # Assuming this automatically extends known[] as required. - known[B].index = I - known[B].secret = secret + known[B].index = I + known[B].secret = secret Finally, if an unknown secret at index `I` needs be derived, it must be discovered which known secret can be used to derive it. The simplest method is iterating over all the known secrets, and testing if each can be used to derive the unknown secret: - derive_old_secret(I): - for b in 0 to len(secrets): - # Mask off the non-zero prefix of the index. - MASK = ~((1 << b) - 1) - if (I & MASK) == secrets[b].index: - return derive_secret(known, i, I) - error Index 'I' hasn't been received yet. + derive_old_secret(I): + for b in 0 to len(secrets): + # Mask off the non-zero prefix of the index. + MASK = ~((1 << b) - 1) + if (I & MASK) == secrets[b].index: + return derive_secret(known, i, I) + error Index 'I' hasn't been received yet. This looks complicated, but remember that the index in entry `b` has `b` trailing 0s; the mask and compare simply checks if the index