Skip to content

Commit b5993c3

Browse files
authored
Merge pull request #2212 from crytic/fix-vyper-send
add support for send builtin
2 parents c162138 + a2d88b8 commit b5993c3

File tree

5 files changed

+35
-14
lines changed

5 files changed

+35
-14
lines changed

slither/core/declarations/solidity_variables.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@
116116
"_abi_encode()": [],
117117
"slice()": [],
118118
"uint2str()": ["string"],
119+
"send()": [],
119120
}
120121

121122

slither/vyper_parsing/expressions/expression_parsing.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,10 +153,10 @@ def parse_expression(
153153
parsed_expr.set_offset(expression.src, caller_context.compilation_unit)
154154
return parsed_expr
155155

156+
# `raw_call` and `send` are treated specially in order to force `extract_tmp_call` to treat this as a `HighLevelCall` which will be converted
157+
# to a `LowLevelCall` by `convert_to_low_level`. This is an artifact of the late conversion of Solidity...
156158
if called.value.name == "raw_call()":
157159
args = [parse_expression(a, caller_context) for a in expression.args]
158-
# This is treated specially in order to force `extract_tmp_call` to treat this as a `HighLevelCall` which will be converted
159-
# to a `LowLevelCall` by `convert_to_low_level`. This is an artifact of the late conversion of Solidity...
160160
call = CallExpression(
161161
MemberAccess("raw_call", "tuple(bool,bytes32)", args[0]),
162162
args[1:],
@@ -183,6 +183,17 @@ def parse_expression(
183183

184184
return call
185185

186+
if called.value.name == "send()":
187+
args = [parse_expression(a, caller_context) for a in expression.args]
188+
call = CallExpression(
189+
MemberAccess("send", "tuple()", args[0]),
190+
args[1:],
191+
"tuple()",
192+
)
193+
call.set_offset(expression.src, caller_context.compilation_unit)
194+
195+
return call
196+
186197
if expression.args and isinstance(expression.args[0], VyDict):
187198
arguments = []
188199
for val in expression.args[0].values:

tests/e2e/vyper_parsing/snapshots/ast_parsing__vyper_cfgir_builtins_c__0.txt

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,23 @@ EXPRESSION:
1616
user_shares.append(1)
1717

1818
IRs:
19-
REF_1 -> LENGTH user_shares
20-
TMP_3(uint256) := REF_1(uint256)
21-
TMP_4(uint256) = TMP_3 (c)+ 1
22-
REF_1(uint256) (->user_shares) := TMP_4(uint256)
23-
REF_2(uint256) -> user_shares[TMP_3]
24-
REF_2(uint256) (->user_shares) := 1(uint256)"];
19+
REF_2 -> LENGTH user_shares
20+
TMP_4(uint256) := REF_2(uint256)
21+
TMP_5(uint256) = TMP_4 (c)+ 1
22+
REF_2(uint256) (->user_shares) := TMP_5(uint256)
23+
REF_3(uint256) -> user_shares[TMP_4]
24+
REF_3(uint256) (->user_shares) := 1(uint256)"];
2525
2->3;
2626
3[label="Node Type: EXPRESSION 3
2727

2828
EXPRESSION:
2929
user_shares.pop()
3030

3131
IRs:
32-
REF_4 -> LENGTH user_shares
33-
TMP_6(uint256) = REF_4 (c)- 1
34-
REF_5(uint256) -> user_shares[TMP_6]
35-
REF_5 = delete REF_5
36-
REF_6 -> LENGTH user_shares
37-
REF_6(uint256) (->user_shares) := TMP_6(uint256)"];
32+
REF_5 -> LENGTH user_shares
33+
TMP_7(uint256) = REF_5 (c)- 1
34+
REF_6(uint256) -> user_shares[TMP_7]
35+
REF_6 = delete REF_6
36+
REF_7 -> LENGTH user_shares
37+
REF_7(uint256) (->user_shares) := TMP_7(uint256)"];
3838
}

tests/e2e/vyper_parsing/snapshots/ast_parsing__vyper_cfgir_builtins_test_builtins__0.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,4 +115,12 @@ x = self.balance
115115

116116
IRs:
117117
x(uint256) := self.balance(uint256)"];
118+
14->15;
119+
15[label="Node Type: EXPRESSION 15
120+
121+
EXPRESSION:
122+
msg.sender.send(x)
123+
124+
IRs:
125+
TMP_2 = SEND dest:msg.sender value:x"];
118126
}

tests/e2e/vyper_parsing/test_data/builtins.vy

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ def test_builtins():
1616
m: address = tx.origin
1717
n: uint256 = tx.gasprice
1818
x: uint256 = self.balance
19+
send(msg.sender, x)
1920

2021
@external
2122
def c(x: uint256):

0 commit comments

Comments
 (0)