From d7ffba150458f947c03741f1b528d45eb6c8771a Mon Sep 17 00:00:00 2001 From: Lefteris Karapetsas Date: Fri, 13 Mar 2015 17:36:00 +0100 Subject: [PATCH 1/2] Adding msg.sig Solidity Magic type msg.sig will return a bytes4 with the function signature located in CALLDATALOAD --- ExpressionCompiler.cpp | 2 ++ Types.cpp | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/ExpressionCompiler.cpp b/ExpressionCompiler.cpp index 3cee40df1..07f4e94ea 100644 --- a/ExpressionCompiler.cpp +++ b/ExpressionCompiler.cpp @@ -646,6 +646,8 @@ void ExpressionCompiler::endVisit(MemberAccess const& _memberAccess) m_context << eth::Instruction::GASPRICE; else if (member == "data") m_context << u256(0) << eth::Instruction::CALLDATASIZE; + else if (member == "sig") + m_context << u256(0) << eth::Instruction::CALLDATALOAD << (u256(0xffffffff) << (256 - 32))<< eth::Instruction::AND; else BOOST_THROW_EXCEPTION(InternalCompilerError() << errinfo_comment("Unknown magic member.")); break; diff --git a/Types.cpp b/Types.cpp index bd55e2a8b..70cbec5d9 100644 --- a/Types.cpp +++ b/Types.cpp @@ -1160,7 +1160,8 @@ MagicType::MagicType(MagicType::Kind _kind): m_members = MemberList({{"sender", make_shared(0, IntegerType::Modifier::Address)}, {"gas", make_shared(256)}, {"value", make_shared(256)}, - {"data", make_shared(ArrayType::Location::CallData)}}); + {"data", make_shared(ArrayType::Location::CallData)}, + {"sig", make_shared(4)}}); break; case Kind::Transaction: m_members = MemberList({{"origin", make_shared(0, IntegerType::Modifier::Address)}, From bb5364dd66a85b287b0dc5b71bd810c7af671b0e Mon Sep 17 00:00:00 2001 From: Lefteris Karapetsas Date: Mon, 16 Mar 2015 15:46:04 +0100 Subject: [PATCH 2/2] Additional test for msg.sig --- ExpressionCompiler.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ExpressionCompiler.cpp b/ExpressionCompiler.cpp index 07f4e94ea..a9cacc65c 100644 --- a/ExpressionCompiler.cpp +++ b/ExpressionCompiler.cpp @@ -647,7 +647,8 @@ void ExpressionCompiler::endVisit(MemberAccess const& _memberAccess) else if (member == "data") m_context << u256(0) << eth::Instruction::CALLDATASIZE; else if (member == "sig") - m_context << u256(0) << eth::Instruction::CALLDATALOAD << (u256(0xffffffff) << (256 - 32))<< eth::Instruction::AND; + m_context << u256(0) << eth::Instruction::CALLDATALOAD + << (u256(0xffffffff) << (256 - 32)) << eth::Instruction::AND; else BOOST_THROW_EXCEPTION(InternalCompilerError() << errinfo_comment("Unknown magic member.")); break;