dtr-org / unit-e

A digital currency for a new era of decentralized trust
https://unit-e.io
MIT License
45 stars 15 forks source link

Implement OP_CHECKCOMMIT #954

Closed Gnappuraz closed 5 years ago

Gnappuraz commented 5 years ago

Currently the scriptPubKey used for commits (deposit, vote, slash and logout) are basically not implemented, but the validation of the script is skipped. This for example allows for anybody to craft a transaction that spends a vote from a finalizer.

Currently commits use the PayVoteSlashScript as follows:

0x21 [validator_pubkey] CHECKVOTESIG
IF 
    1 
ELSE 
    0x21 [validator_pubkey]  SLASHABLE 
    NOTIF 
        DUP HASH160 0x14 [p2pkh_address]  EQUALVERIFY CHECKSIG 
    ELSE 
        1 
    ENDIF 
ENDIF

but OP_CHECKVOTESIG and OP_SLASHABLE execution is just skipped and never checked, the only validation logic in place makes sure that commits contain a script of this shape.

This PR introduces a new opcode OP_CHECKCOMMIT and removes OP_CHECKVOTESIG and OP_SLASHABLE. The new opcode behaves differently depending on the type of transaction spending the script. The PR also streamlines the script, now called CommitScript

0x21 [validator_pubkey] CHECKCOMMIT
IF
    1
ELSE
    DUP HASH160 0x14 [p2pkh_address] EQUALVERIFY CHECKSIG 
ENDIF

This script format is also about 40% shorter then the previous (103 bytes to 64).

scravy commented 5 years ago

BTW what are the plans to move esperanza tx to witness style?

Gnappuraz commented 5 years ago

@scravy Yes there are but my plan is to do it in two steps, the first creates the opcode, the seconds makes it witness compatible (we need the opcode implemented even with the witness).

frolosofsky commented 5 years ago

ConceptACK 2d2ac44fb8b23437a95fd9b4c310de9daecc7be6