diff --git a/libsolidity/analysis/GlobalContext.cpp b/libsolidity/analysis/GlobalContext.cpp index b0f157240d55..b9c8a3c6faab 100644 --- a/libsolidity/analysis/GlobalContext.cpp +++ b/libsolidity/analysis/GlobalContext.cpp @@ -79,7 +79,8 @@ int magicVariableToID(std::string const& _name) else if (_name == "isSrCandidate") return -41; else if (_name == "voteCount") return -42; else if (_name == "totalVoteCount") return -43; - else if (_name == "totalReceivedVoteCount") return -44; + else if (_name == "receivedVoteCount") return -44; + else if (_name == "usedVoteCount") return -45; else solAssert(false, "Unknown magic variable: \"" + _name + "\"."); } @@ -146,7 +147,8 @@ inline vector> constructMagicVariable addIsSRCandidateMethod(); addVoteCountMethod(); addTotalVoteCountMethod(); - addTotalReceivedVoteCountMethod(); + addReceivedVoteCountMethod(); + addUsedVoteCountMethod(); } void GlobalContext::addVerifyMintProofMethod() { @@ -540,8 +542,8 @@ inline vector> constructMagicVariable )); } - void GlobalContext::addTotalReceivedVoteCountMethod() { - // uint totalReceivedVoteCount(address) + void GlobalContext::addReceivedVoteCountMethod() { + // uint receivedVoteCount(address) TypePointers parameterTypes; parameterTypes.push_back(TypeProvider::address()); @@ -552,12 +554,12 @@ inline vector> constructMagicVariable strings returnParameterNames; returnParameterNames.push_back("result"); - m_magicVariables.push_back(make_shared(magicVariableToID("totalReceivedVoteCount"), "totalReceivedVoteCount", TypeProvider::function( + m_magicVariables.push_back(make_shared(magicVariableToID("receivedVoteCount"), "receivedVoteCount", TypeProvider::function( parameterTypes, returnParameterTypes, parameterNames, returnParameterNames, - FunctionType::Kind::totalReceivedVoteCount, + FunctionType::Kind::receivedVoteCount, false, StateMutability::View, nullptr, @@ -568,6 +570,34 @@ inline vector> constructMagicVariable )); } + void GlobalContext::addUsedVoteCountMethod() { + // uint usedVoteCount(address) + TypePointers parameterTypes; + parameterTypes.push_back(TypeProvider::address()); + + TypePointers returnParameterTypes; + returnParameterTypes.push_back(TypeProvider::uint256()); + strings parameterNames; + parameterNames.push_back("address"); + strings returnParameterNames; + returnParameterNames.push_back("result"); + + m_magicVariables.push_back(make_shared(magicVariableToID("usedVoteCount"), "usedVoteCount", TypeProvider::function( + parameterTypes, + returnParameterTypes, + parameterNames, + returnParameterNames, + FunctionType::Kind::usedVoteCount, + false, + StateMutability::View, + nullptr, + false, + false, + false, + false) + )); + } + void GlobalContext::setCurrentContract(ContractDefinition const& _contract) { diff --git a/libsolidity/analysis/GlobalContext.h b/libsolidity/analysis/GlobalContext.h index e4208077a364..4e583e4b86fd 100644 --- a/libsolidity/analysis/GlobalContext.h +++ b/libsolidity/analysis/GlobalContext.h @@ -68,7 +68,8 @@ class GlobalContext: private boost::noncopyable void addIsSRCandidateMethod(); void addVoteCountMethod(); void addTotalVoteCountMethod(); - void addTotalReceivedVoteCountMethod(); + void addReceivedVoteCountMethod(); + void addUsedVoteCountMethod(); }; } diff --git a/libsolidity/ast/Types.cpp b/libsolidity/ast/Types.cpp index 4dd79631a94d..98e10c0cef85 100644 --- a/libsolidity/ast/Types.cpp +++ b/libsolidity/ast/Types.cpp @@ -3051,7 +3051,8 @@ string FunctionType::richIdentifier() const case Kind::isSrCandidate: id += "isSrCandidate"; break; case Kind::voteCount: id += "voteCount"; break; case Kind::totalVoteCount: id += "totalVoteCount"; break; - case Kind::totalReceivedVoteCount: id += "totalReceivedVoteCount"; break; + case Kind::receivedVoteCount: id += "receivedVoteCount"; break; + case Kind::usedVoteCount: id += "usedVoteCount"; break; } id += "_" + stateMutabilityToString(m_stateMutability); id += identifierList(m_parameterTypes) + "returns" + identifierList(m_returnParameterTypes); @@ -3526,7 +3527,8 @@ bool FunctionType::isBareCall() const case Kind::isSrCandidate: case Kind::voteCount: case Kind::totalVoteCount: - case Kind::totalReceivedVoteCount: + case Kind::receivedVoteCount: + case Kind::usedVoteCount: case Kind::SHA256: case Kind::RIPEMD160: return true; diff --git a/libsolidity/ast/Types.h b/libsolidity/ast/Types.h index 5e5738aa348c..4e6c499a7674 100644 --- a/libsolidity/ast/Types.h +++ b/libsolidity/ast/Types.h @@ -1121,7 +1121,8 @@ class FunctionType: public Type isSrCandidate, ///< Judge witness whether or not voteCount, ///< get vote count totalVoteCount, /// get total vote count - totalReceivedVoteCount, /// get total received vote count + receivedVoteCount, /// get total received vote count + usedVoteCount, /// get total used vote count Log0, Log1, Log2, diff --git a/libsolidity/codegen/ExpressionCompiler.cpp b/libsolidity/codegen/ExpressionCompiler.cpp index 36d7f0b817b2..7c2bdb4bb3bf 100644 --- a/libsolidity/codegen/ExpressionCompiler.cpp +++ b/libsolidity/codegen/ExpressionCompiler.cpp @@ -989,7 +989,8 @@ bool ExpressionCompiler::visit(FunctionCall const& _functionCall) case FunctionType::Kind::isSrCandidate: case FunctionType::Kind::voteCount: case FunctionType::Kind::totalVoteCount: - case FunctionType::Kind::totalReceivedVoteCount: + case FunctionType::Kind::receivedVoteCount: + case FunctionType::Kind::usedVoteCount: { _functionCall.expression().accept(*this); static map const contractAddresses{ @@ -1005,8 +1006,9 @@ bool ExpressionCompiler::visit(FunctionCall const& _functionCall) {FunctionType::Kind::rewardBalance, 16777221}, {FunctionType::Kind::isSrCandidate, 16777222}, {FunctionType::Kind::voteCount, 16777223}, - {FunctionType::Kind::totalVoteCount, 16777224}, - {FunctionType::Kind::totalReceivedVoteCount, 16777225} + {FunctionType::Kind::usedVoteCount, 16777224}, + {FunctionType::Kind::receivedVoteCount, 16777225}, + {FunctionType::Kind::totalVoteCount, 16777226} }; m_context << contractAddresses.at(function.kind()); for (unsigned i = function.sizeOnStack(); i > 0; --i) @@ -1524,7 +1526,8 @@ bool ExpressionCompiler::visit(MemberAccess const& _memberAccess) case FunctionType::Kind::isSrCandidate: case FunctionType::Kind::voteCount: case FunctionType::Kind::totalVoteCount: - case FunctionType::Kind::totalReceivedVoteCount: + case FunctionType::Kind::receivedVoteCount: + case FunctionType::Kind::usedVoteCount: case FunctionType::Kind::SHA256: case FunctionType::Kind::RIPEMD160: default: @@ -2495,7 +2498,8 @@ void ExpressionCompiler::appendExternalFunctionCall( || _functionType.kind() == FunctionType::Kind::isSrCandidate || _functionType.kind() == FunctionType::Kind::voteCount || _functionType.kind() == FunctionType::Kind::totalVoteCount - || _functionType.kind() == FunctionType::Kind::totalReceivedVoteCount + || _functionType.kind() == FunctionType::Kind::receivedVoteCount + || _functionType.kind() == FunctionType::Kind::usedVoteCount ) // This would be the only combination of padding and in-place encoding, // but all parameters of ecrecover are value types anyway.