Skip to content

Commit

Permalink
[#63] Fix threshold number calculation
Browse files Browse the repository at this point in the history
`x*2/3` is not equal to `x/3*2` with integers.
The only correct way to calculate threshold is
the first one.

Signed-off-by: Alex Vanin <[email protected]>
  • Loading branch information
alexvanin committed Mar 25, 2021
1 parent 80eadb4 commit 23f5f1e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion common/ir.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func AlphabetAddress() []byte {
// Multiaddress returns default multi signature account address for N keys.
// If committee set to true, then it is `M = N/2+1` committee account.
func Multiaddress(n []interop.PublicKey, committee bool) []byte {
threshold := len(n)/3*2 + 1
threshold := len(n)*2/3 + 1
if committee {
threshold = len(n)/2 + 1
}
Expand Down
8 changes: 4 additions & 4 deletions neofs/neofs_contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ func InnerRingCandidateRemove(key interop.PublicKey) bool {

if !runtime.CheckWitness(key) {
alphabet := getNodes(ctx, alphabetKey)
threshold := len(alphabet)/3*2 + 1
threshold := len(alphabet)*2/3 + 1

nodeKey := common.InnerRingInvoker(alphabet)
if len(nodeKey) == 0 {
Expand Down Expand Up @@ -286,7 +286,7 @@ func Withdraw(user []byte, amount int) bool {
func Cheque(id []byte, user interop.Hash160, amount int, lockAcc []byte) bool {
ctx := storage.GetContext()
alphabet := getNodes(ctx, alphabetKey)
threshold := len(alphabet)/3*2 + 1
threshold := len(alphabet)*2/3 + 1

cashedCheques := getCashedCheques(ctx)
hashID := crypto.Sha256(id)
Expand Down Expand Up @@ -369,7 +369,7 @@ func AlphabetUpdate(chequeID []byte, args []interop.PublicKey) bool {
}

alphabet := getNodes(ctx, alphabetKey)
threshold := len(alphabet)/3*2 + 1
threshold := len(alphabet)*2/3 + 1

key := common.InnerRingInvoker(alphabet)
if len(key) == 0 {
Expand Down Expand Up @@ -426,7 +426,7 @@ func SetConfig(id, key, val []byte) bool {

// check if it is alphabet invocation
alphabet := getNodes(ctx, alphabetKey)
threshold := len(alphabet)/3*2 + 1
threshold := len(alphabet)*2/3 + 1

nodeKey := common.InnerRingInvoker(alphabet)
if len(nodeKey) == 0 {
Expand Down

0 comments on commit 23f5f1e

Please sign in to comment.