MCPcopy Create free account
hub / github.com/argotorg/solidity / constructMagicVariables

Function constructMagicVariables

libsolidity/analysis/GlobalContext.cpp:74–121  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

72}
73
74inline std::vector<std::shared_ptr<MagicVariableDeclaration const>> constructMagicVariables(langutil::EVMVersion _evmVersion)
75{
76 static auto const magicVarDecl = [](std::string const& _name, Type const* _type) {
77 return std::make_shared<MagicVariableDeclaration>(magicVariableToID(_name), _name, _type);
78 };
79
80 std::vector<std::shared_ptr<MagicVariableDeclaration const>> magicVariableDeclarations = {
81 magicVarDecl("abi", TypeProvider::magic(MagicType::Kind::ABI)),
82 magicVarDecl("addmod", TypeProvider::function(strings{"uint256", "uint256", "uint256"}, strings{"uint256"}, FunctionType::Kind::AddMod, StateMutability::Pure)),
83 magicVarDecl("assert", TypeProvider::function(strings{"bool"}, strings{}, FunctionType::Kind::Assert, StateMutability::Pure)),
84 magicVarDecl("block", TypeProvider::magic(MagicType::Kind::Block)),
85 magicVarDecl("blockhash", TypeProvider::function(strings{"uint256"}, strings{"bytes32"}, FunctionType::Kind::BlockHash, StateMutability::View)),
86 magicVarDecl("ecrecover", TypeProvider::function(strings{"bytes32", "uint8", "bytes32", "bytes32"}, strings{"address"}, FunctionType::Kind::ECRecover, StateMutability::Pure)),
87 magicVarDecl("erc7201", TypeProvider::function(strings{"string memory"}, strings{"uint256"}, FunctionType::Kind::ERC7201, StateMutability::Pure)),
88 magicVarDecl("gasleft", TypeProvider::function(strings(), strings{"uint256"}, FunctionType::Kind::GasLeft, StateMutability::View)),
89 magicVarDecl("keccak256", TypeProvider::function(strings{"bytes memory"}, strings{"bytes32"}, FunctionType::Kind::KECCAK256, StateMutability::Pure)),
90 magicVarDecl("msg", TypeProvider::magic(MagicType::Kind::Message)),
91 magicVarDecl("mulmod", TypeProvider::function(strings{"uint256", "uint256", "uint256"}, strings{"uint256"}, FunctionType::Kind::MulMod, StateMutability::Pure)),
92 magicVarDecl("now", TypeProvider::uint256()),
93 magicVarDecl("require", TypeProvider::function(strings{"bool"}, strings{}, FunctionType::Kind::Require, StateMutability::Pure)),
94 magicVarDecl("require", TypeProvider::function(strings{"bool", "string memory"}, strings{}, FunctionType::Kind::Require, StateMutability::Pure)),
95 magicVarDecl("require", TypeProvider::function(TypePointers{TypeProvider::boolean(), TypeProvider::magic(MagicType::Kind::Error)}, TypePointers{}, strings{2, ""}, strings{}, FunctionType::Kind::Require, StateMutability::Pure)),
96 magicVarDecl("revert", TypeProvider::function(strings(), strings(), FunctionType::Kind::Revert, StateMutability::Pure)),
97 magicVarDecl("revert", TypeProvider::function(strings{"string memory"}, strings(), FunctionType::Kind::Revert, StateMutability::Pure)),
98 magicVarDecl("ripemd160", TypeProvider::function(strings{"bytes memory"}, strings{"bytes20"}, FunctionType::Kind::RIPEMD160, StateMutability::Pure)),
99 magicVarDecl("selfdestruct", TypeProvider::function(strings{"address payable"}, strings{}, FunctionType::Kind::Selfdestruct)),
100 magicVarDecl("sha256", TypeProvider::function(strings{"bytes memory"}, strings{"bytes32"}, FunctionType::Kind::SHA256, StateMutability::Pure)),
101 magicVarDecl("sha3", TypeProvider::function(strings{"bytes memory"}, strings{"bytes32"}, FunctionType::Kind::KECCAK256, StateMutability::Pure)),
102 magicVarDecl("suicide", TypeProvider::function(strings{"address payable"}, strings{}, FunctionType::Kind::Selfdestruct)),
103 magicVarDecl("tx", TypeProvider::magic(MagicType::Kind::Transaction)),
104 // Accepts a MagicType that can be any contract type or an Integer type and returns a
105 // MagicType. The TypeChecker handles the correctness of the input and output types.
106 magicVarDecl("type", TypeProvider::function(
107 strings{},
108 strings{},
109 FunctionType::Kind::MetaType,
110 StateMutability::Pure,
111 FunctionType::Options::withArbitraryParameters()
112 )),
113 };
114
115 if (_evmVersion >= langutil::EVMVersion::cancun())
116 magicVariableDeclarations.push_back(
117 magicVarDecl("blobhash", TypeProvider::function(strings{"uint256"}, strings{"bytes32"}, FunctionType::Kind::BlobHash, StateMutability::View))
118 );
119
120 return magicVariableDeclarations;
121}
122
123}
124

Callers 1

GlobalContextMethod · 0.85

Calls 2

magicVariableToIDFunction · 0.85
functionFunction · 0.85

Tested by

no test coverage detected