Skip to content

Commit 46e16fc

Browse files
author
neo hong
committed
add vote relevant instructions
1 parent d6ada68 commit 46e16fc

File tree

10 files changed

+312
-6
lines changed

10 files changed

+312
-6
lines changed

libevmasm/GasMeter.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,12 @@ GasMeter::GasConsumption GasMeter::estimateMax(AssemblyItem const& _item, bool _
207207
case Instruction::NATIVEFREEZEEXPIRETIME:
208208
gas = runGas(Instruction::NATIVEFREEZEEXPIRETIME);
209209
break;
210+
case Instruction::NATIVEVOTE:
211+
gas = runGas(Instruction::NATIVEVOTE);
212+
break;
213+
case Instruction::NATIVEWITHDRAWREWARD:
214+
gas = runGas(Instruction::NATIVEWITHDRAWREWARD);
215+
break;
210216
case Instruction::CHAINID:
211217
gas = runGas(Instruction::CHAINID);
212218
break;

libevmasm/Instruction.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ std::map<std::string, Instruction> const solidity::evmasm::c_instructions =
6868
{ "NATIVEFREEZE", Instruction::NATIVEFREEZE },
6969
{ "NATIVEUNFREEZE", Instruction::NATIVEUNFREEZE },
7070
{ "NATIVEFREEZEEXPIRETIME", Instruction::NATIVEFREEZEEXPIRETIME },
71+
{ "NATIVEVOTE", Instruction::NATIVEVOTE },
72+
{ "NATIVEWITHDRAWREWARD", Instruction::NATIVEWITHDRAWREWARD },
7173
{ "CALLER", Instruction::CALLER },
7274
{ "CALLVALUE", Instruction::CALLVALUE },
7375
{ "CALLTOKENVALUE", Instruction::CALLTOKENVALUE },
@@ -222,6 +224,8 @@ static std::map<Instruction, InstructionInfo> const c_instructionInfo =
222224
{ Instruction::NATIVEFREEZE, { "NATIVEFREEZE", 0, 3, 1, true, Tier::Ext } },
223225
{ Instruction::NATIVEUNFREEZE, { "NATIVEUNFREEZE", 0, 2, 1, true, Tier::Ext } },
224226
{ Instruction::NATIVEFREEZEEXPIRETIME, { "NATIVEFREEZEEXPIRETIME", 0, 2, 1, true, Tier::Ext } },
227+
{ Instruction::NATIVEVOTE, { "NATIVEVOTE", 0, 4, 1, true, Tier::Ext } },
228+
{ Instruction::NATIVEWITHDRAWREWARD, { "NATIVEWITHDRAWREWARD", 0, 0, 1, true, Tier::Ext } },
225229
{ Instruction::CALLER, { "CALLER", 0, 0, 1, false, Tier::Base } },
226230
{ Instruction::CALLVALUE, { "CALLVALUE", 0, 0, 1, false, Tier::Base } },
227231
{ Instruction::CALLTOKENVALUE, { "CALLTOKENVALUE", 0, 0, 1, false, Tier::Base } },

libevmasm/Instruction.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,8 @@ enum class Instruction: uint8_t
183183
NATIVEFREEZE,
184184
NATIVEUNFREEZE,
185185
NATIVEFREEZEEXPIRETIME,
186+
NATIVEVOTE,
187+
NATIVEWITHDRAWREWARD,
186188

187189
CREATE = 0xf0, ///< create a new account with associated code
188190
CALL, ///< message-call into an account

libevmasm/SemanticInformation.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,8 @@ bool SemanticInformation::isDeterministic(AssemblyItem const& _item)
188188
case Instruction::NATIVEFREEZE:
189189
case Instruction::NATIVEUNFREEZE:
190190
case Instruction::NATIVEFREEZEEXPIRETIME:
191+
case Instruction::NATIVEVOTE:
192+
case Instruction::NATIVEWITHDRAWREWARD:
191193
case Instruction::SELFBALANCE: // depends on previous calls
192194
case Instruction::EXTCODESIZE:
193195
case Instruction::EXTCODEHASH:
@@ -364,6 +366,8 @@ bool SemanticInformation::invalidInPureFunctions(Instruction _instruction)
364366
case Instruction::NATIVEFREEZE:
365367
case Instruction::NATIVEUNFREEZE:
366368
case Instruction::NATIVEFREEZEEXPIRETIME:
369+
case Instruction::NATIVEVOTE:
370+
case Instruction::NATIVEWITHDRAWREWARD:
367371
case Instruction::ORIGIN:
368372
case Instruction::CALLER:
369373
case Instruction::CALLVALUE:
@@ -412,6 +416,8 @@ bool SemanticInformation::invalidInViewFunctions(Instruction _instruction)
412416
case Instruction::NATIVEFREEZE:
413417
case Instruction::NATIVEUNFREEZE:
414418
case Instruction::NATIVEFREEZEEXPIRETIME:
419+
case Instruction::NATIVEVOTE:
420+
case Instruction::NATIVEWITHDRAWREWARD:
415421
return true;
416422
default:
417423
break;

libsolidity/analysis/GlobalContext.cpp

Lines changed: 214 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,14 @@ int magicVariableToID(std::string const& _name)
101101
return -36;
102102
else if (_name == "freezeExpireTime")
103103
return -37;
104+
else if (_name == "withdrawreward") return -38;
105+
else if (_name == "vote") return -39;
106+
else if (_name == "rewardBalance") return -40;
107+
else if (_name == "isSrCandidate") return -41;
108+
else if (_name == "voteCount") return -42;
109+
else if (_name == "totalVoteCount") return -43;
110+
else if (_name == "receivedVoteCount") return -44;
111+
else if (_name == "usedVoteCount") return -45;
104112
else
105113
solAssert(false, "Unknown magic variable: \"" + _name + "\".");
106114
}
@@ -223,6 +231,7 @@ inline vector<shared_ptr<MagicVariableDeclaration const>> constructMagicVariable
223231
FunctionType::Kind::FreezeExpireTime,
224232
false,
225233
StateMutability::NonPayable)),
234+
magicVarDecl("withdrawreward", TypeProvider::function(strings{}, strings{"uint"}, FunctionType::Kind::WithdrawReward)),
226235
magicVarDecl("tx", TypeProvider::magic(MagicType::Kind::Transaction)),
227236
// Accepts a MagicType that can be any contract type or an Integer type and returns a
228237
// MagicType. The TypeChecker handles the correctness of the input and output types.
@@ -242,6 +251,13 @@ GlobalContext::GlobalContext(): m_magicVariables{constructMagicVariables()}
242251
addVerifyBurnProofMethod();
243252
addVerifyTransferProofMethod();
244253
addPedersenHashMethod();
254+
addVoteMethod();
255+
addRewardBalanceMethod();
256+
addIsSRCandidateMethod();
257+
addVoteCountMethod();
258+
addTotalVoteCountMethod();
259+
addReceivedVoteCountMethod();
260+
addUsedVoteCountMethod();
245261
}
246262

247263
void GlobalContext::addVerifyMintProofMethod() {
@@ -493,6 +509,204 @@ void GlobalContext::addValidateMultiSignMethod() {
493509
));
494510
}
495511

512+
void GlobalContext::addVoteMethod() {
513+
// bool vote(address[] memory addresses, unit256[] tronpowerlist)
514+
TypePointers parameterTypes;
515+
516+
parameterTypes.push_back(TypeProvider::array(DataLocation::Memory, TypeProvider::address()));
517+
parameterTypes.push_back(TypeProvider::array(DataLocation::Memory, TypeProvider::uint256()));
518+
519+
TypePointers returnParameterTypes;
520+
returnParameterTypes.push_back(TypeProvider::boolean());
521+
strings parameterNames;
522+
parameterNames.push_back("srList");
523+
parameterNames.push_back("tronpowerList");
524+
strings returnParameterNames;
525+
returnParameterNames.push_back("ok");
526+
527+
m_magicVariables.push_back(make_shared<MagicVariableDeclaration>(magicVariableToID("vote"), "vote", TypeProvider::function(
528+
parameterTypes,
529+
returnParameterTypes,
530+
parameterNames,
531+
returnParameterNames,
532+
FunctionType::Kind::vote,
533+
false,
534+
StateMutability::NonPayable,
535+
nullptr,
536+
false,
537+
false,
538+
false,
539+
false)
540+
));
541+
}
542+
543+
void GlobalContext::addRewardBalanceMethod() {
544+
// uint rewardBalance()
545+
TypePointers parameterTypes;
546+
TypePointers returnParameterTypes;
547+
returnParameterTypes.push_back(TypeProvider::uint256());
548+
strings parameterNames;
549+
strings returnParameterNames;
550+
returnParameterNames.push_back("result");
551+
552+
m_magicVariables.push_back(make_shared<MagicVariableDeclaration>(magicVariableToID("rewardBalance"), "rewardBalance", TypeProvider::function(
553+
parameterTypes,
554+
returnParameterTypes,
555+
parameterNames,
556+
returnParameterNames,
557+
FunctionType::Kind::rewardBalance,
558+
false,
559+
StateMutability::View,
560+
nullptr,
561+
false,
562+
false,
563+
false,
564+
false)
565+
));
566+
}
567+
568+
void GlobalContext::addIsSRCandidateMethod() {
569+
// bool isSrCandidate(address)
570+
TypePointers parameterTypes;
571+
parameterTypes.push_back(TypeProvider::address());
572+
573+
TypePointers returnParameterTypes;
574+
returnParameterTypes.push_back(TypeProvider::boolean());
575+
strings parameterNames;
576+
parameterNames.push_back("address");
577+
strings returnParameterNames;
578+
returnParameterNames.push_back("ok");
579+
580+
m_magicVariables.push_back(make_shared<MagicVariableDeclaration>(magicVariableToID("isSrCandidate"), "isSrCandidate", TypeProvider::function(
581+
parameterTypes,
582+
returnParameterTypes,
583+
parameterNames,
584+
returnParameterNames,
585+
FunctionType::Kind::isSrCandidate,
586+
false,
587+
StateMutability::View,
588+
nullptr,
589+
false,
590+
false,
591+
false,
592+
false)
593+
));
594+
}
595+
596+
void GlobalContext::addVoteCountMethod() {
597+
// uint voteCount(address, address)
598+
TypePointers parameterTypes;
599+
parameterTypes.push_back(TypeProvider::address());
600+
parameterTypes.push_back(TypeProvider::address());
601+
602+
TypePointers returnParameterTypes;
603+
returnParameterTypes.push_back(TypeProvider::uint256());
604+
strings parameterNames;
605+
parameterNames.push_back("address");
606+
parameterNames.push_back("address");
607+
strings returnParameterNames;
608+
returnParameterNames.push_back("result");
609+
610+
m_magicVariables.push_back(make_shared<MagicVariableDeclaration>(magicVariableToID("voteCount"), "voteCount", TypeProvider::function(
611+
parameterTypes,
612+
returnParameterTypes,
613+
parameterNames,
614+
returnParameterNames,
615+
FunctionType::Kind::voteCount,
616+
false,
617+
StateMutability::View,
618+
nullptr,
619+
false,
620+
false,
621+
false,
622+
false)
623+
));
624+
}
625+
626+
void GlobalContext::addTotalVoteCountMethod() {
627+
// uint totalVoteCount(address)
628+
TypePointers parameterTypes;
629+
parameterTypes.push_back(TypeProvider::address());
630+
631+
TypePointers returnParameterTypes;
632+
returnParameterTypes.push_back(TypeProvider::uint256());
633+
strings parameterNames;
634+
parameterNames.push_back("address");
635+
strings returnParameterNames;
636+
returnParameterNames.push_back("result");
637+
638+
m_magicVariables.push_back(make_shared<MagicVariableDeclaration>(magicVariableToID("totalVoteCount"), "totalVoteCount", TypeProvider::function(
639+
parameterTypes,
640+
returnParameterTypes,
641+
parameterNames,
642+
returnParameterNames,
643+
FunctionType::Kind::totalVoteCount,
644+
false,
645+
StateMutability::View,
646+
nullptr,
647+
false,
648+
false,
649+
false,
650+
false)
651+
));
652+
}
653+
654+
void GlobalContext::addReceivedVoteCountMethod() {
655+
// uint receivedVoteCount(address)
656+
TypePointers parameterTypes;
657+
parameterTypes.push_back(TypeProvider::address());
658+
659+
TypePointers returnParameterTypes;
660+
returnParameterTypes.push_back(TypeProvider::uint256());
661+
strings parameterNames;
662+
parameterNames.push_back("address");
663+
strings returnParameterNames;
664+
returnParameterNames.push_back("result");
665+
666+
m_magicVariables.push_back(make_shared<MagicVariableDeclaration>(magicVariableToID("receivedVoteCount"), "receivedVoteCount", TypeProvider::function(
667+
parameterTypes,
668+
returnParameterTypes,
669+
parameterNames,
670+
returnParameterNames,
671+
FunctionType::Kind::receivedVoteCount,
672+
false,
673+
StateMutability::View,
674+
nullptr,
675+
false,
676+
false,
677+
false,
678+
false)
679+
));
680+
}
681+
682+
void GlobalContext::addUsedVoteCountMethod() {
683+
// uint usedVoteCount(address)
684+
TypePointers parameterTypes;
685+
parameterTypes.push_back(TypeProvider::address());
686+
687+
TypePointers returnParameterTypes;
688+
returnParameterTypes.push_back(TypeProvider::uint256());
689+
strings parameterNames;
690+
parameterNames.push_back("address");
691+
strings returnParameterNames;
692+
returnParameterNames.push_back("result");
693+
694+
m_magicVariables.push_back(make_shared<MagicVariableDeclaration>(magicVariableToID("usedVoteCount"), "usedVoteCount", TypeProvider::function(
695+
parameterTypes,
696+
returnParameterTypes,
697+
parameterNames,
698+
returnParameterNames,
699+
FunctionType::Kind::usedVoteCount,
700+
false,
701+
StateMutability::View,
702+
nullptr,
703+
false,
704+
false,
705+
false,
706+
false)
707+
));
708+
}
709+
496710
void GlobalContext::setCurrentContract(ContractDefinition const& _contract)
497711
{
498712
m_currentContract = &_contract;

libsolidity/analysis/GlobalContext.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,13 @@ class GlobalContext
6767
void addVerifyTransferProofMethod();
6868
void addVerifyMintProofMethod();
6969
void addPedersenHashMethod();
70+
void addVoteMethod();
71+
void addRewardBalanceMethod();
72+
void addIsSRCandidateMethod();
73+
void addVoteCountMethod();
74+
void addTotalVoteCountMethod();
75+
void addReceivedVoteCountMethod();
76+
void addUsedVoteCountMethod();
7077
};
7178

7279
}

libsolidity/ast/Types.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2939,6 +2939,14 @@ string FunctionType::richIdentifier() const
29392939
case Kind::Freeze: id += "freeze"; break;
29402940
case Kind::Unfreeze: id += "unfreeze"; break;
29412941
case Kind::FreezeExpireTime: id += "freezeExpireTime"; break;
2942+
case Kind::vote: id += "vote"; break;
2943+
case Kind::WithdrawReward: id += "withdrawreward"; break;
2944+
case Kind::rewardBalance: id += "rewardBalance"; break;
2945+
case Kind::isSrCandidate: id += "isSrCandidate"; break;
2946+
case Kind::voteCount: id += "voteCount"; break;
2947+
case Kind::totalVoteCount: id += "totalVoteCount"; break;
2948+
case Kind::receivedVoteCount: id += "receivedVoteCount"; break;
2949+
case Kind::usedVoteCount: id += "usedVoteCount"; break;
29422950
}
29432951
id += "_" + stateMutabilityToString(m_stateMutability);
29442952
id += identifierList(m_parameterTypes) + "returns" + identifierList(m_returnParameterTypes);
@@ -3441,6 +3449,12 @@ bool FunctionType::isBareCall() const
34413449
case Kind::verifyTransferProof:
34423450
case Kind::verifyMintProof:
34433451
case Kind::pedersenHash:
3452+
case Kind::rewardBalance:
3453+
case Kind::isSrCandidate:
3454+
case Kind::voteCount:
3455+
case Kind::totalVoteCount:
3456+
case Kind::receivedVoteCount:
3457+
case Kind::usedVoteCount:
34443458
case Kind::SHA256:
34453459
case Kind::RIPEMD160:
34463460
return true;

libsolidity/ast/Types.h

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1150,11 +1150,19 @@ class FunctionType: public Type
11501150
RIPEMD160, ///< CALL to special contract for ripemd160
11511151
verifyBurnProof,///< CALL to special contract for verifyBurnProof which is used for shielded transaction for TRC-20
11521152
verifyTransferProof,///< CALL to special contract for verifyTransferProof which is used for shielded transaction for TRC-20
1153-
verifyMintProof,//< CALL to special contract for verifyMintProof which is used for shielded transaction for TRC-20
1154-
pedersenHash,//< CALL to special contract for verifyMintProof which is used for shielded transaction for TRC-20
1155-
Freeze,//< CALL to freeze balance
1156-
Unfreeze,//< CALL to unfreeze balance
1157-
FreezeExpireTime,// < CALL to freeze expire time
1153+
verifyMintProof,/// < CALL to special contract for verifyMintProof which is used for shielded transaction for TRC-20
1154+
pedersenHash,/// < CALL to special contract for verifyMintProof which is used for shielded transaction for TRC-20
1155+
Freeze,/// < CALL to freeze balance
1156+
Unfreeze,/// < CALL to unfreeze balance
1157+
FreezeExpireTime,/// < CALL to freeze expire time
1158+
vote,///< CALL to vote witness
1159+
WithdrawReward,///< CALL to withdrawReward to address
1160+
rewardBalance, ///< get reward balance
1161+
isSrCandidate, ///< Judge witness whether or not
1162+
voteCount, ///< get vote count
1163+
totalVoteCount, /// get total vote count
1164+
receivedVoteCount, /// get total received vote count
1165+
usedVoteCount, /// get total used vote count
11581166
Event, ///< syntactic sugar for LOG*
11591167
Error, ///< creating an error instance in revert or require
11601168
SetGas, ///< modify the default gas value for the function call

0 commit comments

Comments
 (0)