Skip to content

[FIL-72] Added callactor support, contract create contract #2

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions libevmasm/GasMeter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,9 @@ GasMeter::GasConsumption GasMeter::estimateMax(AssemblyItem const& _item, bool _
case Instruction::SELFBALANCE:
gas = runGas(Instruction::SELFBALANCE);
break;
case Instruction::CALLACTOR:
gas = runGas(Instruction::CALLACTOR);
break;
default:
gas = runGas(_item.instruction());
break;
Expand Down
6 changes: 4 additions & 2 deletions libevmasm/Instruction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,8 @@ std::map<std::string, Instruction> const solidity::evmasm::c_instructions =
{ "CREATE2", Instruction::CREATE2 },
{ "REVERT", Instruction::REVERT },
{ "INVALID", Instruction::INVALID },
{ "SELFDESTRUCT", Instruction::SELFDESTRUCT }
{ "SELFDESTRUCT", Instruction::SELFDESTRUCT },
{ "CALLACTOR", Instruction::CALLACTOR }
};

static std::map<Instruction, InstructionInfo> const c_instructionInfo =
Expand Down Expand Up @@ -321,7 +322,8 @@ static std::map<Instruction, InstructionInfo> const c_instructionInfo =
{ Instruction::CREATE2, { "CREATE2", 0, 4, 1, true, Tier::Special } },
{ Instruction::REVERT, { "REVERT", 0, 2, 0, true, Tier::Zero } },
{ Instruction::INVALID, { "INVALID", 0, 0, 0, true, Tier::Zero } },
{ Instruction::SELFDESTRUCT, { "SELFDESTRUCT", 0, 1, 0, true, Tier::Special } }
{ Instruction::SELFDESTRUCT, { "SELFDESTRUCT", 0, 1, 0, true, Tier::Special } },
{ Instruction::CALLACTOR, { "CALLACTOR", 0, 5, 1, true, Tier::Base } }
};

void solidity::evmasm::eachInstruction(
Expand Down
2 changes: 1 addition & 1 deletion libevmasm/Instruction.h
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ enum class Instruction: uint8_t
DELEGATECALL, ///< like CALLCODE but keeps caller's value and sender
CREATE2 = 0xf5, ///< create new account with associated code at address `sha3(0xff + sender + salt + init code) % 2**160`
STATICCALL = 0xfa, ///< like CALL but disallow state modifications

CALLACTOR, ///< call contract actor
REVERT = 0xfd, ///< halt execution, revert state and return output data
INVALID = 0xfe, ///< invalid instruction for expressing runtime errors (e.g., division-by-zero)
SELFDESTRUCT = 0xff ///< halt execution and register account for later deletion
Expand Down
1 change: 1 addition & 0 deletions libevmasm/SemanticInformation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ SemanticInformation::Effect SemanticInformation::memory(Instruction _instruction
case Instruction::CALLCODE:
case Instruction::DELEGATECALL:
case Instruction::STATICCALL:
case Instruction::CALLACTOR:
return SemanticInformation::Write;

case Instruction::CREATE:
Expand Down
2 changes: 2 additions & 0 deletions libsolidity/analysis/GlobalContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ int magicVariableToID(std::string const& _name)
else if (_name == "tx") return -26;
else if (_name == "type") return -27;
else if (_name == "this") return -28;
else if (_name == "callactor") return -29;
else
solAssert(false, "Unknown magic variable: \"" + _name + "\".");
}
Expand Down Expand Up @@ -92,6 +93,7 @@ inline vector<shared_ptr<MagicVariableDeclaration const>> constructMagicVariable
magicVarDecl("sha256", TypeProvider::function(strings{"bytes memory"}, strings{"bytes32"}, FunctionType::Kind::SHA256, false, StateMutability::Pure)),
magicVarDecl("sha3", TypeProvider::function(strings{"bytes memory"}, strings{"bytes32"}, FunctionType::Kind::KECCAK256, false, StateMutability::Pure)),
magicVarDecl("suicide", TypeProvider::function(strings{"address payable"}, strings{}, FunctionType::Kind::Selfdestruct)),
magicVarDecl("callactor", TypeProvider::function(strings{"address payable", "uint256", "bytes memory"}, strings{"bytes memory"}, FunctionType::Kind::CallActor, false, StateMutability::Payable)),
magicVarDecl("tx", TypeProvider::magic(MagicType::Kind::Transaction)),
// Accepts a MagicType that can be any contract type or an Integer type and returns a
// MagicType. The TypeChecker handles the correctness of the input and output types.
Expand Down
2 changes: 2 additions & 0 deletions libsolidity/ast/Types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2869,6 +2869,7 @@ string FunctionType::richIdentifier() const
case Kind::ObjectCreation: id += "objectcreation"; break;
case Kind::Assert: id += "assert"; break;
case Kind::Require: id += "require"; break;
case Kind::CallActor: id += "callactor"; break;
case Kind::ABIEncode: id += "abiencode"; break;
case Kind::ABIEncodePacked: id += "abiencodepacked"; break;
case Kind::ABIEncodeWithSelector: id += "abiencodewithselector"; break;
Expand Down Expand Up @@ -3156,6 +3157,7 @@ MemberList::MemberMap FunctionType::nativeMembers(ASTNode const* _scope) const
case Kind::Creation:
case Kind::BareCall:
case Kind::BareCallCode:
case Kind::CallActor:
case Kind::BareDelegateCall:
case Kind::BareStaticCall:
{
Expand Down
1 change: 1 addition & 0 deletions libsolidity/ast/Types.h
Original file line number Diff line number Diff line change
Expand Up @@ -1156,6 +1156,7 @@ class FunctionType: public Type
ObjectCreation, ///< array creation using new
Assert, ///< assert()
Require, ///< require()
CallActor, ///< CALLACTOR
ABIEncode,
ABIEncodePacked,
ABIEncodeWithSelector,
Expand Down
17 changes: 17 additions & 0 deletions libsolidity/codegen/ExpressionCompiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -914,6 +914,23 @@ bool ExpressionCompiler::visit(FunctionCall const& _functionCall)
m_context << Instruction::BLOCKHASH;
break;
}
case FunctionType::Kind::CallActor:
{
acceptAndConvert(*arguments[0], *function.parameterTypes()[0], true);
acceptAndConvert(*arguments[1], *function.parameterTypes()[1], true);
arguments[2]->accept(*this);
utils().fetchFreeMemoryPointer();
utils().packedEncode(
{arguments[2]->annotation().type},
{TypeProvider::array(DataLocation::Memory, true)}
);
utils().toSizeAfterFreeMemoryPointer();

m_context << Instruction::CALLACTOR;

utils().returnDataToArray();
break;
}
case FunctionType::Kind::AddMod:
case FunctionType::Kind::MulMod:
{
Expand Down
2 changes: 1 addition & 1 deletion libsolidity/codegen/ir/IRGeneratorForStatements.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1791,7 +1791,7 @@ void IRGeneratorForStatements::endVisit(MemberAccess const& _memberAccess)
else
define(_memberAccess) << formatNumber(integerType->max()) << "\n";
}
else if (set<string>{"encode", "encodePacked", "encodeWithSelector", "encodeWithSignature", "decode"}.count(member))
else if (set<string>{"encode", "encodePacked", "encodeWithSelector", "encodeWithSignature", "decode", "callactor"}.count(member))
{
// no-op
}
Expand Down
4 changes: 4 additions & 0 deletions test/tools/yulInterpreter/EVMInstructionInterpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,10 @@ u256 EVMInstructionInterpreter::eval(
accessMemory(arg[4], arg[5]);
logTrace(_instruction, arg);
return 0;
case Instruction::CALLACTOR:
accessMemory(arg[3], arg[4]);
logTrace(_instruction, arg);
return 0;
case Instruction::RETURN:
{
bytes data;
Expand Down