Home

Awesome

Guac

This repo contains the payment channel contracts of Althea.

Setup

Make sure you have yarn installed. It is not necessary but the installation is a lot faster compared to npm install.

yarn install

Running tests

# in one terminal run:
npm run ganache
# in another:
npm run test

Contract documentation

ECVerify

function ecverify

ECVerify.ecverify(hash, sig, signer) nonpayable 39cdde32

Inputs

typenamedescription
bytes32hashundefined
bytessigundefined
addresssignerundefined

function ecrecovery

ECVerify.ecrecovery(hash, sig) nonpayable 77d32e94

Inputs

typenamedescription
bytes32hashundefined
bytessigundefined

ETHWallet

function withdraw

ETHWallet.withdraw(amount) nonpayable 2e1a7d4d

Inputs

typenamedescription
uint256amountundefined

function quickDeposit

ETHWallet.quickDeposit() payable 4c0f0e12

function depositToAddress

ETHWallet.depositToAddress(_address) payable 562cc33c

Inputs

typenamedescription
address_addressundefined

function balanceOf

ETHWallet.balanceOf(_address) view 70a08231

Inputs

typenamedescription
address_addressundefined

PaymentChannels

function updateState

PaymentChannels.updateState(_channelId, _sequenceNumber, _balance0, _balance1, _signature0, _signature1) nonpayable 070eae11

Update the balances in the channel to make a payment from one node to another.

Inputs

typenamedescription
bytes32_channelIdThe channelId of the channel to update.
uint256_sequenceNumberThe sequence number of the update. If an update with a higher sequence number has already been added, this updateState tx will fail.
uint256_balance0The balance of address0.
uint256_balance1The balance of address1. These balances must add up to the channel's totalBalance.
bytes_signature0undefined
bytes_signature1undefined

function reDraw

PaymentChannels.reDraw(_channelId, _sequenceNumber, _oldBalance0, _oldBalance1, _newBalance0, _newBalance1, _expiration, _signature0, _signature1) nonpayable 2197daa1

Refill or withdraw money from a channel which is currently open. This is equivalent to both participants signing and sumbitting a closeChannelFast tx followed by a newChannel tx, except that the channelId, the settlingPeriod, and the current sequenceNumber do not change. This logs a ChannelReDrawn event containing the channelId

Inputs

typenamedescription
bytes32_channelIdThe Id of the channel to ReDraw.
uint256_sequenceNumberThe channel's current sequenceNumber.
uint256_oldBalance0The balance of address0.
uint256_oldBalance1The balance of address1.These balances must add up to the channel's totalBalance, and will be sent to address0 and address1 when this tx is submitted.
uint256_newBalance0The intended new balance of address0.
uint256_newBalance1The intended new balance of address1. Address0 and address1 must have enough money to cover these amounts, and it is withdrawn from their accounts when this tx is submitted.
uint256_expirationThe block that this tx expires. See documentation for the newChannel tx for more detail on why this exists.
bytes_signature0undefined
bytes_signature1undefined

function closeChannelFast

PaymentChannels.closeChannelFast(_channelId, _sequenceNumber, _balance0, _balance1, _signature0, _signature1) nonpayable 2d1eda18

Close the channel and transfer the current balances back to the participants.

Inputs

typenamedescription
bytes32_channelIdThe channelId of the channel to update.
uint256_sequenceNumberThe sequence number of the update. If an update with a higher sequence number has already been added, this updateState tx will fail.
uint256_balance0The balance of address0.
uint256_balance1The balance of address1. These balances must add up to the channel's totalBalance, and will be sent to address0 and address1 when this tx is submitted.
bytes_signature0undefined
bytes_signature1undefined

function withdraw

PaymentChannels.withdraw(amount) nonpayable 2e1a7d4d

Inputs

typenamedescription
uint256amountundefined

function ecverify

PaymentChannels.ecverify(hash, sig, signer) nonpayable 39cdde32

Inputs

typenamedescription
bytes32hashundefined
bytessigundefined
addresssignerundefined

function newChannel

PaymentChannels.newChannel(_address0, _address1, _balance0, _balance1, _expiration, _settlingPeriodLength, _signature0, _signature1) nonpayable 454f7ed8

Create a new channel between two nodes. _address0 must be numerically smaller than _address1. This will generate a channelId which is used to make other transactions on this channel. It emits a ChannelOpened event which is indexed by _address0, _address1 and also contains the _channelId.

Inputs

typenamedescription
address_address0The numerically lower address of one of the channel participants.
address_address1The numerically higher address of the other channel participant.
uint256_balance0The amount that _address0 would like to lock in the channel.
uint256_balance1The amount that _address1 would like to lock in the channel. Address0 and address1 must have enough money to cover these amounts, and it is withdrawn from their accounts when this tx is submitted.
uint256_expirationThe block that this newChannel tx will expire. The purpose of the expiration is to prevent a scenario where an attacker submits an old, forgotten newChannel tx in the future, causing an unexpected withdrawal of our funds into the channel. If this is set to be too soon in the future, then it may not be possible to get this tx countersigned and onto the blockchain in time.
uint256_settlingPeriodLengthThis is the amount of time that the channel will remain in settling mode during a contentious close. If this is set too short, it may not be possible for a node (or bounty hunter) to prevent an old update attack before the settling period ends. If this is set too long, it will allow an attacker to unfairly lock up an honest node's funds for an unreasonable amount of time.
bytes_signature0undefined
bytes_signature1undefined

function quickDeposit

PaymentChannels.quickDeposit() payable 4c0f0e12

function closeChannel

PaymentChannels.closeChannel(_channelId) nonpayable 4c2ee09d

Close the channel after a settling period has been started and has ended, transfering the balances in the last updateState tx back to the participants. This is only used in a contentious closing, where startSettlingPeriod has already been called.

Inputs

typenamedescription
bytes32_channelIdThe Id of the channel to be closed.

function depositToAddress

PaymentChannels.depositToAddress(_address) payable 562cc33c

Inputs

typenamedescription
address_addressundefined

function balanceOf

PaymentChannels.balanceOf(_address) view 70a08231

Inputs

typenamedescription
address_addressundefined

function ecrecovery

PaymentChannels.ecrecovery(hash, sig) nonpayable 77d32e94

Inputs

typenamedescription
bytes32hashundefined
bytessigundefined

function channels

PaymentChannels.channels() view 7a7ebd7b

Inputs

typenamedescription
bytes32undefined

function startSettlingPeriod

PaymentChannels.startSettlingPeriod(_channelId, _signature) nonpayable d50e30ce

Start the channel's settling period. This is used in the event of a contentious channel closing, where the participants can not agree to sign a closeChannelFast tx. This only requires the signature of one of the participants.

Inputs

typenamedescription
bytes32_channelIdThe Id of the channel to settle.
bytes_signatureThe signature of address0 or address1.

function channelBetweenPairs

PaymentChannels.channelBetweenPairs(, ) view e12d11a3

Inputs

typenamedescription
addressundefined
addressundefined

function updateStateWithBounty

PaymentChannels.updateStateWithBounty(_channelId, _sequenceNumber, _balance0, _balance1, _signature0, _signature1, _bountyAmount, _bountySignature) nonpayable fa7c09da

Submit an updateTx on behalf of another node and recieve a bounty if this saves them from an old update attack.

Inputs

typenamedescription
bytes32_channelIdThe channelId of the channel to update.
uint256_sequenceNumberThe sequence number of the update. If an update with a higher sequence number has already been added, this updateState tx will fail.
uint256_balance0The balance of address0.
uint256_balance1The balance of address1. These balances must add up to the channel's totalBalance.
bytes_signature0The signature of address0 on the updateTx.
bytes_signature1The signature of address1 on the updateTx.
uint256_bountyAmountThe amount of the bounty that will be granted to the node submitting this transaction if it will prevent an old update attack on address0 or address1.
bytes_bountySignatureThe signature of the account paying the bounty.

event ChannelOpened

PaymentChannels.ChannelOpened(address0, address1, _channelId) a79f57c9

Arguments

typenamedescription
addressaddress0indexed
addressaddress1indexed
bytes32_channelIdnot indexed

event SettlingStarted

PaymentChannels.SettlingStarted(_channelId, _sequenceNumber) 3056d24b

Arguments

typenamedescription
bytes32_channelIdindexed
uint256_sequenceNumbernot indexed

event ChannelReDrawn

PaymentChannels.ChannelReDrawn(_channelId) 82e612a2

Arguments

typenamedescription
bytes32_channelIdindexed

SafeMath