Bitcoin Forum

Alternate cryptocurrencies => Altcoin Discussion => Topic started by: tacotime on April 03, 2013, 03:42:32 PM



Title: Mincoin difficulty coaster exploit script
Post by: tacotime on April 03, 2013, 03:42:32 PM
Quote from: manface
Considering you were one of the first posters in here complaining about how you couldn't work out how to download the blockchain I doubt you could do much of anything.

Litecoin:
Code:
unsigned int ComputeMinWork(unsigned int nBase, int64 nTime)
{
    // Testnet has min-difficulty blocks
    // after nTargetSpacing*2 time between blocks:
    if (fTestNet && nTime > nTargetSpacing*2)
        return bnProofOfWorkLimit.GetCompact();

    CBigNum bnResult;
    bnResult.SetCompact(nBase);
    while (nTime > 0 && bnResult < bnProofOfWorkLimit)
    {
        // Maximum 400% adjustment...
        bnResult *= 4;
        // ... in best-case exactly 4-times-normal target time
        nTime -= nTargetTimespan*4;
    }
    if (bnResult > bnProofOfWorkLimit)
        bnResult = bnProofOfWorkLimit;
    return bnResult.GetCompact();
}

unsigned int static GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlock *pblock)
{
    unsigned int nProofOfWorkLimit = bnProofOfWorkLimit.GetCompact();

    // Genesis block
    if (pindexLast == NULL)
        return nProofOfWorkLimit;

    // Only change once per interval
    if ((pindexLast->nHeight+1) % nInterval != 0)
    {
        // Special difficulty rule for testnet:
        if (fTestNet)
        {
            // If the new block's timestamp is more than 2* 10 minutes
            // then allow mining of a min-difficulty block.
            if (pblock->nTime > pindexLast->nTime + nTargetSpacing*2)
                return nProofOfWorkLimit;
            else
            {
                // Return the last non-special-min-difficulty-rules-block
                const CBlockIndex* pindex = pindexLast;
                while (pindex->pprev && pindex->nHeight % nInterval != 0 && pindex->nBits == nProofOfWorkLimit)
                    pindex = pindex->pprev;
                return pindex->nBits;
            }
        }

        return pindexLast->nBits;
    }

Mincoin:
Code:
unsigned int ComputeMinWork(unsigned int nBase, int64 nTime)
{
    // Testnet has min-difficulty blocks
    // after nTargetSpacing*2 time between blocks:
    if (fTestNet && nTime > nTargetSpacing*2)
        return bnProofOfWorkLimit.GetCompact();

    CBigNum bnResult;
    bnResult.SetCompact(nBase);
    while (nTime > 0 && bnResult < bnProofOfWorkLimit)
    {
        // Maximum 400% adjustment...
        bnResult *= 4;
        // ... in best-case exactly 4-times-normal target time
        nTime -= nTargetTimespan*4;
    }
    if (bnResult > bnProofOfWorkLimit)
        bnResult = bnProofOfWorkLimit;
    return bnResult.GetCompact();
}

unsigned int static GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlock *pblock)
{
    unsigned int nProofOfWorkLimit = bnProofOfWorkLimit.GetCompact();

    // Genesis block
    if (pindexLast == NULL)
        return nProofOfWorkLimit;

    // Only change once per interval
    if ((pindexLast->nHeight+1) % nInterval != 0)
    {
        // Special difficulty rule for testnet:
        if (fTestNet)
        {
            // If the new block's timestamp is more than 2* 10 minutes
            // then allow mining of a min-difficulty block.
            if (pblock->nTime > pindexLast->nTime + nTargetSpacing*2)
                return nProofOfWorkLimit;
            else
            {
                // Return the last non-special-min-difficulty-rules-block
                const CBlockIndex* pindex = pindexLast;
                while (pindex->pprev && pindex->nHeight % nInterval != 0 && pindex->nBits == nProofOfWorkLimit)
                    pindex = pindex->pprev;
                return pindex->nBits;
            }
        }

        return pindexLast->nBits;
    }

--> Chain is still vulnerable to coaster exploit, in fact even more so because of the faster retarget

Code for exploit (Unix, Python 2.7)
Code:
from subprocess import Popen, PIPE, STDOUT
import time
import json
import math

class Min(object):
    def __init__(self, blocks):
        self.blocks = blocks

scan_time = 5

while(True):
    ### Get the initial block number from mincoind, store in output_j['blocks']
    cmd = './mincoind getinfo' ### Command for dumping info from mincoind in json format; we use this lots
    p = Popen(cmd, shell=True, stdin=PIPE, stdout=PIPE, stderr=STDOUT, close_fds=True) ### Execute command
    output = p.stdout.read() ### Read the stdout that output gives us
    output_j = json.loads(output) ### Convert from json to python values; we call block number using the class given above
    print("Current block is " + str(output_j['blocks']))

    if (math.floor(output_j['blocks']/720) % 2 == 0): ### During exploit period of 720 blocks, mine MinCoin
        print ("Exploit block, mining mincoin...")

        mincoin_config = open('minmine.conf','r')
        card_config = open('cardconf.conf','r')
        configuration = open('litecoin.conf', 'w')

        ### Copy the reaper configuration to litecoin.conf for mincoin
        for line in mincoin_config:
            configuration.write(line)
        for line in card_config:
            configuration.write(line)

        mincoin_config.close()
        card_config.close()
        configuration.close()

        miner_cmd = './reaper' ### Command for your miner to mine NVC
        miner_thread = Popen(miner_cmd, shell=True, stdin=PIPE, stdout=PIPE, stderr=STDOUT, close_fds=True)

        ### Loop below checks to see when block we're on, terminates miner if we are on an off number block
        while(True):
            p = Popen(cmd, shell=True, stdin=PIPE, stdout=PIPE, stderr=STDOUT, close_fds=True)
            output = p.stdout.read()
            output_j = json.loads(output)
            if not(math.floor(output_j['blocks']/720) % 2 == 0):
                miner_thread.terminate()
                break
            else:
                print("Block height still in exploit period, mining mincoin.")
                time.sleep(scan_time)

    else: ### Block is not exploit, mine something else
        print ("Non-exploit block, mining another chain...")

        mincoin_config = open('elsemine.conf','r')
        card_config = open('cardconf.conf','r')
        configuration = open('litecoin.conf', 'w')

        ### Copy the reaper configuration to litecoin.conf for other chain
        for line in mincoin_config:
            configuration.write(line)
        for line in card_config:
            configuration.write(line)

        mincoin_config.close()
        card_config.close()
        configuration.close()

        miner_cmd = './reaper' ### Command for your miner to mine something else; the same here because we use reaper
        miner_thread = Popen(miner_cmd, shell=True, stdin=PIPE, stdout=PIPE, stderr=STDOUT, close_fds=True)

        ### Loop below checks to see when block we're on, terminates miner if we are on an exploit number block
        while(True):
            p = Popen(cmd, shell=True, stdin=PIPE, stdout=PIPE, stderr=STDOUT, close_fds=True)
            output = p.stdout.read()
            output_j = json.loads(output)
            if (math.floor(output_j['blocks']/720) % 2 == 0):
                miner_thread.terminate()
                break
            else:
                print("Block not exploit height, mining another chain.")
                time.sleep(scan_time)

Code for exploit (Windows, Python 2.7)
Code:
from subprocess import Popen, PIPE, STDOUT
import time
import json
import math

class Min(object):
    def __init__(self, blocks):
        self.blocks = blocks

scan_time = 5

while(True):
    ### Get the initial block number from mincoind, store in output_j['blocks']
    cmd = 'mincoind.exe getinfo' ### Command for dumping info from mincoind in json format; we use this lots
    p = Popen(cmd, shell=True, stdin=PIPE, stdout=PIPE, stderr=STDOUT, close_fds=True) ### Execute command
    output = p.stdout.read() ### Read the stdout that output gives us
    output_j = json.loads(output) ### Convert from json to python values; we call block number using the class given above
    print("Current block is " + str(output_j['blocks']))

    if (math.floor(output_j['blocks']/720) % 2 == 0): ### During exploit period of 720 blocks, mine MinCoin
        print ("Exploit block, mining mincoin...")

        mincoin_config = open('minmine.conf','r')
        card_config = open('cardconf.conf','r')
        configuration = open('litecoin.conf', 'w')

        ### Copy the reaper configuration to litecoin.conf for mincoin
        for line in mincoin_config:
            configuration.write(line)
        for line in card_config:
            configuration.write(line)

        mincoin_config.close()
        card_config.close()
        configuration.close()

        miner_cmd = 'reaper.exe' ### Command for your miner to mine NVC
        miner_thread = Popen(miner_cmd, shell=True, stdin=PIPE, stdout=PIPE, stderr=STDOUT, close_fds=True)

        ### Loop below checks to see when block we're on, terminates miner if we are on an off number block
        while(True):
            p = Popen(cmd, shell=True, stdin=PIPE, stdout=PIPE, stderr=STDOUT, close_fds=True)
            output = p.stdout.read()
            output_j = json.loads(output)
            if not(math.floor(output_j['blocks']/720) % 2 == 0):
                miner_thread.terminate()
                break
            else:
                print("Block height still in exploit period, mining mincoin.")
                time.sleep(scan_time)

    else: ### Block is not exploit, mine something else
        print ("Non-exploit block, mining another chain...")

        mincoin_config = open('elsemine.conf','r')
        card_config = open('cardconf.conf','r')
        configuration = open('litecoin.conf', 'w')

        ### Copy the reaper configuration to litecoin.conf for other chain
        for line in mincoin_config:
            configuration.write(line)
        for line in card_config:
            configuration.write(line)

        mincoin_config.close()
        card_config.close()
        configuration.close()

        miner_cmd = 'reaper.exe' ### Command for your miner to mine something else; the same here because we use reaper
        miner_thread = Popen(miner_cmd, shell=True, stdin=PIPE, stdout=PIPE, stderr=STDOUT, close_fds=True)

        ### Loop below checks to see when block we're on, terminates miner if we are on an exploit number block
        while(True):
            p = Popen(cmd, shell=True, stdin=PIPE, stdout=PIPE, stderr=STDOUT, close_fds=True)
            output = p.stdout.read()
            output_j = json.loads(output)
            if (math.floor(output_j['blocks']/720) % 2 == 0):
                miner_thread.terminate()
                break
            else:
                print("Block not exploit height, mining another chain.")
                time.sleep(scan_time)

Requires the following files to exist:
mincoind executable that is running prior to executing the python code above
reaper executable
reaper.conf (configured as per normal)
Requires reaper and mincoind to be in the same directory

minmine.conf:
Code:
host minecoinhost
port ????
user username
pass password
elsemine.conf (mines litecoin or whatever with reaper)
Code:
host litecoinhost
port ????
user username
pass password
cardconf.conf (configuration for scrypt):
Code:

protocol litecoin

worksize 256
vectors 1
aggression 20
threads_per_gpu 1
sharethreads 32
lookup_gap 2
gpu_thread_concurrency ####


Title: Re: Mincoin difficulty coaster exploit script
Post by: tacotime on April 03, 2013, 03:49:21 PM
Whoops, forgot to change a couple of lines, should work now

Not that anyone is mining mincoin anyway


Title: Re: Mincoin difficulty coaster exploit script
Post by: phantastisch on April 03, 2013, 03:53:34 PM
Whoops, forgot to change a couple of lines, should work now

Not that anyone is mining mincoin anyway

Your Litecoin & Mincoin Code examples read identic to me , is this intended?


Title: Re: Mincoin difficulty coaster exploit script
Post by: tacotime on April 03, 2013, 03:55:47 PM
Your Litecoin & Mincoin Code examples read identic to me , is this intended?

Yes, it's a problem with litecoin (and bitcoin) as diff changes are ONLY based upon the retarget period.  However, if your retarget period is long enough it's not a problem -- the shorter the retarget, the more exploitable the chain.  About 5 months ago the problem was bad for litecoin, but now as litecoin is worth much more than bitcoin, chain hopping is discouraged and it's not really a problem.  PPcoin (and now with Sunny King's help, TRC) addressed this by basing retarget on longer moving average periods.

Was used successfully for TRC here: https://bitcointalk.org/index.php?topic=157449.0

Although not by me, I only wrote the script.


Title: Re: Mincoin difficulty coaster exploit script
Post by: bushstar on April 03, 2013, 03:56:30 PM
Thanks for that Taco. Very interesting.


Title: Re: Mincoin difficulty coaster exploit script
Post by: phantastisch on April 03, 2013, 03:58:31 PM
Your Litecoin & Mincoin Code examples read identic to me , is this intended?

Yes, it's a problem with litecoin (and bitcoin) as diff changes are ONLY based upon the retarget period.  However, if your retarget period is long enough it's not a problem -- the shorter the retarget, the more exploitable the chain.  About 5 months ago the problem was bad for litecoin, but now as litecoin is worth much more than bitcoin, chain hopping is discouraged and it's not really a problem.  PPcoin (and now with Sunny King's help, TRC) addressed this by basing retarget on longer moving average periods.

thx, i thought at first mincoin changed something after forking from litecoin and where now susceptible to this attack.


Title: Re: Mincoin difficulty coaster exploit script
Post by: Cyberdyne on May 07, 2013, 02:37:45 AM
This is the only thread on the entire forum that contains the word 'mincoind'.

Where does one get a copy of this for Windows? :)  Feeling very lame right now.


Title: Re: Mincoin difficulty coaster exploit script
Post by: GSnak on May 07, 2013, 02:40:13 AM
The trash bin.


Title: Re: Mincoin difficulty coaster exploit script
Post by: Cyberdyne on May 07, 2013, 02:51:42 AM
The trash bin.

I checked but all I found there was midget porn. (I delete that regularly).


Title: Re: Mincoin difficulty coaster exploit script
Post by: manface on May 07, 2013, 03:08:00 AM
All Bitcoin chains suffer from this same thing, its just easier to do in Mincoin. It doesn't harm the chain it just means more coins can be released faster over a period if the miner doing it has enough power. As the mining network grows this is more and more difficult to do like tacotime pointed out. Not a big deal at all.


Title: Re: Mincoin difficulty coaster exploit script
Post by: Shad3dOne on May 07, 2013, 03:23:13 AM
interesting...


Title: Re: Mincoin difficulty coaster exploit script
Post by: TheSwede75 on May 07, 2013, 04:34:49 AM
Why are we even discussing mincoin? Check first day block reward and diff and you have to be a lunatic to ever touch that shit. Block reward goes from 100/block to 2/block in 3 days ha ha..  'Developer' (and I am using the term loosely) must have been smoking fucking Meth when he threw that piece of dung out on the forum.


Title: Re: Mincoin difficulty coaster exploit script
Post by: mc_lovin on May 07, 2013, 04:40:59 AM
Why are we even discussing mincoin? Check first day block reward and diff and you have to be a lunatic to ever touch that shit. Block reward goes from 100/block to 2/block in 3 days ha ha..  'Developer' (and I am using the term loosely) must have been smoking fucking Meth when he threw that piece of dung out on the forum.

Yeah but look how much meth money he has now by selling his failcoins on noobs?


Title: Re: Mincoin difficulty coaster exploit script
Post by: TheSwede75 on May 07, 2013, 05:23:03 AM
Why are we even discussing mincoin? Check first day block reward and diff and you have to be a lunatic to ever touch that shit. Block reward goes from 100/block to 2/block in 3 days ha ha..  'Developer' (and I am using the term loosely) must have been smoking fucking Meth when he threw that piece of dung out on the forum.

Yeah but look how much meth money he has now by selling his failcoins on noobs?


If you want to giggle for a second, check out this screenshot of the 'mincoin mafia' (such cute kids) bragging about calling me out as a scammer and trying to discredit me on BTC-E:
https://i.imgur.com/UOYpl7B.png

Priceless! Altcoins - It's serious business :)


Title: Re: Mincoin difficulty coaster exploit script
Post by: AzureEngineer on May 07, 2013, 05:24:15 AM
MNC is changing the scheme from "Pump and Dump" to "Crash and Burn."