Преглед на файлове

Move quorum out of verifyVM (#1162)

* Move quorum out of verifyVM

* Add stub out to demonstrate sol-based tests

* Remove unnecessary import

* Neaten up the quorum conditional

* Another iteration on figuring out the test logic

* Fix indentation

* Refactor quorum and setup unit-test cases

* fix return naming

* More variable name clean up

* Move length check inside loop structure

* Fix condition by wrapping

* Fix syntax error

* fix type definition for testCases

* Drop inline struct usage for simple 2d array

* Fix logic in quorum check

* Make test public and fully qualify quorum

* Make wormhole.sol fail

* Specify where to store testCases

* Define array directly

* Fix syntax error on array definition

* Fix variable name

* Move back to memory-based variable

* Add remove qualified quorum call

* Get really direct on quorum tests

* Simplify quorum logic

* Add test for 19 guardians
Jonathan Claudius преди 3 години
родител
ревизия
8875735581
променени са 2 файла, в които са добавени 35 реда и са изтрити 1 реда
  1. 8 1
      ethereum/contracts/Messages.sol
  2. 27 0
      ethereum/test/wormhole.sol

+ 8 - 1
ethereum/contracts/Messages.sol

@@ -51,7 +51,7 @@ contract Messages is Getters {
         *   if making any changes to this, obtain additional peer review. If guardianSet key length is 0 and 
         *   vm.signatures length is 0, this could compromise the integrity of both vm and signature verification.
         */
-        if(((guardianSet.keys.length * 10 / 3) * 2) / 10 + 1 > vm.signatures.length){
+        if (vm.signatures.length < quorum(guardianSet.keys.length)){
             return (false, "no quorum");
         }
 
@@ -145,4 +145,11 @@ contract Messages is Getters {
 
         vm.payload = encodedVM.slice(index, encodedVM.length - index);
     }
+
+    /**
+     * @dev quorum serves solely to determine the number of signatures required to acheive quorum
+     */
+    function quorum(uint numGuardians) public pure virtual returns (uint numSignaturesRequiredForQuorum) {
+        return ((numGuardians * 2) / 3) + 1;
+    }
 }

+ 27 - 0
ethereum/test/wormhole.sol

@@ -0,0 +1,27 @@
+// contracts/Messages.sol
+// SPDX-License-Identifier: Apache 2
+
+pragma solidity ^0.8.0;
+
+import "truffle/Assert.sol";
+import "../contracts/Messages.sol";
+
+contract TestMessages is Messages {
+  function testQuorum() public { 
+    Assert.equal(quorum(0), 1, "it should return quorum");
+    Assert.equal(quorum(1), 1, "it should return quorum");
+    Assert.equal(quorum(2), 2, "it should return quorum");
+    Assert.equal(quorum(3), 3, "it should return quorum");
+    Assert.equal(quorum(4), 3, "it should return quorum");
+    Assert.equal(quorum(5), 4, "it should return quorum");
+    Assert.equal(quorum(6), 5, "it should return quorum");
+    Assert.equal(quorum(7), 5, "it should return quorum");
+    Assert.equal(quorum(8), 6, "it should return quorum");
+    Assert.equal(quorum(9), 7, "it should return quorum");
+    Assert.equal(quorum(10), 7, "it should return quorum");
+    Assert.equal(quorum(11), 8, "it should return quorum");
+    Assert.equal(quorum(12), 9, "it should return quorum");
+    Assert.equal(quorum(19), 13, "it should return quorum");
+    Assert.equal(quorum(20), 14, "it should return quorum");
+  }  
+}