From aa94000a91be455af7b9436db172ffa86cc57494 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Mon, 28 Aug 2017 13:35:28 +0100 Subject: Mark all built in functions with appropriate statemutability --- libsolidity/analysis/GlobalContext.cpp | 20 ++++++++++---------- libsolidity/analysis/TypeChecker.cpp | 5 ++++- libsolidity/ast/Types.cpp | 4 +++- 3 files changed, 17 insertions(+), 12 deletions(-) diff --git a/libsolidity/analysis/GlobalContext.cpp b/libsolidity/analysis/GlobalContext.cpp index a54b8c8d..62dbd394 100644 --- a/libsolidity/analysis/GlobalContext.cpp +++ b/libsolidity/analysis/GlobalContext.cpp @@ -43,13 +43,13 @@ m_magicVariables(vector>{make_shared< make_shared("selfdestruct", make_shared(strings{"address"}, strings{}, FunctionType::Kind::Selfdestruct)), make_shared("addmod", - make_shared(strings{"uint256", "uint256", "uint256"}, strings{"uint256"}, FunctionType::Kind::AddMod)), + make_shared(strings{"uint256", "uint256", "uint256"}, strings{"uint256"}, FunctionType::Kind::AddMod, false, StateMutability::Pure)), make_shared("mulmod", - make_shared(strings{"uint256", "uint256", "uint256"}, strings{"uint256"}, FunctionType::Kind::MulMod)), + make_shared(strings{"uint256", "uint256", "uint256"}, strings{"uint256"}, FunctionType::Kind::MulMod, false, StateMutability::Pure)), make_shared("sha3", - make_shared(strings(), strings{"bytes32"}, FunctionType::Kind::SHA3, true)), + make_shared(strings(), strings{"bytes32"}, FunctionType::Kind::SHA3, true, StateMutability::Pure)), make_shared("keccak256", - make_shared(strings(), strings{"bytes32"}, FunctionType::Kind::SHA3, true)), + make_shared(strings(), strings{"bytes32"}, FunctionType::Kind::SHA3, true, StateMutability::Pure)), make_shared("log0", make_shared(strings{"bytes32"}, strings{}, FunctionType::Kind::Log0)), make_shared("log1", @@ -61,17 +61,17 @@ m_magicVariables(vector>{make_shared< make_shared("log4", make_shared(strings{"bytes32", "bytes32", "bytes32", "bytes32", "bytes32"}, strings{}, FunctionType::Kind::Log4)), make_shared("sha256", - make_shared(strings(), strings{"bytes32"}, FunctionType::Kind::SHA256, true)), + make_shared(strings(), strings{"bytes32"}, FunctionType::Kind::SHA256, true, StateMutability::Pure)), make_shared("ecrecover", - make_shared(strings{"bytes32", "uint8", "bytes32", "bytes32"}, strings{"address"}, FunctionType::Kind::ECRecover)), + make_shared(strings{"bytes32", "uint8", "bytes32", "bytes32"}, strings{"address"}, FunctionType::Kind::ECRecover, false, StateMutability::Pure)), make_shared("ripemd160", - make_shared(strings(), strings{"bytes20"}, FunctionType::Kind::RIPEMD160, true)), + make_shared(strings(), strings{"bytes20"}, FunctionType::Kind::RIPEMD160, true, StateMutability::Pure)), make_shared("assert", - make_shared(strings{"bool"}, strings{}, FunctionType::Kind::Assert)), + make_shared(strings{"bool"}, strings{}, FunctionType::Kind::Assert, false, StateMutability::Pure)), make_shared("require", - make_shared(strings{"bool"}, strings{}, FunctionType::Kind::Require)), + make_shared(strings{"bool"}, strings{}, FunctionType::Kind::Require, false, StateMutability::Pure)), make_shared("revert", - make_shared(strings(), strings(), FunctionType::Kind::Revert))}) + make_shared(strings(), strings(), FunctionType::Kind::Revert, false, StateMutability::Pure))}) { } diff --git a/libsolidity/analysis/TypeChecker.cpp b/libsolidity/analysis/TypeChecker.cpp index d594a060..c70b0497 100644 --- a/libsolidity/analysis/TypeChecker.cpp +++ b/libsolidity/analysis/TypeChecker.cpp @@ -1626,7 +1626,10 @@ void TypeChecker::endVisit(NewExpression const& _newExpression) TypePointers{type}, strings(), strings(), - FunctionType::Kind::ObjectCreation + FunctionType::Kind::ObjectCreation, + false, + nullptr, + StateMutability::Pure ); _newExpression.annotation().isPure = true; } diff --git a/libsolidity/ast/Types.cpp b/libsolidity/ast/Types.cpp index 65b09840..4bffd9a5 100644 --- a/libsolidity/ast/Types.cpp +++ b/libsolidity/ast/Types.cpp @@ -2569,6 +2569,8 @@ u256 FunctionType::externalIdentifier() const bool FunctionType::isPure() const { + // FIXME: replace this with m_stateMutability == StateMutability::Pure once + // the callgraph analyzer is in place return m_kind == Kind::SHA3 || m_kind == Kind::ECRecover || @@ -2865,7 +2867,7 @@ MemberList::MemberMap MagicType::nativeMembers(ContractDefinition const*) const return MemberList::MemberMap({ {"coinbase", make_shared(0, IntegerType::Modifier::Address)}, {"timestamp", make_shared(256)}, - {"blockhash", make_shared(strings{"uint"}, strings{"bytes32"}, FunctionType::Kind::BlockHash)}, + {"blockhash", make_shared(strings{"uint"}, strings{"bytes32"}, FunctionType::Kind::BlockHash, false, StateMutability::View)}, {"difficulty", make_shared(256)}, {"number", make_shared(256)}, {"gaslimit", make_shared(256)} -- cgit From 79e84a8fa43b55838100f9c24dec04b1e721c65c Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Mon, 28 Aug 2017 14:40:28 +0100 Subject: Swap declaration/statemutability in FunctionType constructor --- libsolidity/analysis/TypeChecker.cpp | 1 - libsolidity/ast/Types.cpp | 13 ++++++------- libsolidity/ast/Types.h | 3 +-- libsolidity/codegen/ExpressionCompiler.cpp | 2 +- 4 files changed, 8 insertions(+), 11 deletions(-) diff --git a/libsolidity/analysis/TypeChecker.cpp b/libsolidity/analysis/TypeChecker.cpp index c70b0497..7d5a0c8c 100644 --- a/libsolidity/analysis/TypeChecker.cpp +++ b/libsolidity/analysis/TypeChecker.cpp @@ -1628,7 +1628,6 @@ void TypeChecker::endVisit(NewExpression const& _newExpression) strings(), FunctionType::Kind::ObjectCreation, false, - nullptr, StateMutability::Pure ); _newExpression.annotation().isPure = true; diff --git a/libsolidity/ast/Types.cpp b/libsolidity/ast/Types.cpp index 4bffd9a5..22751c45 100644 --- a/libsolidity/ast/Types.cpp +++ b/libsolidity/ast/Types.cpp @@ -2164,7 +2164,6 @@ FunctionTypePointer FunctionType::newExpressionType(ContractDefinition const& _c strings{""}, Kind::Creation, false, - nullptr, stateMutability ); } @@ -2416,8 +2415,8 @@ FunctionTypePointer FunctionType::interfaceFunctionType() const m_returnParameterNames, m_kind, m_arbitraryParameters, - m_declaration, - m_stateMutability + m_stateMutability, + m_declaration ); } @@ -2444,8 +2443,8 @@ MemberList::MemberMap FunctionType::nativeMembers(ContractDefinition const*) con strings(), Kind::SetValue, false, - nullptr, StateMutability::NonPayable, + nullptr, m_gasSet, m_valueSet ) @@ -2461,8 +2460,8 @@ MemberList::MemberMap FunctionType::nativeMembers(ContractDefinition const*) con strings(), Kind::SetGas, false, - nullptr, StateMutability::NonPayable, + nullptr, m_gasSet, m_valueSet ) @@ -2599,8 +2598,8 @@ TypePointer FunctionType::copyAndSetGasOrValue(bool _setGas, bool _setValue) con m_returnParameterNames, m_kind, m_arbitraryParameters, - m_declaration, m_stateMutability, + m_declaration, m_gasSet || _setGas, m_valueSet || _setValue, m_bound @@ -2648,8 +2647,8 @@ FunctionTypePointer FunctionType::asMemberFunction(bool _inLibrary, bool _bound) m_returnParameterNames, kind, m_arbitraryParameters, - m_declaration, m_stateMutability, + m_declaration, m_gasSet, m_valueSet, _bound diff --git a/libsolidity/ast/Types.h b/libsolidity/ast/Types.h index 310c34fe..de6dcee9 100644 --- a/libsolidity/ast/Types.h +++ b/libsolidity/ast/Types.h @@ -899,7 +899,6 @@ public: strings(), _kind, _arbitraryParameters, - nullptr, _stateMutability ) { @@ -916,8 +915,8 @@ public: strings _returnParameterNames = strings(), Kind _kind = Kind::Internal, bool _arbitraryParameters = false, - Declaration const* _declaration = nullptr, StateMutability _stateMutability = StateMutability::NonPayable, + Declaration const* _declaration = nullptr, bool _gasSet = false, bool _valueSet = false, bool _bound = false diff --git a/libsolidity/codegen/ExpressionCompiler.cpp b/libsolidity/codegen/ExpressionCompiler.cpp index 45c2170c..5c9b743a 100644 --- a/libsolidity/codegen/ExpressionCompiler.cpp +++ b/libsolidity/codegen/ExpressionCompiler.cpp @@ -644,8 +644,8 @@ bool ExpressionCompiler::visit(FunctionCall const& _functionCall) strings(), FunctionType::Kind::BareCall, false, - nullptr, StateMutability::NonPayable, + nullptr, true, true ), -- cgit