Skip to content

Commit 1f3e4c1

Browse files
committed
merge new code for chainsql ins and support sm3 precompile
1 parent 60dce06 commit 1f3e4c1

File tree

15 files changed

+92
-77
lines changed

15 files changed

+92
-77
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ docs/utils/*.pyc
4040
deps/install
4141
deps/cache
4242
cmake-build-*/
43+
vsbuild
4344

4445
# vim stuff
4546
[._]*.sw[a-p]

libevmasm/Instruction.cpp

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -187,18 +187,17 @@ std::map<std::string, Instruction> const solidity::evmasm::c_instructions =
187187
{ "EXGETLENBYINDEX", Instruction::EXGETLENBYINDEX},
188188
/* End SQL instruction */
189189

190+
{ "REVERTDIY", Instruction::REVERTDIY},
191+
190192
/* Begin Token instruction */
191193
{ "EXACCOUNTSET", Instruction::EXACCOUNTSET },
192-
{ "EXTRANSFERRATESET", Instruction::EXTRANSFERRATESET },
193-
{ "EXTRANSFERRANGESET", Instruction::EXTRANSFERRANGESET },
194+
{ "EXTRANSFERFEESET", Instruction::EXTRANSFERFEESET },
194195
{ "EXTRUSTSET", Instruction::EXTRUSTSET },
195196
{ "EXTRUSTLIMIT", Instruction::EXTRUSTLIMIT },
196197
{ "EXGATEWAYBALANCE", Instruction::EXGATEWAYBALANCE },
197198
{ "EXPAY", Instruction::EXPAY },
198199
/* End Token instructtion */
199200

200-
{ "REVERTDIY", Instruction::REVERTDIY},
201-
202201
{ "CALL", Instruction::CALL },
203202
{ "CALLCODE", Instruction::CALLCODE },
204203
{ "STATICCALL", Instruction::STATICCALL },
@@ -359,17 +358,16 @@ static std::map<Instruction, InstructionInfo> const c_instructionInfo =
359358
{ Instruction::EXGETCOLSIZE, { "EXGETCOLSIZE", 0, 1, 1, true, Tier::Zero} },
360359
{ Instruction::EXGETVALUEBYKEY, { "EXGETVALUEBYKEY", 0, 6, 1, true, Tier::Zero} },
361360
{ Instruction::EXGETVALUEBYINDEX, { "EXGETVALUEBYINDEX", 0, 5, 1, true, Tier::Zero} },
361+
{ Instruction::REVERTDIY, { "REVERTDIY", 0, 2, 0, true, Tier::Zero } },
362362
{ Instruction::EXEXITFUNC, { "EXEXITFUNC", 0, 0, 0, true, Tier::Zero} },
363363
{ Instruction::EXGETLENBYKEY, { "EXGETLENBYKEY", 0, 4, 1, true, Tier::Zero} },
364364
{ Instruction::EXGETLENBYINDEX, { "EXGETLENBYINDEX",0, 3, 1, true, Tier::Zero} },
365365
{ Instruction::EXACCOUNTSET, { "EXACCOUNTSET", 0, 3, 1, true, Tier::Zero } },
366-
{ Instruction::EXTRANSFERRATESET,{ "EXTRANSFERRATESET", 0, 3, 1, true, Tier::Zero } },
367-
{ Instruction::EXTRANSFERRANGESET,{ "EXTRANSFERRANGESET", 0, 5, 1, true, Tier::Zero } },
366+
{ Instruction::EXTRANSFERFEESET,{ "EXTRANSFERFEESET", 0, 7, 1, true, Tier::Zero } },
368367
{ Instruction::EXTRUSTSET,{ "EXTRUSTSET", 0, 6, 1, true, Tier::Zero } },
369-
{ Instruction::EXTRUSTLIMIT,{ "EXTRUSTLIMIT", 0, 4, 1, true, Tier::Zero } },
370-
{ Instruction::EXGATEWAYBALANCE,{ "EXGATEWAYBALANCE", 0, 4, 1, true, Tier::Zero } },
371-
{ Instruction::EXPAY,{ "EXPAY", 0, 7, 1, true, Tier::Zero } },
372-
{ Instruction::REVERTDIY, { "REVERTDIY", 0, 2, 0, true, Tier::Zero } },
368+
{ Instruction::EXTRUSTLIMIT,{ "EXTRUSTLIMIT", 0, 5, 1, true, Tier::Zero } },
369+
{ Instruction::EXGATEWAYBALANCE,{ "EXGATEWAYBALANCE", 0, 5, 1, true, Tier::Zero } },
370+
{ Instruction::EXPAY,{ "EXPAY", 0, 9, 1, true, Tier::Zero } },
373371
{ Instruction::CALL, { "CALL", 0, 7, 1, true, Tier::Special } },
374372
{ Instruction::CALLCODE, { "CALLCODE", 0, 7, 1, true, Tier::Special } },
375373
{ Instruction::RETURN, { "RETURN", 0, 2, 0, true, Tier::Zero } },

libevmasm/Instruction.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -193,15 +193,15 @@ enum class Instruction: uint8_t
193193
EXGETLENBYKEY,
194194
EXGETLENBYINDEX = 0xd0,
195195

196+
REVERTDIY,
197+
196198
EXACCOUNTSET,
197-
EXTRANSFERRATESET,
198-
EXTRANSFERRANGESET,
199+
EXTRANSFERFEESET,
199200
EXTRUSTSET,
200201
EXTRUSTLIMIT,
201202
EXGATEWAYBALANCE,
202203
EXPAY,
203204

204-
REVERTDIY,
205205
/** NOTE: maximum value is 0xef */
206206

207207
CREATE = 0xf0, ///< create a new account with associated code

libsolidity/analysis/GlobalContext.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ int magicVariableToID(std::string const& _name)
6161
else if (_name == "tx") return -26;
6262
else if (_name == "type") return -27;
6363
else if (_name == "this") return -28;
64+
else if (_name == "revertdiy") return -29;
65+
else if (_name == "db") return -30;
66+
else if (_name == "sm3") return -31;
6467
else
6568
solAssert(false, "Unknown magic variable: \"" + _name + "\".");
6669
}
@@ -95,7 +98,6 @@ inline vector<shared_ptr<MagicVariableDeclaration const>> constructMagicVariable
9598
magicVarDecl("sha3", TypeProvider::function(strings{"bytes memory"}, strings{"bytes32"}, FunctionType::Kind::KECCAK256, false, StateMutability::Pure)),
9699
magicVarDecl("suicide", TypeProvider::function(strings{"address payable"}, strings{}, FunctionType::Kind::Selfdestruct)),
97100
magicVarDecl("tx", TypeProvider::magic(MagicType::Kind::Transaction)),
98-
magicVarDecl("db", TypeProvider::magic(MagicType::Kind::Database)),
99101
// Accepts a MagicType that can be any contract type or an Integer type and returns a
100102
// MagicType. The TypeChecker handles the correctness of the input and output types.
101103
magicVarDecl("type", TypeProvider::function(
@@ -105,6 +107,8 @@ inline vector<shared_ptr<MagicVariableDeclaration const>> constructMagicVariable
105107
true,
106108
StateMutability::Pure
107109
)),
110+
magicVarDecl("db", TypeProvider::magic(MagicType::Kind::Database)),
111+
magicVarDecl("sm3", TypeProvider::function(strings{"bytes memory"}, strings{"bytes32"}, FunctionType::Kind::SM3, false, StateMutability::Pure)),
108112
};
109113
}
110114

libsolidity/analysis/TypeChecker.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2122,7 +2122,8 @@ void TypeChecker::typeCheckFunctionGeneralChecks(
21222122
else if (
21232123
_functionType->kind() == FunctionType::Kind::KECCAK256 ||
21242124
_functionType->kind() == FunctionType::Kind::SHA256 ||
2125-
_functionType->kind() == FunctionType::Kind::RIPEMD160
2125+
_functionType->kind() == FunctionType::Kind::RIPEMD160 ||
2126+
_functionType->kind() == FunctionType::Kind::SM3
21262127
)
21272128
{
21282129
solAssert(!isVariadic, "");
@@ -2240,7 +2241,8 @@ void TypeChecker::typeCheckFunctionGeneralChecks(
22402241
else if (
22412242
_functionType->kind() == FunctionType::Kind::KECCAK256 ||
22422243
_functionType->kind() == FunctionType::Kind::SHA256 ||
2243-
_functionType->kind() == FunctionType::Kind::RIPEMD160
2244+
_functionType->kind() == FunctionType::Kind::RIPEMD160 ||
2245+
_functionType->kind() == FunctionType::Kind::SM3
22442246
)
22452247
return {
22462248
7556_error,

libsolidity/ast/TypeProvider.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,11 +146,13 @@ array<unique_ptr<FixedBytesType>, 32> const TypeProvider::m_bytesM{{
146146
{make_unique<FixedBytesType>(32)}
147147
}};
148148

149-
array<unique_ptr<MagicType>, 4> const TypeProvider::m_magics{{
149+
array<unique_ptr<MagicType>, 6> const TypeProvider::m_magics{ {
150150
{make_unique<MagicType>(MagicType::Kind::Block)},
151151
{make_unique<MagicType>(MagicType::Kind::Message)},
152152
{make_unique<MagicType>(MagicType::Kind::Transaction)},
153-
{make_unique<MagicType>(MagicType::Kind::ABI)}
153+
{make_unique<MagicType>(MagicType::Kind::ABI)},
154+
{make_unique<MagicType>(MagicType::Kind::MetaType)},
155+
{make_unique<MagicType>(MagicType::Kind::Database)}
154156
// MetaType is stored separately
155157
}};
156158

libsolidity/ast/TypeProvider.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ class TypeProvider
228228
static std::array<std::unique_ptr<IntegerType>, 32> const m_intM;
229229
static std::array<std::unique_ptr<IntegerType>, 32> const m_uintM;
230230
static std::array<std::unique_ptr<FixedBytesType>, 32> const m_bytesM;
231-
static std::array<std::unique_ptr<MagicType>, 4> const m_magics; ///< MagicType's except MetaType
231+
static std::array<std::unique_ptr<MagicType>, 6> const m_magics; ///< MagicType's except MetaType
232232

233233
std::map<std::pair<unsigned, unsigned>, std::unique_ptr<FixedPointType>> m_ufixedMxN{};
234234
std::map<std::pair<unsigned, unsigned>, std::unique_ptr<FixedPointType>> m_fixedMxN{};

libsolidity/ast/Types.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -484,12 +484,11 @@ MemberList::MemberMap AddressType::nativeMembers(ASTNode const*) const
484484
{"get", TypeProvider::function(strings{"string memory", "string memory"}, strings{"uint256"}, FunctionType::Kind::GetSQL, false, StateMutability::View)},
485485
{"grant", TypeProvider::function(strings{"address", "string memory", "string memory"}, strings(), FunctionType::Kind::GrantSQL)},
486486
{ "accountSet", TypeProvider::function(strings{"uint32", "bool"}, strings(), FunctionType::Kind::AccountSet) },
487-
{ "setTransferRate", TypeProvider::function(strings{ "string memory"}, strings(), FunctionType::Kind::SetTransferRate) },
488-
{ "setTransferRange", TypeProvider::function(strings{ "string memory", "string memory" }, strings(), FunctionType::Kind::SetTransferRange) },
487+
{ "setTransferFee", TypeProvider::function(strings{ "string memory", "string memory", "string memory" }, strings(), FunctionType::Kind::SetTransferFee) },
489488
{ "trustSet", TypeProvider::function(strings{ "string memory", "string memory", "address" }, strings(), FunctionType::Kind::TrustSet) },
490-
{ "trustLimit", TypeProvider::function(strings{ "string memory", "address" }, strings{ "int" }, FunctionType::Kind::TrustLimit, false, StateMutability::View) },
491-
{ "gatewayBalance", TypeProvider::function(strings{ "string memory", "address" }, strings{ "int" }, FunctionType::Kind::GateWayBalance, false, StateMutability::View) },
492-
{ "pay", TypeProvider::function(strings{ "address", "string memory", "string memory", "address" }, strings(), FunctionType::Kind::Pay) }
489+
{ "trustLimit", TypeProvider::function(strings{ "string memory", "uint64", "address" }, strings{ "int" }, FunctionType::Kind::TrustLimit, false, StateMutability::View) },
490+
{ "gatewayBalance", TypeProvider::function(strings{ "string memory", "uint64", "address" }, strings{ "int" }, FunctionType::Kind::GateWayBalance, false, StateMutability::View) },
491+
{ "pay", TypeProvider::function(strings{ "address", "string memory", "string memory", "string memory", "address" }, strings(), FunctionType::Kind::Pay) }
493492
};
494493
if (m_stateMutability == StateMutability::Payable)
495494
{
@@ -2933,8 +2932,7 @@ string FunctionType::richIdentifier() const
29332932
case Kind::BeginTrans: id += "beginTrans"; break;
29342933
case Kind::CommitTrans: id += "commit"; break;
29352934
case Kind::AccountSet: id += "accountSet"; break;
2936-
case Kind::SetTransferRate: id += "setTransferRate"; break;
2937-
case Kind::SetTransferRange: id += "setTransferRange"; break;
2935+
case Kind::SetTransferFee: id += "setTransferFee"; break;
29382936
case Kind::TrustSet: id += "trustSet"; break;
29392937
case Kind::TrustLimit: id += "trustLimit"; break;
29402938
case Kind::GateWayBalance: id += "gatewayBalance"; break;
@@ -3434,6 +3432,7 @@ bool FunctionType::isBareCall() const
34343432
case Kind::ECRecover:
34353433
case Kind::SHA256:
34363434
case Kind::RIPEMD160:
3435+
case Kind::SM3:
34373436
return true;
34383437
default:
34393438
return false;
@@ -3497,6 +3496,7 @@ bool FunctionType::isPure() const
34973496
m_kind == Kind::ECRecover ||
34983497
m_kind == Kind::SHA256 ||
34993498
m_kind == Kind::RIPEMD160 ||
3499+
m_kind == Kind::SM3 ||
35003500
m_kind == Kind::AddMod ||
35013501
m_kind == Kind::MulMod ||
35023502
m_kind == Kind::ObjectCreation ||
@@ -3629,6 +3629,7 @@ bool FunctionType::padArguments() const
36293629
case Kind::BareStaticCall:
36303630
case Kind::SHA256:
36313631
case Kind::RIPEMD160:
3632+
case Kind::SM3:
36323633
case Kind::KECCAK256:
36333634
case Kind::ABIEncodePacked:
36343635
case Kind::CreateSQL:

libsolidity/ast/Types.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1187,8 +1187,7 @@ class FunctionType: public Type
11871187

11881188
/* Begin Token */
11891189
AccountSet,
1190-
SetTransferRate,
1191-
SetTransferRange,
1190+
SetTransferFee,
11921191
TrustSet,
11931192
TrustLimit,
11941193
GateWayBalance,
@@ -1371,6 +1370,7 @@ class FunctionType: public Type
13711370
case FunctionType::Kind::KECCAK256:
13721371
case FunctionType::Kind::SHA256:
13731372
case FunctionType::Kind::RIPEMD160:
1373+
case FunctionType::Kind::SM3:
13741374
case FunctionType::Kind::BareCall:
13751375
case FunctionType::Kind::BareCallCode:
13761376
case FunctionType::Kind::BareDelegateCall:

libsolidity/codegen/ExpressionCompiler.cpp

Lines changed: 44 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1597,29 +1597,9 @@ bool ExpressionCompiler::visit(FunctionCall const& _functionCall)
15971597

15981598
break;
15991599
}
1600-
case FunctionType::Kind::SetTransferRate: {
1601-
solAssert(arguments.size() == 1, "argument's size doesn't math parameter");
1602-
1603-
/* address */
1604-
_functionCall.expression().accept(*this);
1605-
1606-
/* argument (string memory) */
1607-
prepareSQLCallMemParams(arguments, parameterTypes);
1608-
1609-
m_context << Instruction::DUP2 << Instruction::DUP2
1610-
<< Instruction::DUP5 << Instruction::EXTRANSFERRATESET
1611-
<< swapInstruction(3);
1612-
1613-
utils().popStackSlots(3);
1614-
1615-
m_context << Instruction::ISZERO;
1616-
m_context.appendConditionalRevertDIY(true);
1617-
1618-
break;
1619-
}
1620-
case FunctionType::Kind::SetTransferRange:
1600+
case FunctionType::Kind::SetTransferFee:
16211601
{
1622-
solAssert(arguments.size() == 2, "argument's size doesn't math parameter");
1602+
solAssert(arguments.size() == 3, "argument's size doesn't math parameter");
16231603

16241604
/* address */
16251605
_functionCall.expression().accept(*this);
@@ -1629,10 +1609,11 @@ bool ExpressionCompiler::visit(FunctionCall const& _functionCall)
16291609

16301610
m_context << Instruction::DUP2 << Instruction::DUP2
16311611
<< Instruction::DUP6 << Instruction::DUP6
1632-
<< Instruction::DUP9 << Instruction::EXTRANSFERRANGESET
1633-
<< swapInstruction(5);
1612+
<< Instruction::DUP10 << Instruction::DUP10
1613+
<< Instruction::DUP13 << Instruction::EXTRANSFERFEESET
1614+
<< swapInstruction(7);
16341615

1635-
utils().popStackSlots(5);
1616+
utils().popStackSlots(7);
16361617

16371618
m_context << Instruction::ISZERO;
16381619
m_context.appendConditionalRevertDIY(true);
@@ -1673,18 +1654,32 @@ bool ExpressionCompiler::visit(FunctionCall const& _functionCall)
16731654
case FunctionType::Kind::TrustLimit:
16741655
case FunctionType::Kind::GateWayBalance:
16751656
{
1676-
solAssert(arguments.size() == 2, "argument's size doesn't math parameter");
1657+
solAssert(arguments.size() == 3, "argument's size doesn't math parameter");
16771658

16781659
/* address */
16791660
_functionCall.expression().accept(*this);
1661+
auto arg = arguments.begin();
1662+
auto param = parameterTypes.begin();
16801663

16811664
/* argument (string memory) */
1682-
copyParamToMemory(*arguments.begin(), *parameterTypes.begin());
1665+
copyParamToMemory(*arg, *param);
1666+
1667+
++arg;
1668+
++param;
1669+
1670+
/* argument (uint64) */
1671+
TypePointer const &argType1 = (*arg)->annotation().type;
1672+
solAssert(argType1, "");
1673+
(*arg)->accept(*this);
1674+
utils().convertType(*argType1, **param, true);
1675+
1676+
++arg;
1677+
++param;
16831678

16841679
/** argument (address) */
1685-
auto const &argType = arguments.back()->annotation().type;
1686-
solAssert(argType, "");
1687-
arguments.back()->accept(*this);
1680+
auto const &argType2 = (*arg)->annotation().type;
1681+
solAssert(argType2, "");
1682+
(*arg)->accept(*this);
16881683

16891684
Instruction cmd = Instruction::EXTRUSTLIMIT;
16901685
switch (function.kind())
@@ -1700,22 +1695,23 @@ bool ExpressionCompiler::visit(FunctionCall const& _functionCall)
17001695
}
17011696

17021697
m_context << Instruction::DUP1
1703-
<< Instruction::DUP4 << Instruction::DUP4
1704-
<< Instruction::DUP7 << cmd
1705-
<< swapInstruction(4);
1698+
<< Instruction::DUP3
1699+
<< Instruction::DUP6 << Instruction::DUP6
1700+
<< Instruction::DUP9 << cmd
1701+
<< swapInstruction(5);
17061702

1707-
utils().popStackSlots(4);
1703+
utils().popStackSlots(5);
17081704

17091705
break;
17101706
}
17111707
case FunctionType::Kind::Pay:
17121708
{
1713-
solAssert(arguments.size() == 4, "argument's size doesn't math parameter");
1709+
solAssert(arguments.size() == 5, "argument's size doesn't math parameter");
17141710

1715-
/* address */
1711+
/* address sender */
17161712
_functionCall.expression().accept(*this);
17171713

1718-
/** argument (address) */
1714+
/** argument (address reciever) */
17191715
auto const &argType1 = arguments.front()->annotation().type;
17201716
solAssert(argType1, "");
17211717
arguments.front()->accept(*this);
@@ -1726,20 +1722,16 @@ bool ExpressionCompiler::visit(FunctionCall const& _functionCall)
17261722
TypePointers params(parameterTypes.begin() + 1, parameterTypes.end() - 1);
17271723
prepareSQLCallMemParams(memArguments, params);
17281724

1729-
/** argument (address) */
1725+
/** argument (address gateway) */
17301726
auto const &argType2 = arguments.back()->annotation().type;
17311727
solAssert(argType2, "");
17321728
arguments.back()->accept(*this);
17331729

1734-
m_context << Instruction::DUP1
1735-
<< Instruction::DUP4 << Instruction::DUP4
1736-
<< Instruction::DUP8 << Instruction::DUP8
1737-
<< Instruction::DUP11
1738-
<< Instruction::DUP13
1739-
<< Instruction::EXPAY
1740-
<< swapInstruction(7);
1730+
utils().copyToStackTop(9, 9);
17411731

1742-
utils().popStackSlots(7);
1732+
m_context << Instruction::EXPAY << swapInstruction(9);
1733+
1734+
utils().popStackSlots(9);
17431735

17441736
m_context << Instruction::ISZERO;
17451737
m_context.appendConditionalRevertDIY(true);
@@ -1896,8 +1888,7 @@ bool ExpressionCompiler::visit(MemberAccess const& _memberAccess)
18961888
case FunctionType::Kind::DeleteSQL:
18971889
case FunctionType::Kind::UpdateSQL:
18981890
case FunctionType::Kind::AccountSet:
1899-
case FunctionType::Kind::SetTransferRate:
1900-
case FunctionType::Kind::SetTransferRange:
1891+
case FunctionType::Kind::SetTransferFee:
19011892
case FunctionType::Kind::TrustSet:
19021893
case FunctionType::Kind::TrustLimit:
19031894
case FunctionType::Kind::GateWayBalance:
@@ -2107,7 +2098,11 @@ bool ExpressionCompiler::visit(MemberAccess const& _memberAccess)
21072098
true
21082099
);
21092100
}
2110-
else if ((set<string>{"call", "callcode", "delegatecall", "staticcall"}).count(member))
2101+
else if ((set<string>{"call", "callcode", "delegatecall", "staticcall",
2102+
"create", "drop", "rename", "insert",
2103+
"deletex", "update", "grant", "get",
2104+
"accountSet", "setTransferFee", "trustSet",
2105+
"trustLimit", "gatewayBalance", "pay"}).count(member))
21112106
utils().convertType(
21122107
*_memberAccess.expression().annotation().type,
21132108
*TypeProvider::address(),

0 commit comments

Comments
 (0)