Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 93b1cc9

Browse files
authored
Merge pull request argotorg#2833 from ethereum/statemutability-builtins
Mark all built in functions with appropriate statemutability
2 parents e77e594 + 79e84a8 commit 93b1cc9

File tree

5 files changed

+24
-22
lines changed

5 files changed

+24
-22
lines changed

libsolidity/analysis/GlobalContext.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,13 @@ m_magicVariables(vector<shared_ptr<MagicVariableDeclaration const>>{make_shared<
4343
make_shared<MagicVariableDeclaration>("selfdestruct",
4444
make_shared<FunctionType>(strings{"address"}, strings{}, FunctionType::Kind::Selfdestruct)),
4545
make_shared<MagicVariableDeclaration>("addmod",
46-
make_shared<FunctionType>(strings{"uint256", "uint256", "uint256"}, strings{"uint256"}, FunctionType::Kind::AddMod)),
46+
make_shared<FunctionType>(strings{"uint256", "uint256", "uint256"}, strings{"uint256"}, FunctionType::Kind::AddMod, false, StateMutability::Pure)),
4747
make_shared<MagicVariableDeclaration>("mulmod",
48-
make_shared<FunctionType>(strings{"uint256", "uint256", "uint256"}, strings{"uint256"}, FunctionType::Kind::MulMod)),
48+
make_shared<FunctionType>(strings{"uint256", "uint256", "uint256"}, strings{"uint256"}, FunctionType::Kind::MulMod, false, StateMutability::Pure)),
4949
make_shared<MagicVariableDeclaration>("sha3",
50-
make_shared<FunctionType>(strings(), strings{"bytes32"}, FunctionType::Kind::SHA3, true)),
50+
make_shared<FunctionType>(strings(), strings{"bytes32"}, FunctionType::Kind::SHA3, true, StateMutability::Pure)),
5151
make_shared<MagicVariableDeclaration>("keccak256",
52-
make_shared<FunctionType>(strings(), strings{"bytes32"}, FunctionType::Kind::SHA3, true)),
52+
make_shared<FunctionType>(strings(), strings{"bytes32"}, FunctionType::Kind::SHA3, true, StateMutability::Pure)),
5353
make_shared<MagicVariableDeclaration>("log0",
5454
make_shared<FunctionType>(strings{"bytes32"}, strings{}, FunctionType::Kind::Log0)),
5555
make_shared<MagicVariableDeclaration>("log1",
@@ -61,17 +61,17 @@ m_magicVariables(vector<shared_ptr<MagicVariableDeclaration const>>{make_shared<
6161
make_shared<MagicVariableDeclaration>("log4",
6262
make_shared<FunctionType>(strings{"bytes32", "bytes32", "bytes32", "bytes32", "bytes32"}, strings{}, FunctionType::Kind::Log4)),
6363
make_shared<MagicVariableDeclaration>("sha256",
64-
make_shared<FunctionType>(strings(), strings{"bytes32"}, FunctionType::Kind::SHA256, true)),
64+
make_shared<FunctionType>(strings(), strings{"bytes32"}, FunctionType::Kind::SHA256, true, StateMutability::Pure)),
6565
make_shared<MagicVariableDeclaration>("ecrecover",
66-
make_shared<FunctionType>(strings{"bytes32", "uint8", "bytes32", "bytes32"}, strings{"address"}, FunctionType::Kind::ECRecover)),
66+
make_shared<FunctionType>(strings{"bytes32", "uint8", "bytes32", "bytes32"}, strings{"address"}, FunctionType::Kind::ECRecover, false, StateMutability::Pure)),
6767
make_shared<MagicVariableDeclaration>("ripemd160",
68-
make_shared<FunctionType>(strings(), strings{"bytes20"}, FunctionType::Kind::RIPEMD160, true)),
68+
make_shared<FunctionType>(strings(), strings{"bytes20"}, FunctionType::Kind::RIPEMD160, true, StateMutability::Pure)),
6969
make_shared<MagicVariableDeclaration>("assert",
70-
make_shared<FunctionType>(strings{"bool"}, strings{}, FunctionType::Kind::Assert)),
70+
make_shared<FunctionType>(strings{"bool"}, strings{}, FunctionType::Kind::Assert, false, StateMutability::Pure)),
7171
make_shared<MagicVariableDeclaration>("require",
72-
make_shared<FunctionType>(strings{"bool"}, strings{}, FunctionType::Kind::Require)),
72+
make_shared<FunctionType>(strings{"bool"}, strings{}, FunctionType::Kind::Require, false, StateMutability::Pure)),
7373
make_shared<MagicVariableDeclaration>("revert",
74-
make_shared<FunctionType>(strings(), strings(), FunctionType::Kind::Revert))})
74+
make_shared<FunctionType>(strings(), strings(), FunctionType::Kind::Revert, false, StateMutability::Pure))})
7575
{
7676
}
7777

libsolidity/analysis/TypeChecker.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1626,7 +1626,9 @@ void TypeChecker::endVisit(NewExpression const& _newExpression)
16261626
TypePointers{type},
16271627
strings(),
16281628
strings(),
1629-
FunctionType::Kind::ObjectCreation
1629+
FunctionType::Kind::ObjectCreation,
1630+
false,
1631+
StateMutability::Pure
16301632
);
16311633
_newExpression.annotation().isPure = true;
16321634
}

libsolidity/ast/Types.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2169,7 +2169,6 @@ FunctionTypePointer FunctionType::newExpressionType(ContractDefinition const& _c
21692169
strings{""},
21702170
Kind::Creation,
21712171
false,
2172-
nullptr,
21732172
stateMutability
21742173
);
21752174
}
@@ -2421,8 +2420,8 @@ FunctionTypePointer FunctionType::interfaceFunctionType() const
24212420
m_returnParameterNames,
24222421
m_kind,
24232422
m_arbitraryParameters,
2424-
m_declaration,
2425-
m_stateMutability
2423+
m_stateMutability,
2424+
m_declaration
24262425
);
24272426
}
24282427

@@ -2449,8 +2448,8 @@ MemberList::MemberMap FunctionType::nativeMembers(ContractDefinition const*) con
24492448
strings(),
24502449
Kind::SetValue,
24512450
false,
2452-
nullptr,
24532451
StateMutability::NonPayable,
2452+
nullptr,
24542453
m_gasSet,
24552454
m_valueSet
24562455
)
@@ -2466,8 +2465,8 @@ MemberList::MemberMap FunctionType::nativeMembers(ContractDefinition const*) con
24662465
strings(),
24672466
Kind::SetGas,
24682467
false,
2469-
nullptr,
24702468
StateMutability::NonPayable,
2469+
nullptr,
24712470
m_gasSet,
24722471
m_valueSet
24732472
)
@@ -2574,6 +2573,8 @@ u256 FunctionType::externalIdentifier() const
25742573

25752574
bool FunctionType::isPure() const
25762575
{
2576+
// FIXME: replace this with m_stateMutability == StateMutability::Pure once
2577+
// the callgraph analyzer is in place
25772578
return
25782579
m_kind == Kind::SHA3 ||
25792580
m_kind == Kind::ECRecover ||
@@ -2602,8 +2603,8 @@ TypePointer FunctionType::copyAndSetGasOrValue(bool _setGas, bool _setValue) con
26022603
m_returnParameterNames,
26032604
m_kind,
26042605
m_arbitraryParameters,
2605-
m_declaration,
26062606
m_stateMutability,
2607+
m_declaration,
26072608
m_gasSet || _setGas,
26082609
m_valueSet || _setValue,
26092610
m_bound
@@ -2651,8 +2652,8 @@ FunctionTypePointer FunctionType::asMemberFunction(bool _inLibrary, bool _bound)
26512652
m_returnParameterNames,
26522653
kind,
26532654
m_arbitraryParameters,
2654-
m_declaration,
26552655
m_stateMutability,
2656+
m_declaration,
26562657
m_gasSet,
26572658
m_valueSet,
26582659
_bound
@@ -2870,7 +2871,7 @@ MemberList::MemberMap MagicType::nativeMembers(ContractDefinition const*) const
28702871
return MemberList::MemberMap({
28712872
{"coinbase", make_shared<IntegerType>(0, IntegerType::Modifier::Address)},
28722873
{"timestamp", make_shared<IntegerType>(256)},
2873-
{"blockhash", make_shared<FunctionType>(strings{"uint"}, strings{"bytes32"}, FunctionType::Kind::BlockHash)},
2874+
{"blockhash", make_shared<FunctionType>(strings{"uint"}, strings{"bytes32"}, FunctionType::Kind::BlockHash, false, StateMutability::View)},
28742875
{"difficulty", make_shared<IntegerType>(256)},
28752876
{"number", make_shared<IntegerType>(256)},
28762877
{"gaslimit", make_shared<IntegerType>(256)}

libsolidity/ast/Types.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -899,7 +899,6 @@ class FunctionType: public Type
899899
strings(),
900900
_kind,
901901
_arbitraryParameters,
902-
nullptr,
903902
_stateMutability
904903
)
905904
{
@@ -916,8 +915,8 @@ class FunctionType: public Type
916915
strings _returnParameterNames = strings(),
917916
Kind _kind = Kind::Internal,
918917
bool _arbitraryParameters = false,
919-
Declaration const* _declaration = nullptr,
920918
StateMutability _stateMutability = StateMutability::NonPayable,
919+
Declaration const* _declaration = nullptr,
921920
bool _gasSet = false,
922921
bool _valueSet = false,
923922
bool _bound = false

libsolidity/codegen/ExpressionCompiler.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -644,8 +644,8 @@ bool ExpressionCompiler::visit(FunctionCall const& _functionCall)
644644
strings(),
645645
FunctionType::Kind::BareCall,
646646
false,
647-
nullptr,
648647
StateMutability::NonPayable,
648+
nullptr,
649649
true,
650650
true
651651
),

0 commit comments

Comments
 (0)