-
Notifications
You must be signed in to change notification settings - Fork 6.1k
Use STATICCALL for pure function calls. #2966
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1610,6 +1610,10 @@ void ExpressionCompiler::appendExternalFunctionCall( | |
| bool returnSuccessCondition = funKind == FunctionType::Kind::BareCall || funKind == FunctionType::Kind::BareCallCode || funKind == FunctionType::Kind::BareDelegateCall; | ||
| bool isCallCode = funKind == FunctionType::Kind::BareCallCode || funKind == FunctionType::Kind::CallCode; | ||
| bool isDelegateCall = funKind == FunctionType::Kind::BareDelegateCall || funKind == FunctionType::Kind::DelegateCall; | ||
| bool useStaticCall = | ||
| _functionType.stateMutability() <= StateMutability::View && | ||
| m_context.experimentalFeatureActive(ExperimentalFeature::V050) && | ||
|
Contributor
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. Actually this contradicts #3600.
Contributor
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. Do we really need this line? We should just enable it based on the EMV version (which we also have as a condition below).
Contributor
Author
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. We perform changes in codegen from time to time without requiring a breaking release. The condition for that is that the actual semantics visible from outside do not change. This is only the case if people do not perform invalid type conversions and if they use the most recent EVM version. I think it is fine to assume the latter, so we can just remove it. We should highlight that in the release notes.
Contributor
Author
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. Ok but actually arguing the other way around: If we remove this condition, then we actually assume that it is perfectly fine to use. This means it is not an experimental feature. In turn, we don't have to warn about using experimental 0.5.0.
Contributor
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. Copying this from the channel for the record:
Luckily, the Though it is kind of a breaking change because if they disregard the warning the output will not work. |
||
| m_context.evmVersion().hasStaticCall(); | ||
|
|
||
| unsigned retSize = 0; | ||
| if (returnSuccessCondition) | ||
|
|
@@ -1738,6 +1742,8 @@ void ExpressionCompiler::appendExternalFunctionCall( | |
| // [value,] addr, gas (stack top) | ||
| if (isDelegateCall) | ||
| solAssert(!_functionType.valueSet(), "Value set for delegatecall"); | ||
| else if (useStaticCall) | ||
| solAssert(!_functionType.valueSet(), "Value set for staticcall"); | ||
| else if (_functionType.valueSet()) | ||
| m_context << dupInstruction(m_context.baseToCurrentStackOffset(valueStackPos)); | ||
| else | ||
|
|
@@ -1769,10 +1775,13 @@ void ExpressionCompiler::appendExternalFunctionCall( | |
| gasNeededByCaller += eth::GasCosts::callNewAccountGas; // we never know | ||
| m_context << gasNeededByCaller << Instruction::GAS << Instruction::SUB; | ||
| } | ||
| // Order is important here, STATICCALL might overlap with DELEGATECALL. | ||
| if (isDelegateCall) | ||
| m_context << Instruction::DELEGATECALL; | ||
| else if (isCallCode) | ||
| m_context << Instruction::CALLCODE; | ||
| else if (useStaticCall) | ||
| m_context << Instruction::STATICCALL; | ||
| else | ||
| m_context << Instruction::CALL; | ||
|
|
||
|
|
||
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.
I think
usesuits this better, but the other two are namedisso perhaps just go withisStaticCallor alternatively rename the other two touse?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.
It's a different thing. I would call it
isStaticCallout of the function type, butuseStaticCalltells whether the compiler is also allowed to use the opcode due to pragmas.