I've got a function with a decent number of modifiers and I hit the CompilerError: Stack too deep, try removing local variables error. If I remove one of the modifiers though, everything's all right.
It seems that modifiers get bundled into the same stack region as the function, thus increasing the size and throwing the error above. Is that a true statement? If yes, what are the best practices for handling large modifiers? That is, I don't want to create a function as a replacement, because I want to use require.
The full contract can be found here, but here's a snippet with the tricky function:
function update(
uint256 _streamId,
uint256 _stopBlock,
uint256 _payment,
uint256 _interval
)
public
payable
streamExists(_streamId)
onlyInvolvedParties(_streamId)
onlyNewTerms(_streamId, _stopBlock, _payment, _interval)
validTerms(block.number, _stopBlock, _payment, _interval)
{
shallowStackUpdate(_streamId, _stopBlock, _payment, _interval);
}
function shallowStackUpdate(
uint256 _streamId,
uint256 _stopBlock,
uint256 _payment,
uint256 _interval
)
private
{
Stream memory stream = streams[_streamId];
stop(_streamId);
create(stream.sender, stream.recipient, block.number, _stopBlock, _payment, _interval);
emit LogUpdate(streamNonce, stream.sender, stream.recipient, block.number, _stopBlock, _payment, _interval);
}
I had to write the shallowStackUpdate function to successfully compile the contract. Ideally, the two would merge into only one function.
Note: I searched SE and my situation is NOT the same with the one in the How to Fix “Stack Too Deep” Error? thread.