TinyGo WASM smart contracts that bridge account-based blockchains (EVM and ERC-20 compatible) to the VSC/Magi network.
Companion to vsc-eco/utxo-mapping, which covers UTXO-based chains (BTC, LTC, DASH, DOGE, BCH).
| Contract | Chain(s) | Asset |
|---|---|---|
evm-mapping-contract |
Ethereum + any EVM L2 (Arbitrum, Optimism, Base, …) | ETH + ERC-20 |
Chain selection is compile-time via the NetworkMode ldflag and runtime via setChainId.
The contract verifies on-chain deposit proofs (receipt-trie inclusion against a stored block header) and credits the depositor's VSC account with a wrapped token balance. Withdrawals (unmapping) construct and TSS-sign an EVM transaction, returning funds to the user's external address.
Deposit & transfer:
map— process an incoming deposit with a receipt-trie prooftransfer/transferFrom/approve/increaseAllowance/decreaseAllowance— ERC-20-style balance operations on mapped tokensconfirmSpend— finalize a pending unmap after its tx confirms on-chain
Withdrawal:
unmapETH— withdraw native ETH to an external addressunmapERC20— withdraw a registered ERC-20 tokenunmapFrom— withdraw on behalf of a third party via allowancereplaceWithdrawal— replace a stuck withdrawal tx (e.g. for fee bump)clearNonce— reset the contract's EVM nonce tracker after an on-chain rollback
Chain relay:
addBlocks— oracle appends new EVM block headersreplaceBlock— replace the tip header after a reorg
Admin / owner:
registerPublicKey— register TSS primary + backup keysregisterRouter— register the DEX router contractregisterToken— whitelist an ERC-20 contractsetVault— set the 20-byte EVM vault address holding mapped fundssetChainId— set the EIP-155 chain IDsetGasReserve— set the gas buffer retained for withdrawal txsadminMint— emergency mint (owner-only)
evm-mapping-contract/
├── Makefile # TinyGo build targets (dev/testnet/mainnet/…)
├── go.mod, go.sum
├── contract/ # on-chain logic
│ ├── main.go # wasmexport entry points
│ ├── blocklist/ # EVM block header relay + reorg
│ ├── mapping/ # deposit/withdrawal flow
│ ├── crypto/ # keccak, RLP, receipt decoding
│ ├── constants/
│ └── contracterrors/
├── monitor/ # off-chain helpers (scanner, receipt encoding)
├── sdk/ # VSC WASM runtime bindings
└── runtime/ # TinyGo GC shim (leaking allocator)
cd evm-mapping-contract
USE_DOCKER=1 make testnet # -> bin/testnet.wasm
USE_DOCKER=1 make mainnet # -> bin/mainnet.wasm
USE_DOCKER=1 make dev # -> bin/dev.wasm (regtest)
make test # Go tests (no TinyGo)Docker is recommended because TinyGo 0.39 requires Go 1.19–1.25 and most dev boxes run newer Go.
See upstream at vsc-eco/utxo-mapping — same license applies.