mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge pull request #2833 from ethereum/statemutability-builtins
Mark all built in functions with appropriate statemutability
This commit is contained in:
commit
93b1cc9702
@ -43,13 +43,13 @@ m_magicVariables(vector<shared_ptr<MagicVariableDeclaration const>>{make_shared<
|
|||||||
make_shared<MagicVariableDeclaration>("selfdestruct",
|
make_shared<MagicVariableDeclaration>("selfdestruct",
|
||||||
make_shared<FunctionType>(strings{"address"}, strings{}, FunctionType::Kind::Selfdestruct)),
|
make_shared<FunctionType>(strings{"address"}, strings{}, FunctionType::Kind::Selfdestruct)),
|
||||||
make_shared<MagicVariableDeclaration>("addmod",
|
make_shared<MagicVariableDeclaration>("addmod",
|
||||||
make_shared<FunctionType>(strings{"uint256", "uint256", "uint256"}, strings{"uint256"}, FunctionType::Kind::AddMod)),
|
make_shared<FunctionType>(strings{"uint256", "uint256", "uint256"}, strings{"uint256"}, FunctionType::Kind::AddMod, false, StateMutability::Pure)),
|
||||||
make_shared<MagicVariableDeclaration>("mulmod",
|
make_shared<MagicVariableDeclaration>("mulmod",
|
||||||
make_shared<FunctionType>(strings{"uint256", "uint256", "uint256"}, strings{"uint256"}, FunctionType::Kind::MulMod)),
|
make_shared<FunctionType>(strings{"uint256", "uint256", "uint256"}, strings{"uint256"}, FunctionType::Kind::MulMod, false, StateMutability::Pure)),
|
||||||
make_shared<MagicVariableDeclaration>("sha3",
|
make_shared<MagicVariableDeclaration>("sha3",
|
||||||
make_shared<FunctionType>(strings(), strings{"bytes32"}, FunctionType::Kind::SHA3, true)),
|
make_shared<FunctionType>(strings(), strings{"bytes32"}, FunctionType::Kind::SHA3, true, StateMutability::Pure)),
|
||||||
make_shared<MagicVariableDeclaration>("keccak256",
|
make_shared<MagicVariableDeclaration>("keccak256",
|
||||||
make_shared<FunctionType>(strings(), strings{"bytes32"}, FunctionType::Kind::SHA3, true)),
|
make_shared<FunctionType>(strings(), strings{"bytes32"}, FunctionType::Kind::SHA3, true, StateMutability::Pure)),
|
||||||
make_shared<MagicVariableDeclaration>("log0",
|
make_shared<MagicVariableDeclaration>("log0",
|
||||||
make_shared<FunctionType>(strings{"bytes32"}, strings{}, FunctionType::Kind::Log0)),
|
make_shared<FunctionType>(strings{"bytes32"}, strings{}, FunctionType::Kind::Log0)),
|
||||||
make_shared<MagicVariableDeclaration>("log1",
|
make_shared<MagicVariableDeclaration>("log1",
|
||||||
@ -61,17 +61,17 @@ m_magicVariables(vector<shared_ptr<MagicVariableDeclaration const>>{make_shared<
|
|||||||
make_shared<MagicVariableDeclaration>("log4",
|
make_shared<MagicVariableDeclaration>("log4",
|
||||||
make_shared<FunctionType>(strings{"bytes32", "bytes32", "bytes32", "bytes32", "bytes32"}, strings{}, FunctionType::Kind::Log4)),
|
make_shared<FunctionType>(strings{"bytes32", "bytes32", "bytes32", "bytes32", "bytes32"}, strings{}, FunctionType::Kind::Log4)),
|
||||||
make_shared<MagicVariableDeclaration>("sha256",
|
make_shared<MagicVariableDeclaration>("sha256",
|
||||||
make_shared<FunctionType>(strings(), strings{"bytes32"}, FunctionType::Kind::SHA256, true)),
|
make_shared<FunctionType>(strings(), strings{"bytes32"}, FunctionType::Kind::SHA256, true, StateMutability::Pure)),
|
||||||
make_shared<MagicVariableDeclaration>("ecrecover",
|
make_shared<MagicVariableDeclaration>("ecrecover",
|
||||||
make_shared<FunctionType>(strings{"bytes32", "uint8", "bytes32", "bytes32"}, strings{"address"}, FunctionType::Kind::ECRecover)),
|
make_shared<FunctionType>(strings{"bytes32", "uint8", "bytes32", "bytes32"}, strings{"address"}, FunctionType::Kind::ECRecover, false, StateMutability::Pure)),
|
||||||
make_shared<MagicVariableDeclaration>("ripemd160",
|
make_shared<MagicVariableDeclaration>("ripemd160",
|
||||||
make_shared<FunctionType>(strings(), strings{"bytes20"}, FunctionType::Kind::RIPEMD160, true)),
|
make_shared<FunctionType>(strings(), strings{"bytes20"}, FunctionType::Kind::RIPEMD160, true, StateMutability::Pure)),
|
||||||
make_shared<MagicVariableDeclaration>("assert",
|
make_shared<MagicVariableDeclaration>("assert",
|
||||||
make_shared<FunctionType>(strings{"bool"}, strings{}, FunctionType::Kind::Assert)),
|
make_shared<FunctionType>(strings{"bool"}, strings{}, FunctionType::Kind::Assert, false, StateMutability::Pure)),
|
||||||
make_shared<MagicVariableDeclaration>("require",
|
make_shared<MagicVariableDeclaration>("require",
|
||||||
make_shared<FunctionType>(strings{"bool"}, strings{}, FunctionType::Kind::Require)),
|
make_shared<FunctionType>(strings{"bool"}, strings{}, FunctionType::Kind::Require, false, StateMutability::Pure)),
|
||||||
make_shared<MagicVariableDeclaration>("revert",
|
make_shared<MagicVariableDeclaration>("revert",
|
||||||
make_shared<FunctionType>(strings(), strings(), FunctionType::Kind::Revert))})
|
make_shared<FunctionType>(strings(), strings(), FunctionType::Kind::Revert, false, StateMutability::Pure))})
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1626,7 +1626,9 @@ void TypeChecker::endVisit(NewExpression const& _newExpression)
|
|||||||
TypePointers{type},
|
TypePointers{type},
|
||||||
strings(),
|
strings(),
|
||||||
strings(),
|
strings(),
|
||||||
FunctionType::Kind::ObjectCreation
|
FunctionType::Kind::ObjectCreation,
|
||||||
|
false,
|
||||||
|
StateMutability::Pure
|
||||||
);
|
);
|
||||||
_newExpression.annotation().isPure = true;
|
_newExpression.annotation().isPure = true;
|
||||||
}
|
}
|
||||||
|
@ -2169,7 +2169,6 @@ FunctionTypePointer FunctionType::newExpressionType(ContractDefinition const& _c
|
|||||||
strings{""},
|
strings{""},
|
||||||
Kind::Creation,
|
Kind::Creation,
|
||||||
false,
|
false,
|
||||||
nullptr,
|
|
||||||
stateMutability
|
stateMutability
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -2421,8 +2420,8 @@ FunctionTypePointer FunctionType::interfaceFunctionType() const
|
|||||||
m_returnParameterNames,
|
m_returnParameterNames,
|
||||||
m_kind,
|
m_kind,
|
||||||
m_arbitraryParameters,
|
m_arbitraryParameters,
|
||||||
m_declaration,
|
m_stateMutability,
|
||||||
m_stateMutability
|
m_declaration
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2449,8 +2448,8 @@ MemberList::MemberMap FunctionType::nativeMembers(ContractDefinition const*) con
|
|||||||
strings(),
|
strings(),
|
||||||
Kind::SetValue,
|
Kind::SetValue,
|
||||||
false,
|
false,
|
||||||
nullptr,
|
|
||||||
StateMutability::NonPayable,
|
StateMutability::NonPayable,
|
||||||
|
nullptr,
|
||||||
m_gasSet,
|
m_gasSet,
|
||||||
m_valueSet
|
m_valueSet
|
||||||
)
|
)
|
||||||
@ -2466,8 +2465,8 @@ MemberList::MemberMap FunctionType::nativeMembers(ContractDefinition const*) con
|
|||||||
strings(),
|
strings(),
|
||||||
Kind::SetGas,
|
Kind::SetGas,
|
||||||
false,
|
false,
|
||||||
nullptr,
|
|
||||||
StateMutability::NonPayable,
|
StateMutability::NonPayable,
|
||||||
|
nullptr,
|
||||||
m_gasSet,
|
m_gasSet,
|
||||||
m_valueSet
|
m_valueSet
|
||||||
)
|
)
|
||||||
@ -2574,6 +2573,8 @@ u256 FunctionType::externalIdentifier() const
|
|||||||
|
|
||||||
bool FunctionType::isPure() const
|
bool FunctionType::isPure() const
|
||||||
{
|
{
|
||||||
|
// FIXME: replace this with m_stateMutability == StateMutability::Pure once
|
||||||
|
// the callgraph analyzer is in place
|
||||||
return
|
return
|
||||||
m_kind == Kind::SHA3 ||
|
m_kind == Kind::SHA3 ||
|
||||||
m_kind == Kind::ECRecover ||
|
m_kind == Kind::ECRecover ||
|
||||||
@ -2602,8 +2603,8 @@ TypePointer FunctionType::copyAndSetGasOrValue(bool _setGas, bool _setValue) con
|
|||||||
m_returnParameterNames,
|
m_returnParameterNames,
|
||||||
m_kind,
|
m_kind,
|
||||||
m_arbitraryParameters,
|
m_arbitraryParameters,
|
||||||
m_declaration,
|
|
||||||
m_stateMutability,
|
m_stateMutability,
|
||||||
|
m_declaration,
|
||||||
m_gasSet || _setGas,
|
m_gasSet || _setGas,
|
||||||
m_valueSet || _setValue,
|
m_valueSet || _setValue,
|
||||||
m_bound
|
m_bound
|
||||||
@ -2651,8 +2652,8 @@ FunctionTypePointer FunctionType::asMemberFunction(bool _inLibrary, bool _bound)
|
|||||||
m_returnParameterNames,
|
m_returnParameterNames,
|
||||||
kind,
|
kind,
|
||||||
m_arbitraryParameters,
|
m_arbitraryParameters,
|
||||||
m_declaration,
|
|
||||||
m_stateMutability,
|
m_stateMutability,
|
||||||
|
m_declaration,
|
||||||
m_gasSet,
|
m_gasSet,
|
||||||
m_valueSet,
|
m_valueSet,
|
||||||
_bound
|
_bound
|
||||||
@ -2870,7 +2871,7 @@ MemberList::MemberMap MagicType::nativeMembers(ContractDefinition const*) const
|
|||||||
return MemberList::MemberMap({
|
return MemberList::MemberMap({
|
||||||
{"coinbase", make_shared<IntegerType>(0, IntegerType::Modifier::Address)},
|
{"coinbase", make_shared<IntegerType>(0, IntegerType::Modifier::Address)},
|
||||||
{"timestamp", make_shared<IntegerType>(256)},
|
{"timestamp", make_shared<IntegerType>(256)},
|
||||||
{"blockhash", make_shared<FunctionType>(strings{"uint"}, strings{"bytes32"}, FunctionType::Kind::BlockHash)},
|
{"blockhash", make_shared<FunctionType>(strings{"uint"}, strings{"bytes32"}, FunctionType::Kind::BlockHash, false, StateMutability::View)},
|
||||||
{"difficulty", make_shared<IntegerType>(256)},
|
{"difficulty", make_shared<IntegerType>(256)},
|
||||||
{"number", make_shared<IntegerType>(256)},
|
{"number", make_shared<IntegerType>(256)},
|
||||||
{"gaslimit", make_shared<IntegerType>(256)}
|
{"gaslimit", make_shared<IntegerType>(256)}
|
||||||
|
@ -899,7 +899,6 @@ public:
|
|||||||
strings(),
|
strings(),
|
||||||
_kind,
|
_kind,
|
||||||
_arbitraryParameters,
|
_arbitraryParameters,
|
||||||
nullptr,
|
|
||||||
_stateMutability
|
_stateMutability
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
@ -916,8 +915,8 @@ public:
|
|||||||
strings _returnParameterNames = strings(),
|
strings _returnParameterNames = strings(),
|
||||||
Kind _kind = Kind::Internal,
|
Kind _kind = Kind::Internal,
|
||||||
bool _arbitraryParameters = false,
|
bool _arbitraryParameters = false,
|
||||||
Declaration const* _declaration = nullptr,
|
|
||||||
StateMutability _stateMutability = StateMutability::NonPayable,
|
StateMutability _stateMutability = StateMutability::NonPayable,
|
||||||
|
Declaration const* _declaration = nullptr,
|
||||||
bool _gasSet = false,
|
bool _gasSet = false,
|
||||||
bool _valueSet = false,
|
bool _valueSet = false,
|
||||||
bool _bound = false
|
bool _bound = false
|
||||||
|
@ -644,8 +644,8 @@ bool ExpressionCompiler::visit(FunctionCall const& _functionCall)
|
|||||||
strings(),
|
strings(),
|
||||||
FunctionType::Kind::BareCall,
|
FunctionType::Kind::BareCall,
|
||||||
false,
|
false,
|
||||||
nullptr,
|
|
||||||
StateMutability::NonPayable,
|
StateMutability::NonPayable,
|
||||||
|
nullptr,
|
||||||
true,
|
true,
|
||||||
true
|
true
|
||||||
),
|
),
|
||||||
|
Loading…
Reference in New Issue
Block a user