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

[NayNay] Signing bug for validators #63

Merged
merged 5 commits into from
Jun 12, 2024
Merged

Conversation

rh0delta
Copy link
Contributor

@rh0delta rh0delta commented Jun 3, 2024

closes entropyxyz/sdk#367
close #77

package.json Show resolved Hide resolved
import { initializeEntropy } from "../../common/initializeEntropy"
import { debug, getSelectedAccount, print } from "../../common/utils"

let msg: string
let signingAttempts: number = 0
Copy link
Contributor

Choose a reason for hiding this comment

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

🔥 this is a global variable. The way you're using it means that this function will try fixing once, then it will not be reset to 0 after this signing... so all future buggy signings will be skipped.

This function feels like it's way too fancy, and also not really named what it is. I *\think* all that we need is for the original code to be the same but like this:

const sigOpts = {
  msg: msgParam,
  order: ['deviceKeyProxy', 'noop'],
}

const signature = await entropy.signWithAdaptersInOrder(sigOpt)
  .catch(err => {
    // HACK: sometimes order is reversed D:
    sigOpts.order.reverse()
    return entropy.signWithAdaptersInOrder(sigOpt)
  })

Copy link
Contributor

Choose a reason for hiding this comment

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

NOTE this code assumes signWithAdaptersInOrder DOES NOT MUTATE the input... that would need checking.
We should not write functions which mutate inputs though 💀

Copy link
Contributor

Choose a reason for hiding this comment

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

don't see any mutations, should be fine?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

🔥 this is a global variable. The way you're using it means that this function will try fixing once, then it will not be reset to 0 after this signing... so all future buggy signings will be skipped.

This function feels like it's way too fancy, and also not really named what it is. I *\think* all that we need is for the original code to be the same but like this:

const sigOpts = {

  msg: msgParam,

  order: ['deviceKeyProxy', 'noop'],

}



const signature = await entropy.signWithAdaptersInOrder(sigOpt)

  .catch(err => {

    // HACK: sometimes order is reversed D:

    sigOpts.order.reverse()

    return entropy.signWithAdaptersInOrder(sigOpt)

  })

We could do this way of catching the error, but we still need to keep track of the attempts made to signing and handle accordingly. I find the try..catch to be cleaner, thoughts?

Copy link
Contributor

@mixmix mixmix Jun 5, 2024

Choose a reason for hiding this comment

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

  • try / catch is the same as promise.catch 🤷 (don't mind)
  • your global variable is still a liability - if multiple people are calling this function your global variable becomes a race condition

You need to change this to not use it - either the way I suggested, or pass the attempts count as an argument

async function signWithAdaptersInOrder (entropy, signingData, attempts = 0) {
  if (attempts > 1) throw Error('NOPE')
  // ...

  const newSignData = { /* ... */ } // shuffle
  return signWithAdaptersInOrder(entropy, newSignData, attempts + 1)
}

- updated signing with adapters to retry the signing request if a specific error is hit as defined in this issue entropyxyz/sdk#367
@rh0delta rh0delta force-pushed the naynay/signing-validators-bug branch from cc81daa to ad43e99 Compare June 4, 2024 01:51
@rh0delta rh0delta requested a review from mixmix June 4, 2024 15:03
@rh0delta
Copy link
Contributor Author

rh0delta commented Jun 4, 2024

@mixmix ready for re-review

@mixmix
Copy link
Contributor

mixmix commented Jun 6, 2024

@rh0delta that 🔥 is still an issue. I've added more context why it's dangerous
https://github.com/entropyxyz/cli/pull/63/files#r1628548871

@rh0delta
Copy link
Contributor Author

rh0delta commented Jun 6, 2024

@mixmix this is ready for re-review. I followed your idea of passing in the signing attempts, but rather than having the check for the number of attempts at the top, I've added it to the conditional for retrying the signing request with the shuffled order

@rh0delta rh0delta merged commit 3251471 into main Jun 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants