Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apb 46 #24

Merged
merged 10 commits into from
Sep 17, 2018
2 changes: 2 additions & 0 deletions solidity/libsolidity/analysis/GlobalContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ m_magicVariables(vector<shared_ptr<MagicVariableDeclaration const>>{make_shared<
make_shared<FunctionType>(strings(), strings{"bytes32"}, FunctionType::Kind::SHA256, true)),
make_shared<MagicVariableDeclaration>("ecrecover",
make_shared<FunctionType>(strings{"bytes32", "uint8", "bytes32", "bytes32"}, strings{"address"}, FunctionType::Kind::ECRecover)),
make_shared<MagicVariableDeclaration>("edverify",
make_shared<FunctionType>(strings{"bytes32", "bytes32", "bytes32", "bytes32"}, strings{"address"}, FunctionType::Kind::EDVerify)),
make_shared<MagicVariableDeclaration>("ripemd160",
make_shared<FunctionType>(strings(), strings{"bytes20"}, FunctionType::Kind::RIPEMD160, true)),
make_shared<MagicVariableDeclaration>("assert",
Expand Down
3 changes: 3 additions & 0 deletions solidity/libsolidity/ast/Types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2191,6 +2191,7 @@ string FunctionType::identifier() const
case Kind::Selfdestruct: id += "selfdestruct"; break;
case Kind::Revert: id += "revert"; break;
case Kind::ECRecover: id += "ecrecover"; break;
case Kind::EDVerify: id += "edverify"; break;
case Kind::SHA256: id += "sha256"; break;
case Kind::RIPEMD160: id += "ripemd160"; break;
case Kind::Log0: id += "log0"; break;
Expand Down Expand Up @@ -2515,6 +2516,7 @@ bool FunctionType::isBareCall() const
case Kind::BareCallCode:
case Kind::BareDelegateCall:
case Kind::ECRecover:
case Kind::EDVerify:
case Kind::SHA256:
case Kind::RIPEMD160:
return true;
Expand Down Expand Up @@ -2554,6 +2556,7 @@ bool FunctionType::isPure() const
return
m_kind == Kind::SHA3 ||
m_kind == Kind::ECRecover ||
m_kind == Kind::EDVerify ||
m_kind == Kind::SHA256 ||
m_kind == Kind::RIPEMD160 ||
m_kind == Kind::AddMod ||
Expand Down
1 change: 1 addition & 0 deletions solidity/libsolidity/ast/Types.h
Original file line number Diff line number Diff line change
Expand Up @@ -859,6 +859,7 @@ class FunctionType: public Type
Selfdestruct, ///< SELFDESTRUCT
Revert, ///< REVERT
ECRecover, ///< CALL to special contract for ecrecover
EDVerify, ///< CALL to special contract for edverify
SHA256, ///< CALL to special contract for sha256
RIPEMD160, ///< CALL to special contract for ripemd160
Log0,
Expand Down
11 changes: 8 additions & 3 deletions solidity/libsolidity/codegen/ExpressionCompiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -823,11 +823,15 @@ bool ExpressionCompiler::visit(FunctionCall const& _functionCall)
case FunctionType::Kind::ECRecover:
case FunctionType::Kind::SHA256:
case FunctionType::Kind::RIPEMD160:
case FunctionType::Kind::EDVerify:
{
_functionCall.expression().accept(*this);
static const map<FunctionType::Kind, u128> contractAddresses{{FunctionType::Kind::ECRecover, 1},
{FunctionType::Kind::SHA256, 2},
{FunctionType::Kind::RIPEMD160, 3}};
static const map<FunctionType::Kind, u128> contractAddresses{
{FunctionType::Kind::ECRecover, 1},
{FunctionType::Kind::SHA256, 2},
{FunctionType::Kind::RIPEMD160, 3},
{FunctionType::Kind::EDVerify, 16}};

m_context << contractAddresses.find(function.kind())->second;
m_context << u128(0); // as address should take two stack items
for (unsigned i = function.sizeOnStack(); i > 0; --i)
Expand Down Expand Up @@ -1029,6 +1033,7 @@ bool ExpressionCompiler::visit(MemberAccess const& _memberAccess)
case FunctionType::Kind::Log3:
case FunctionType::Kind::Log4:
case FunctionType::Kind::ECRecover:
case FunctionType::Kind::EDVerify:
case FunctionType::Kind::SHA256:
case FunctionType::Kind::RIPEMD160:
default:
Expand Down
12 changes: 12 additions & 0 deletions solidity/tests/contracts/testedvalidate.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
pragma solidity ^0.4.15;

contract testedvalidate {
function validate(
bytes32 messageHash,
bytes32 publicKey,
bytes32 sig1,
bytes32 sig2)
returns (address) {
return edverify(messageHash, publicKey, sig1, sig2);
}
}