-
Notifications
You must be signed in to change notification settings - Fork 45
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use ABI V2 to shorten settle arg list #1392
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
adbcbde
Use ABI V2 to shorten settle arg list
karlb 67cf44e
Shorten `ParticipantSettleInput` to `SettleInput`
karlb 4deabfd
Use `SettleInput` in `verifyBalanceHashData`
karlb 65a977e
Use `SettleInput` in `storeUnlockData`
karlb ad0a198
Compile contracts
karlb File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
pragma solidity 0.6.4; | ||
pragma experimental ABIEncoderV2; | ||
|
||
import "lib/ECVerify.sol"; | ||
import "raiden/Token.sol"; | ||
|
@@ -124,6 +125,13 @@ contract TokenNetwork is Utils { | |
uint256 locked_amount; | ||
} | ||
|
||
struct SettleInput { | ||
address participant; | ||
uint256 transferred_amount; | ||
uint256 locked_amount; | ||
bytes32 locksroot; | ||
} | ||
|
||
event ChannelOpened( | ||
uint256 indexed channel_identifier, | ||
address indexed participant1, | ||
|
@@ -692,6 +700,30 @@ contract TokenNetwork is Utils { | |
bytes32 participant2_locksroot | ||
) | ||
public | ||
{ | ||
settleChannel2( | ||
channel_identifier, | ||
SettleInput({ | ||
participant: participant1, | ||
transferred_amount: participant1_transferred_amount, | ||
locked_amount: participant1_locked_amount, | ||
locksroot: participant1_locksroot | ||
}), | ||
SettleInput({ | ||
participant: participant2, | ||
transferred_amount: participant2_transferred_amount, | ||
locked_amount: participant2_locked_amount, | ||
locksroot: participant2_locksroot | ||
}) | ||
); | ||
} | ||
|
||
function settleChannel2( | ||
uint256 channel_identifier, | ||
SettleInput memory participant1_settlement, | ||
SettleInput memory participant2_settlement | ||
) | ||
public | ||
{ | ||
// There are several requirements that this function MUST enforce: | ||
// - it MUST never fail; therefore, any overflows or underflows must be | ||
|
@@ -708,6 +740,8 @@ contract TokenNetwork is Utils { | |
// therefore it cannot ensure correctness. Users MUST use the official | ||
// Raiden clients for signing balance proofs. | ||
|
||
address participant1 = participant1_settlement.participant; | ||
address participant2 = participant2_settlement.participant; | ||
require(channel_identifier == getChannelIdentifier(participant1, participant2)); | ||
|
||
bytes32 pair_hash; | ||
|
@@ -725,16 +759,12 @@ contract TokenNetwork is Utils { | |
|
||
require(verifyBalanceHashData( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
participant1_state, | ||
participant1_transferred_amount, | ||
participant1_locked_amount, | ||
participant1_locksroot | ||
participant1_settlement | ||
)); | ||
|
||
require(verifyBalanceHashData( | ||
participant2_state, | ||
participant2_transferred_amount, | ||
participant2_locked_amount, | ||
participant2_locksroot | ||
participant2_settlement | ||
)); | ||
|
||
// We are calculating the final token amounts that need to be | ||
|
@@ -752,17 +782,17 @@ contract TokenNetwork is Utils { | |
// We are reusing variables due to the local variables number limit. | ||
// For better readability this can be refactored further. | ||
( | ||
participant1_transferred_amount, | ||
participant2_transferred_amount, | ||
participant1_locked_amount, | ||
participant2_locked_amount | ||
participant1_settlement.transferred_amount, | ||
participant2_settlement.transferred_amount, | ||
participant1_settlement.locked_amount, | ||
participant2_settlement.locked_amount | ||
) = getSettleTransferAmounts( | ||
participant1_state, | ||
participant1_transferred_amount, | ||
participant1_locked_amount, | ||
participant1_settlement.transferred_amount, | ||
participant1_settlement.locked_amount, | ||
participant2_state, | ||
participant2_transferred_amount, | ||
participant2_locked_amount | ||
participant2_settlement.transferred_amount, | ||
participant2_settlement.locked_amount | ||
); | ||
|
||
// Remove the channel data from storage | ||
|
@@ -777,34 +807,30 @@ contract TokenNetwork is Utils { | |
// locked amounts remaining in the contract. | ||
storeUnlockData( | ||
channel_identifier, | ||
participant1, | ||
participant2, | ||
participant1_locked_amount, | ||
participant1_locksroot | ||
participant1_settlement, | ||
participant2 | ||
); | ||
storeUnlockData( | ||
channel_identifier, | ||
participant2, | ||
participant1, | ||
participant2_locked_amount, | ||
participant2_locksroot | ||
participant2_settlement, | ||
participant1 | ||
); | ||
|
||
emit ChannelSettled( | ||
channel_identifier, | ||
participant1_transferred_amount, | ||
participant1_locksroot, | ||
participant2_transferred_amount, | ||
participant2_locksroot | ||
participant1_settlement.transferred_amount, | ||
participant1_settlement.locksroot, | ||
participant2_settlement.transferred_amount, | ||
participant2_settlement.locksroot | ||
); | ||
|
||
// Do the actual token transfers | ||
if (participant1_transferred_amount > 0) { | ||
require(token.transfer(participant1, participant1_transferred_amount)); | ||
if (participant1_settlement.transferred_amount > 0) { | ||
require(token.transfer(participant1, participant1_settlement.transferred_amount)); | ||
} | ||
|
||
if (participant2_transferred_amount > 0) { | ||
require(token.transfer(participant2, participant2_transferred_amount)); | ||
if (participant2_settlement.transferred_amount > 0) { | ||
require(token.transfer(participant2, participant2_settlement.transferred_amount)); | ||
} | ||
} | ||
|
||
|
@@ -1173,23 +1199,21 @@ contract TokenNetwork is Utils { | |
|
||
function storeUnlockData( | ||
uint256 channel_identifier, | ||
address sender, | ||
address receiver, | ||
uint256 locked_amount, | ||
bytes32 locksroot | ||
SettleInput memory settle_input, | ||
address receiver | ||
) | ||
internal | ||
{ | ||
// If there are transfers to unlock, store the locksroot and total | ||
// amount of tokens | ||
if (locked_amount == 0) { | ||
if (settle_input.locked_amount == 0) { | ||
return; | ||
} | ||
|
||
bytes32 key = getUnlockIdentifier(channel_identifier, sender, receiver); | ||
bytes32 key = getUnlockIdentifier(channel_identifier, settle_input.participant, receiver); | ||
UnlockData storage unlock_data = unlock_identifier_to_unlock_data[key]; | ||
unlock_data.locksroot = locksroot; | ||
unlock_data.locked_amount = locked_amount; | ||
unlock_data.locksroot = settle_input.locksroot; | ||
unlock_data.locked_amount = settle_input.locked_amount; | ||
} | ||
|
||
function getChannelAvailableDeposit( | ||
|
@@ -1455,9 +1479,7 @@ contract TokenNetwork is Utils { | |
|
||
function verifyBalanceHashData( | ||
Participant storage participant, | ||
uint256 transferred_amount, | ||
uint256 locked_amount, | ||
bytes32 locksroot | ||
SettleInput memory settle_input | ||
) | ||
internal | ||
view | ||
|
@@ -1466,8 +1488,8 @@ contract TokenNetwork is Utils { | |
// When no balance proof has been provided, we need to check this | ||
// separately because hashing values of 0 outputs a value != 0 | ||
if (participant.balance_hash == 0 && | ||
transferred_amount == 0 && | ||
locked_amount == 0 | ||
settle_input.transferred_amount == 0 && | ||
settle_input.locked_amount == 0 | ||
/* locksroot is ignored. */ | ||
) { | ||
return true; | ||
|
@@ -1476,9 +1498,9 @@ contract TokenNetwork is Utils { | |
// Make sure the hash of the provided state is the same as the stored | ||
// balance_hash | ||
return participant.balance_hash == keccak256(abi.encodePacked( | ||
transferred_amount, | ||
locked_amount, | ||
locksroot | ||
settle_input.transferred_amount, | ||
settle_input.locked_amount, | ||
settle_input.locksroot | ||
)); | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why wouldn't we change the signature for
settleChannel
as well?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah, expand-contract pattern...I see.