Skip to content

Commit

Permalink
Merge pull request #15 from vitelabs/development
Browse files Browse the repository at this point in the history
fix: fix bad address of function type. close #14
  • Loading branch information
vuilder0 authored Mar 3, 2022
2 parents e6990d2 + ef41f32 commit f89f688
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions libsolidity/codegen/YulUtilFunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,36 +21,48 @@ using namespace solidity;
using namespace solidity::util;
using namespace solidity::frontend;

// Solidity++: 168-bit address
string YulUtilFunctions::combineExternalFunctionIdFunction()
{
string functionName = "combine_external_function_id";
return m_functionCollector.createFunction(functionName, [&]() {
// steps:
// before: [11-byte zeros][21-byte address]
// make space for selector: [7-byte zeros][21-byte address][4-byte zeros]
// append selector: [7-byte zeros][21-byte address][4-byte selector]
// remove leading zeros: [21-byte address][4-byte selector][7-byte zeros]
return Whiskers(R"(
function <functionName>(addr, selector) -> combined {
combined := <shl64>(or(<shl32>(addr), and(selector, 0xffffffff)))
combined := <shl56>(or(<shl32>(addr), and(selector, 0xffffffff)))
}
)")
("functionName", functionName)
("shl32", shiftLeftFunction(32))
("shl64", shiftLeftFunction(64))
("shl56", shiftLeftFunction(56))
.render();
});
}

// Solidity++: 168-bit address
string YulUtilFunctions::splitExternalFunctionIdFunction()
{
string functionName = "split_external_function_id";
return m_functionCollector.createFunction(functionName, [&]() {
// steps:
// before: [21-byte address][4-byte selector][7-byte zeros]
// remove trailing zeros: [7-byte zeros][21-byte address][4-byte selector]
// extract selector: [28-byte zeros][4-byte selector]
// extract address: [11-byte zeros][21-byte address]
return Whiskers(R"(
function <functionName>(combined) -> addr, selector {
combined := <shr64>(combined)
combined := <shr56>(combined)
selector := and(combined, 0xffffffff)
addr := <shr32>(combined)
}
)")
("functionName", functionName)
("shr32", shiftRightFunction(32))
("shr64", shiftRightFunction(64))
("shr56", shiftRightFunction(56))
.render();
});
}
Expand Down Expand Up @@ -3526,7 +3538,7 @@ string YulUtilFunctions::cleanupFunction(Type const& _type)
switch (dynamic_cast<FunctionType const&>(_type).kind())
{
case FunctionType::Kind::External:
templ("body", "cleaned := " + cleanupFunction(FixedBytesType(24)) + "(value)");
templ("body", "cleaned := " + cleanupFunction(FixedBytesType(25)) + "(value)"); // Solidity++: 168-bit address: the function type has 25 bytes (21-byte address + 4-byte selector)
break;
case FunctionType::Kind::Internal:
templ("body", "cleaned := value");
Expand Down

0 comments on commit f89f688

Please sign in to comment.