Sfoglia il codice sorgente

Fix tests and add double hashing

Change-Id: I9676e8dd8d25f44c43ef10462493f20d1caff724
Hendrik Hofstadt 4 anni fa
parent
commit
227445cd76

+ 3 - 3
ethereum/contracts/Implementation.sol

@@ -9,14 +9,14 @@ import "./Governance.sol";
 import "@openzeppelin/contracts/proxy/ERC1967/ERC1967Upgrade.sol";
 
 contract Implementation is Governance {
-    event LogMessagePublished(address indexed sender, uint64 sequence, uint32 nonce, bytes payload, bool persistMessage, uint8 consistency_level);
+    event LogMessagePublished(address indexed sender, uint64 sequence, uint32 nonce, bytes payload, bool persistMessage, uint8 consistencyLevel);
 
     // Publish a message to be attested by the Wormhole network
     function publishMessage(
         uint32 nonce,
         bytes memory payload,
         bool persistMessage,
-        uint8 consistency_level
+        uint8 consistencyLevel
     ) public payable {
         // check fee
         if( persistMessage ) {
@@ -26,7 +26,7 @@ contract Implementation is Governance {
         }
 
         // emit log
-        emit LogMessagePublished(msg.sender, useSequence(msg.sender), nonce, payload, persistMessage, consistency_level);
+        emit LogMessagePublished(msg.sender, useSequence(msg.sender), nonce, payload, persistMessage, consistencyLevel);
     }
 
     function useSequence(address emitter) internal returns (uint64 sequence) {

+ 1 - 1
ethereum/contracts/Messages.sol

@@ -83,7 +83,7 @@ contract Messages is Getters {
 
         // Hash the body
         bytes memory body = encodedVM.slice(index, encodedVM.length - index);
-        vm.hash = keccak256(body);
+        vm.hash = keccak256(abi.encodePacked(keccak256(body)));
 
         // Parse the body
         vm.timestamp = encodedVM.toUint32(index);

+ 37 - 17
ethereum/test/wormhole.js

@@ -107,7 +107,8 @@ contract("Wormhole", function () {
         const log = await initialized.methods.publishMessage(
             "0x123",
             "0x123321",
-            false
+            false,
+            32
         ).send({
             value: 0, // fees are set to 0 initially
             from: accounts[0]
@@ -117,6 +118,8 @@ contract("Wormhole", function () {
         assert.equal(log.events.LogMessagePublished.returnValues.sequence.toString(), "0");
         assert.equal(log.events.LogMessagePublished.returnValues.nonce, 291);
         assert.equal(log.events.LogMessagePublished.returnValues.payload.toString(), "0x123321");
+        assert.equal(log.events.LogMessagePublished.returnValues.consistencyLevel, 32);
+        assert.equal(log.events.LogMessagePublished.returnValues.persistMessage, false);
     })
 
     it("should increase the sequence for an account", async function () {
@@ -126,7 +129,8 @@ contract("Wormhole", function () {
         const log = await initialized.methods.publishMessage(
             "0x1",
             "0x1",
-            false
+            false,
+            32
         ).send({
             value: 0, // fees are set to 0 initially
             from: accounts[0]
@@ -154,7 +158,8 @@ contract("Wormhole", function () {
             [
                 testSigner1PK,
             ],
-            0
+            0,
+            2
         );
 
         let result
@@ -173,6 +178,7 @@ contract("Wormhole", function () {
         assert.equal(result.vm.payload, data);
         assert.equal(result.vm.guardianSetIndex, 0);
         assert.equal(result.vm.sequence, 1337);
+        assert.equal(result.vm.consistencyLevel, 2);
 
         assert.equal(result.valid, true);
 
@@ -205,7 +211,8 @@ contract("Wormhole", function () {
             [
                 testSigner1PK,
             ],
-            0
+            0,
+            2
         );
 
 
@@ -226,7 +233,8 @@ contract("Wormhole", function () {
         await initialized.methods.publishMessage(
             "0x123",
             "0x123321",
-            false
+            false,
+            32
         ).send({
             from: accounts[0],
             value: 1111
@@ -235,7 +243,8 @@ contract("Wormhole", function () {
         await initialized.methods.publishMessage(
             "0x123",
             "0x123321",
-            true
+            true,
+            32
         ).send({
             from: accounts[0],
             value: 2222
@@ -246,7 +255,8 @@ contract("Wormhole", function () {
             await initialized.methods.publishMessage(
                 "0x123",
                 "0x123321",
-                false
+                false,
+                32
             ).send({
                 value: 1110,
                 from: accounts[0]
@@ -286,7 +296,8 @@ contract("Wormhole", function () {
             [
                 testSigner1PK,
             ],
-            0
+            0,
+            2
         );
 
         let WHBefore = await web3.eth.getBalance(Wormhole.address);
@@ -336,7 +347,8 @@ contract("Wormhole", function () {
             [
                 testSigner1PK,
             ],
-            0
+            0,
+            2
         );
 
         let set = await initialized.methods.submitNewGuardianSet("0x" + vm).send({
@@ -400,7 +412,8 @@ contract("Wormhole", function () {
                 testSigner2PK,
                 testSigner3PK
             ],
-            1
+            1,
+            2
         );
 
         let before = await web3.eth.getStorageAt(Wormhole.address, "0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc");
@@ -445,7 +458,8 @@ contract("Wormhole", function () {
             [
                 testSigner1PK,
             ],
-            0
+            0,
+            2
         );
 
         let failed = false;
@@ -480,7 +494,8 @@ contract("Wormhole", function () {
             [
                 testSigner1PK,
             ],
-            0
+            0,
+            2
         );
 
         // this should pass
@@ -518,7 +533,8 @@ contract("Wormhole", function () {
                 testSigner2PK,
                 testSigner3PK,
             ],
-            1
+            1,
+            2
         );
 
         try {
@@ -556,7 +572,8 @@ contract("Wormhole", function () {
                 testSigner2PK,
                 testSigner3PK,
             ],
-            1
+            1,
+            2
         );
 
         try {
@@ -594,7 +611,8 @@ contract("Wormhole", function () {
                 testSigner2PK,
                 testSigner3PK,
             ],
-            1
+            1,
+            2
         );
 
         await initialized.methods.submitTransferFees("0x" + vm).send({
@@ -625,7 +643,8 @@ const signAndEncodeVM = async function (
     sequence,
     data,
     signers,
-    guardianSetIndex
+    guardianSetIndex,
+    consistencyLevel
 ) {
     const body = [
         web3.eth.abi.encodeParameter("uint32", timestamp).substring(2 + (64 - 8)),
@@ -633,10 +652,11 @@ const signAndEncodeVM = async function (
         web3.eth.abi.encodeParameter("uint16", emitterChainId).substring(2 + (64 - 4)),
         web3.eth.abi.encodeParameter("bytes32", emitterAddress).substring(2),
         web3.eth.abi.encodeParameter("uint64", sequence).substring(2 + (64 - 16)),
+        web3.eth.abi.encodeParameter("uint8", consistencyLevel).substring(2 + (64 - 2)),
         data.substr(2)
     ]
 
-    const hash = web3.utils.soliditySha3("0x" + body.join(""))
+    const hash = web3.utils.soliditySha3(web3.utils.soliditySha3("0x" + body.join("")))
 
     let signatures = "";