Miner Voting Covenant for Sidechain bridging

Continuing the discussion from Will SHA-Gate be ready for the May 15th upgrade? on an improved miner voting covenant for sidechain bridging:

I’m finally open-sourcing the improved version of the first SHA gate contract! The contract is well commented so as to make it readable and invite review! Here it is: https://github.com/mr-zwets/upgraded-SHA-gate/blob/main/sha-gate-improved.cash

As mentioned in the thread

  • better architecture solves Bitmain firmware issue, requires way less voting and makes monitoring the contract way easier (!)
  • actually enforces only miners in a certain window can vote (!)
  • allows withdrawals of arbitrary amount (!)
  • changed variable voting period to fixed length
  • 5 operators (increase from 3)
  • removed unnecessary op_return message

There’s also a second smart contract in the repo for the sidechain withdrawals.


Made some necessary optimizations to the contract, because apparently the cashscript “cashc” compiler does not take the contract arguments in to account when calculating bytesize so the contract was actually over the 520 bytesize limit. The improved version uses pkhs instead of public keys and replaces long hardcode bytesequences full of zeros by an int to byte conversion to save on bytesize.

The contract is now 194 opcodes (max 201) and 478 bytes large (max 520) including contract parameters. This change means that the contract can still fit up to 6 operator pkhs but no longer 8 like I first thought.

The demo contract made also did not take this compiler behavior in to account but managed to stay under the limit with 193 opcodes and 504 bytes (but the documentation said it was only 359 bytes)