mochimodev/mochimo

Mochimo 3.0 Suggestion - Prevent tag on existing naked WOTS

0rtis opened this issue · 1 comments

0rtis commented

Add check while creating tag to insure that the target WOTS doesnt not exist in the ledger.
The fix below was made by @chrisdigity but never made it to pull request I guess:

@@ -113,6 +113,8 @@ int tag_valid(byte *src_addr, byte *chg_addr, byte *dst_addr, int checkq, byte *
 {
    LENTRY le;
    word32 tagval_trigger[2];
+   byte dummy_chg_addr[TXADDRLEN];
+   byte default_tag[12] = {0x42, 0, 0, 0, 0xe, 0, 0, 0, 0x1, 0, 0, 0};
 
    tagval_trigger[0] = tagval_trigger[1] = 0;
    if(checkq == 0 && bnum != NULL) {
@@ -146,6 +148,14 @@ int tag_valid(byte *src_addr, byte *chg_addr, byte *dst_addr, int checkq, byte *
       plog("SRC_TAG != CHG_TAG, and SRC_TAG is Non-Default!"); 
       goto bad;
    }
+   /* If the change address already exists in ledger.dat as a WOTS+
+    * with a default tag, tx is invalid */
+   memcpy(dummy_chg_addr, dst_addr, TXADDRLEN - 12);
+   memcpy(ADDR_TAG_PTR(dummy_chg_addr), default_tag, 12);
+   if(le_find(dummy_chg_addr, &le, NULL, 0) == FALSE) {
+      plog("CHG_ADDR WOTS+ already exists in ledger!");
+      goto bad;
+   }
    /* Otherwise, check all queues and ledger.dat for change tag.
     * First, if change tag is in ledger.dat, tx is invalid.
     */

Will bring up a discussion during the next meeting to determine if this will cause any issues with the current state of the ledger.