-
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
Assess code splitting for core contracts (libraries, proxies etc.) #215
Comments
As mentioned above, there are two main issues: Possible solutions for A:1.
|
function getMaxPossibleReceivableAmount( | |
SettlementData participant1_settlement, | |
SettlementData participant2_settlement | |
) |
The stack too deep
issue when adding modifiers appeared with settleChannel
, updateNonClosingBalanceProof
, cooperativeSettle
. So, these would look like:
// NOW:
function settleChannel(
uint256 channel_identifier,
address participant1,
uint256 participant1_transferred_amount,
uint256 participant1_locked_amount,
bytes32 participant1_locksroot,
address participant2,
uint256 participant2_transferred_amount,
uint256 participant2_locked_amount,
bytes32 participant2_locksroot
)
// AFTER:
struct SettlementData {
address participant;
uint256 transferred;
uint256 locked;
bytes32 locksroot;
}
function settleChannel(
uint256 channel_identifier,
SettlementData participant1,
SettlementData participant2
)
// NOW:
function updateNonClosingBalanceProof(
uint256 channel_identifier,
address closing_participant,
address non_closing_participant,
bytes32 balance_hash,
uint256 nonce,
bytes32 additional_hash,
bytes closing_signature,
bytes non_closing_signature
)
// AFTER
struct BalanceData {
bytes32 balance_hash;
uint256 nonce;
bytes32 additional_hash;
bytes closing_signature;
}
function updateNonClosingBalanceProof(
uint256 channel_identifier,
address closing_participant,
address non_closing_participant,
BalanceData balance_data,
bytes non_closing_signature
)
// NOW:
function cooperativeSettle(
uint256 channel_identifier,
address participant1_address,
uint256 participant1_balance,
address participant2_address,
uint256 participant2_balance,
bytes participant1_signature,
bytes participant2_signature
)
// AFTER:
struct CooperativeSettlementData {
address participant1_address;
uint256 participant1_balance;
address participant2_address;
uint256 participant2_balance;
}
function cooperativeSettle(
uint256 channel_identifier,
CooperativeSettlementData coop_settlement_data,
bytes participant1_signature,
bytes participant2_signature
)
2. Functions instead of modifiers
Instead of using modifiers, which keep the stack occupied until the function call is finished, we could use normal functions, that we always call first (code style to enforce readability and security). These would not fill up the main stack.
Team retreat November - we scoped out upgradability and decided to go with the approach suggested in #264 (splitting |
Opened #401 for the current Ithaca solution mentioned in #215 (comment). |
(In work issue)
tl;dr Code splitting with libraries and/or proxies could make the code cleaner.
Feature requested for a while. Latest discussion: #213 (comment)
History
Initial contracts from the
raiden
repo https://github.com/raiden-network/raiden/tree/9e12805fccf777cda8446b33842ad7ca3215d6c8/raiden/smart_contracts had a structure based on libraries.This does not exist in the current contracts.
My main reasons for not keeping it in the raiden-network/raiden#1286 refactoring:
Therefore, I thought it might be better for the contracts development to handle this issue after the protocol is stable and we have time to research other patterns.
Current issues
we are facing that might be solved with better code splitting:
TokenNetwork
contract has the oldNettingChannel
andChannelManager
combined in a single contract. Therefore, this can happen: Add revert error strings for TokenNetwork #213 (comment)TokenNetworkRegistry
contract imports theTokenNetwork
contract and deployment is> 5mil gas
, with an expensive token network creation>3mil gas
stack
faster. E.g.updateNonClosingBalanceProof
,settleChannel
,cooperativeSettle
. This currently prevents us to have clean state modifiers Ideally, we should use modifiers for function input checks #197Known existing solutions:
TODO: properly document known existing solutions.
The text was updated successfully, but these errors were encountered: