Weekly Dev Update #39
THORChain Weekly Dev Update for Week 14–20 Apr 2020; Bitcoin Integration, Ethereum Integration, Errata Tx, Accpetance Criteria
THORChain Weekly Dev Update for Week 14–20 Apr 2020
Summary
Bitcoin Integration
THORNode has integrated BTC as a chain type, as well as Bitcoin address validation supporting P2WSH, P2WPKH (segwit) and P2SH, P2PKH (non-segwit). This means users will be able to send BTC.BTC to new addresses (starting with bc1 ) as well as legacy addresses, starting with 3 or 1.

Bifröst now observes incoming Bitcoin transactions, with the following required structure:

Any transaction that does not have this structure will be ignored. This is because Bitcoin has an extremely flexible transaction structure and allowing a wider range of transactions was going to cause too much complexity for THORNode. Any wallet or exchange that wishes to integrate THORChain will have to follow this structure. ASGARDEX will provide a reference implementation.
Bitcoin has also been integrated into Smoke tests, and all aspects have been validated in the single-node environment. The next aspect will be to integrate it into a multi-node environment in order to test out THORChain TSS batch signing of UTXOs.
Ethereum Integration
Ethereum has also been integrated in Bifröst, with the following code-chunk showing how a transaction is decoded and used to create a valid txIn :

Ethereum is a bit simpler in decoding a transaction, however only ETH.ETH is supported currently. The issue is that the MEMO can easily be parsed from tx.Data() in an eth transaction, but in a ERC-20 transaction the tx.Data() object is completely filled with the ERC-20 transfer call. The solution is to use a smart contract to allow the MEMO to be added as a string, however this creates UX problems among other things. ERC-20 can be solved, it will just require concessions.
Errata Transactions
Proof-of-Work is leaderless because it uses the power of probability and a huge number space to create entropy for leader selection. However, a leaderless blockchain (while excellent at being live and censorship-resistant), necessarily requires users to accept that the chain-tip may not be correct at any given time. Chain re-organisations are a natural event and happen all the time. Malicious re-organisations happen when a network user uses this natural occurence to their advantage and fools another network user in accepting their transaction. In either case (natural or malicious), the network user accepting the transaction is THORChain and it has not ability to seek retribution for loss of funds. All it can (and should) do is maintain eventual consistency with solvency — that the funds it thinks it has in its vaults matches what it actually has.
As such, THORChain adds the concept of an errataTx — a mechanism for accepting that a transaction it previously observed and took action on no longer exists (re-orged out) and the balances associated with that transaction has to be removed from its system. The transaction is quite simple and it submitted by nodes who, upon receiving a new chain-tip candidate, re-scan previously reported transactions to find those that no longer exist:type errataTx struct {
ID TxID `json:"id"`
Chain Chain `json:"chain"`
}
Once THORChain reaches consensus on it, it will then go ahead with the following logic:
- Swap: Deduct pool balance
- Stake: Deduct pool balance and remove stakeUnits for associated staker.
Since it cannot undo the event, it is simply trying return the system to solvency, and in doing so, socialise the loss of funds to all pool stakers.
Importantly, loss of funds is limited to just the amount of the re-orged funds. It is imagined if this occurs, then THORNodes will release an update to increase the acceptance criteria of new transactions for that chain to prevent re-occurence.
Acceptance Criteria
Since THORChain has an excellent view of connected networks (all THORNodes run associated nodes for each chain), then accepting 1-confirmation is relatively safe. THORChain’s team has previously argued that any transaction that is less than the block reward for a chain can be safely accepted, and it is not likely that large (10+Bitcoin, 100+ Ether) transactions will occur on the network for a while (due to low starting liquidity). Confirmation-counting will be added at a future point in time, and since it is not consensus-related, it can be released as a network patch easily.
THORNode
Bitcoin
- Resolve “Add utxo accessor in bitcoin client”
- Resolve “Add bitcoin mock”
- 428-issue update SigningTransactionPeriod to 300 blocks, and a few fixes for bitcoin chain client
- Resolve “[ADD] calculate GAS on a bitcoin transaction”
Ethereum
Other
- Resolve “[ADD] Fork txscript, and update it to support tss”
- [feature] bifrost waits for thorchain to catch up
- [refactor] Flip thorchain signer to use new common block scanner
- Resolve “[Fix] Bifrost data race issue”
- [feature] Tx markers
- [feature] Register node ip address
- [feature] Resolve “ADD: ErrataTx”
- [feature] Event stream by chain
- 432-issue fix gas management for BTC and ETH
Midgard
Maintenance
- Add support for self signed TLS
- Testnet docker image builds
- Resolve “Abstract Thorchain client”
- Resolve “Implement mock for store”
- Resolve “Add NodeKey Endpoint”
- Resolve “Invalid Reward Event Test”
- Resolve “Fix getOutTx”
Clients
BEPSwap
Tweaks, bugfixes and improvements to Byzantine.
- Resolve “Add eslint rule for linebreak issue on windows os”
- Merge latest development into master (04–16–20)
- Resolve “Retry Midgard requests in case of failing”
- Use one route for `Swap` and `Send` only
- Fix number of requests on tx history page
- Resolve “Update to latest Byzantine (04–17–20)”
- Merge latest development into master (04–17–20)
- Fix Midgard IP in Header + bump Byzantine
Asgard Wallet
Preparing for release.
- Changes for UI to select networks
- Feature/network ui
- Feature/cleanup codebase
- Feature/prep release
- Develop
Community
Arb Bots
Two open-source trading bots are being developed by the community and will be unveiled soon.

THORNode Notification Service
Block42 is leading the charge on the TNS and it will be unveiled soon.
Bounty Program
Enquire with the team about bounties for THORChain development.
Audit
Code Review: Complete
Economic Review: Completed most of THORChain's economic architecture
TSS Audit: kickoff
Next Milestones
The updated testnet is in the final stages of testing. Chaosnet is expected once testnet has been fully-validated in several environments. There currently isn’t any known blockers to Chaosnet release.
Community
To keep up to date, please monitor community channels, particularly Telegram and Twitter:
- Twitter: https://twitter.com/thorchain_org
- Telegram Community: https://t.me/thorchain_org
- Telegram Announcements: https://t.me/thorchain
- Reddit: https://reddit.com/r/thorchain
- Github: https://github.com/thorchain
- Medium: https://medium.com/thorchain