Skip to content

Commit c341445

Browse files
ekpyronhrkrshnn
authored andcommitted
Maintain disambiguation when generating new functions in StackToMemoryMover.
1 parent 17d69e2 commit c341445

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

libyul/optimiser/StackToMemoryMover.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,12 @@ void StackToMemoryMover::operator()(FunctionDefinition& _functionDefinition)
158158
{},
159159
move(_functionDefinition.body)
160160
});
161+
// Generate new names for the arguments to maintain disambiguation.
162+
std::map<YulString, YulString> newArgumentNames;
163+
for (TypedName const& _var: stackParameters)
164+
newArgumentNames[_var.name] = m_context.dispenser.newName(_var.name);
165+
for (auto& parameter: _functionDefinition.parameters)
166+
parameter.name = util::valueOrDefault(newArgumentNames, parameter.name, parameter.name);
161167
// Replace original function by a call to the new function and an assignment to the return variable from memory.
162168
_functionDefinition.body = Block{_functionDefinition.debugData, move(memoryVariableInits)};
163169
_functionDefinition.body.statements.emplace_back(ExpressionStatement{
@@ -166,7 +172,7 @@ void StackToMemoryMover::operator()(FunctionDefinition& _functionDefinition)
166172
_functionDefinition.debugData,
167173
Identifier{_functionDefinition.debugData, newFunctionName},
168174
stackParameters | ranges::views::transform([&](TypedName const& _arg) {
169-
return Expression{Identifier{_arg.debugData, _arg.name}};
175+
return Expression{Identifier{_arg.debugData, newArgumentNames.at(_arg.name)}};
170176
}) | ranges::to<vector<Expression>>
171177
}
172178
});
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{
2+
{
3+
mstore(0x40, memoryguard(0x80))
4+
sstore(0, f(1,2,3))
5+
}
6+
function f(a, b, c) -> $b1 {
7+
if calldataload(add(sub(a,b),c)) {
8+
$b1 := 0
9+
leave
10+
}
11+
$b1 := 1
12+
}
13+
14+
}
15+
// ----
16+
// step: fakeStackLimitEvader
17+
//
18+
// {
19+
// {
20+
// mstore(0x40, memoryguard(0xa0))
21+
// sstore(0, f(1, 2, 3))
22+
// }
23+
// function f(a_2, b_3, c_4) -> $b1
24+
// {
25+
// mstore(0x80, 0)
26+
// f_1(a_2, b_3, c_4)
27+
// $b1 := mload(0x80)
28+
// }
29+
// function f_1(a, b, c)
30+
// {
31+
// if calldataload(add(sub(a, b), c))
32+
// {
33+
// mstore(0x80, 0)
34+
// leave
35+
// }
36+
// mstore(0x80, 1)
37+
// }
38+
// }

0 commit comments

Comments
 (0)