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

Extend multisig contract with weights #416

Merged
merged 6 commits into from
Mar 21, 2019

Conversation

husio
Copy link
Contributor

@husio husio commented Mar 18, 2019

x/multisig extension was updated and now each signature is having a
weight that defines what is the power of that signature.

  • each signature power/weight must be greater than 0,

  • activation threshold must be less or equal to the sum of all signature
    powers,

  • admin threshold can be greater than the sum of all signature powers.
    This can be used to create a contract that can be only activated but
    never changed,

  • multisig contract must have at least one participant/signature
    declared,

  • maximum number of participants is 100 in order to prevent CPU burning,

  • 🔔 Update the CHANGELOG and include the breaking change description.

resolve #285

@husio husio force-pushed the multisig_support_voting_weight_issue_285 branch 2 times, most recently from 57a2a98 to 5730468 Compare March 20, 2019 11:10
@ethanfrey
Copy link
Contributor

Is this ready for a review?
I have plenty of other issues to go through, but ping me when you think you are ready (mention here or on slack) and I will give a proper pr review

@husio
Copy link
Contributor Author

husio commented Mar 20, 2019

Is this ready for a review?

Almost. I want to write a few more tests and double check that everything is implemented as expected. I will let you know when the code is ready for review.

`x/multisig` extension was updated and now each signature is having a
weight that defines what is the power of that signature.

- each signature power/weight must be greater than 0,
- activation threshold must be less or equal to the sum of all signature
  powers,
- admin threshold can be greater than the sum of all signature powers.
  This can be used to create a contract that can be only activated but
  never changed,
- multisig contract must have at least one participant/signature
  declared,
- maximum number of participants is 100 in order to prevent CPU burning,

resolve #285
@husio husio force-pushed the multisig_support_voting_weight_issue_285 branch from 7095b77 to 275fbba Compare March 21, 2019 10:49
@husio husio marked this pull request as ready for review March 21, 2019 10:49
@husio husio requested a review from alpe as a code owner March 21, 2019 10:49
@husio husio requested a review from ethanfrey March 21, 2019 10:49
@codecov-io
Copy link

codecov-io commented Mar 21, 2019

Codecov Report

Merging #416 into master will increase coverage by <.1%.
The diff coverage is 71%.

Impacted file tree graph

@@           Coverage Diff            @@
##           master    #416     +/-   ##
========================================
+ Coverage    68.6%   68.6%   +<.1%     
========================================
  Files         141     141             
  Lines        6936    6971     +35     
========================================
+ Hits         4761    4788     +27     
- Misses       1670    1677      +7     
- Partials      505     506      +1
Impacted Files Coverage Δ
weavetest/handlers.go 100% <ø> (ø) ⬆️
x/multisig/init.go 84.6% <100%> (+4.6%) ⬆️
x/multisig/model.go 59.1% <41.9%> (-6.4%) ⬇️
x/multisig/msg.go 65% <57.5%> (+11.1%) ⬆️
x/multisig/handlers.go 73.1% <84.2%> (+1.4%) ⬆️
x/multisig/decorator.go 94.8% <93.7%> (+4.6%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a849904...65a530b. Read the comment docs.

Copy link
Contributor

@ethanfrey ethanfrey left a comment

Choose a reason for hiding this comment

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

Nice job here.

I will approve it now, as I am not available to review again for a few hours, but please make a number of the changes I wrote below (or respond with a comment why it is a bad idea), and merge once you feel you addressed them all.

Also, note that this implements the POST approach (as before), not PATCH. So, maybe we will need a new PR to add that. (Just add a comment when closing the issue).

x/multisig/decorator.go Show resolved Hide resolved
x/multisig/decorator.go Outdated Show resolved Hide resolved
x/multisig/decorator.go Outdated Show resolved Hide resolved
x/multisig/decorator.go Show resolved Hide resolved
x/multisig/decorator.go Outdated Show resolved Hide resolved
x/multisig/msg.go Show resolved Hide resolved
x/multisig/msg.go Outdated Show resolved Hide resolved
x/multisig/model.go Show resolved Hide resolved
x/multisig/msg.go Show resolved Hide resolved
cmd/bnsd/scenarios/main_test.go Show resolved Hide resolved
Copy link
Contributor

@alpe alpe left a comment

Choose a reason for hiding this comment

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

Good work 🌷. Please also take care of the input data validation. A dedicated test file for msg.go may make sense.

authenticated := x.HasNAddresses(ctx, h.auth, sigs, int(contract.AdminThreshold))
if !authenticated {
return nil, errors.Wrapf(errors.ErrUnauthorized, "contract=%X", updateContractMsg.Id)
if err := msg.Validate(); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

req: please move this up before L146 so that you validate the input data before you actually use them

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I moved it after checking the weights because I want to get ErrUnauthorized before any validation is executed. Otherwise, you can create a transaction without signing that will be validated.
Not sure if that is a bit deal but it feels more appropriate to check permissions before running any functionality.
What do you think?

Copy link
Contributor

Choose a reason for hiding this comment

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

With other handlers like cash or escrow we do input validation before auth checks. I have not checked the others but it would be nice to be consistent

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree. We should validate the message first.
But not modify db state until we have auth

x/multisig/init.go Show resolved Hide resolved
x/multisig/codec.proto Show resolved Hide resolved
x/multisig/decorator.go Show resolved Hide resolved
x/multisig/decorator.go Outdated Show resolved Hide resolved
auth: auth,
bucket: NewContractBucket(),
}
res, err := handler.Deliver(ctx, db, &weavetest.Tx{Msg: &msg})
Copy link
Contributor

Choose a reason for hiding this comment

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

pp: would be ok to persist the contract via the bucket directly. This test is about the decorator reading it only. Deliver should be checked in the handler_test

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, great spot! Done in fd1a9bf

x/multisig/decorator_test.go Outdated Show resolved Hide resolved
x/multisig/model.go Show resolved Hide resolved
return errors.Wrap(err, "admin threshold")
}

var total Weight
Copy link
Contributor

Choose a reason for hiding this comment

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

req: you need to check max power <256 as in the spec. Otherwise this can give you an overflow

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done in 21a8610

x/multisig/msg.go Show resolved Hide resolved
@husio husio merged commit a921d89 into master Mar 21, 2019
@husio husio deleted the multisig_support_voting_weight_issue_285 branch March 21, 2019 15:43
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.

Extend multisig contract with weights
4 participants