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

blockchain/types: multisig improvement #1001

Merged
merged 5 commits into from
Jul 22, 2021

Conversation

yoomee1313
Copy link
Contributor

@yoomee1313 yoomee1313 commented Jun 30, 2021

Proposed changes

  • This PR implements the one of the istanbul compatible change item, multisig improvement.

  • Istanbul compatible change is not activated since IstanbulCompatibleBlock of cypress and baobab network is nil.

  • Main idea

    • multiSig gas cost change
      • before the change, gas cost is charged depend on the number of registered key
      • after the change, gas cost is charged depend on the number of signature number
    • multiSig tx validation1: when len(tx signature) > len(registeredKey), the tx is invalid.
    • multiSig tx validation2: when invalid signature is included, the tx is invalid.
  • dcd39aa commit will be removed after consensus/istanbul: add round to previous hash #997 merged.

Types of changes

Please put an x in the boxes related to your change.

  • Bugfix
  • New feature or enhancement
  • Others

Checklist

Put an x in the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your code.

  • I have read the CONTRIBUTING GUIDELINES doc
  • I have signed the CLA
  • Lint and unit tests pass locally with my changes ($ make test)
  • I have added tests that prove my fix is effective or that my feature works
  • I have added necessary documentation (if appropriate)
  • Any dependent changes have been merged and published in downstream modules

Related issues

  • Please leave the issue numbers or links related to this PR here.

Further comments

If this is a relatively large or complex change, kick off the discussion by explaining why you chose the solution you did and what alternatives you considered, etc...

Copy link
Member

@aidan-kwon aidan-kwon left a comment

Choose a reason for hiding this comment

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

@yoomee1313 Your suggestion passes isIstanbul value to too many functions. Could you use fork package instead of passing it too much? You can refer our hard fork tests conducted before mainnet launching.
https://github.com/ground-x/klaytn/pull/2356
https://github.com/ground-x/klaytn/pull/2370

@yoomee1313 yoomee1313 marked this pull request as draft July 2, 2021 08:43
@yoomee1313 yoomee1313 marked this pull request as ready for review July 20, 2021 06:33
@yoomee1313 yoomee1313 removed the draft label Jul 20, 2021
blockchain/types/transaction.go Outdated Show resolved Hide resolved
blockchain/types/transaction.go Outdated Show resolved Hide resolved
fork/fork.go Outdated Show resolved Hide resolved
blockchain/types/accountkey/account_key_test.go Outdated Show resolved Hide resolved
@yoomee1313 yoomee1313 marked this pull request as draft July 21, 2021 00:08
* multiSig tx is invalid when the number of signatures is larger than the number of registered key
* multiSig tx is invalid when it includes invalid signature
* multiSig gas cost is charged depend on the number of signature number, not the number of registered key
@yoomee1313 yoomee1313 marked this pull request as ready for review July 21, 2021 00:44
@yoomee1313
Copy link
Contributor Author

yoomee1313 commented Jul 21, 2021

@aidan-kwon @ehnuje @jeongkyun-oh @hyochan-brown

The previous implementation is using valid sigNum when calculating gas cost.
It is changed to use the number of whole signatures in transaction,

so validate is changed not to return second return value. It returns only bool.

Please take a second look

aidan-kwon
aidan-kwon previously approved these changes Jul 21, 2021
jeongkyun-oh
jeongkyun-oh previously approved these changes Jul 21, 2021
ehnuje
ehnuje previously approved these changes Jul 21, 2021
Copy link
Contributor

@ehnuje ehnuje left a comment

Choose a reason for hiding this comment

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

LGTM except for minor comment.

@@ -72,7 +72,7 @@ type AccountKey interface {
AccountCreationGas(currentBlockNumber uint64) (uint64, error)

// SigValidationGas returns gas required to validate a tx with the account.
SigValidationGas(currentBlockNumber uint64, r RoleType) (uint64, error)
SigValidationGas(currentBlockNumber uint64, r RoleType, sigNum int) (uint64, error)
Copy link
Contributor

Choose a reason for hiding this comment

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

I prefer naming "num+plural" format for something's "number". In this case, numSigs
For me, sigNum sounds like a ID for a signature. e.g., sigNum=100 (it means 100 is signature's number)

Please check below example.

BlockNumber = A (unique) number assigned to a block
Number(Of)Blocks = How many blocks

As we need to merge this change today, please ignore above comment for now.
But please consider it in your later changes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thinking back, it reads like that.. thanks! Revised in new commit 4becba9

if weightedSum >= a.Threshold {
return true
// Validation 2. if isIstanbul is true, check whether invalid signature exists
if isIstanbul && validSigNum < len(pMap) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Same comment for validSigNum

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Revised in new commit 4becba9

@aidan-kwon
Copy link
Member

@yoomee1313 Please, resolve the conflict

@yoomee1313 yoomee1313 dismissed stale reviews from ehnuje, jeongkyun-oh, and aidan-kwon via 6faa7df July 21, 2021 11:07
Copy link
Member

@aidan-kwon aidan-kwon left a comment

Choose a reason for hiding this comment

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

Thanks a lot!

@aidan-kwon aidan-kwon merged commit 84b8454 into klaytn:dev Jul 22, 2021
@yoomee1313 yoomee1313 deleted the incompatiblechange-multisig branch January 13, 2022 00:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants