felipe (@mande_eth) header
felipe (@mande_eth) profile picture
Joined February 2022
Photo by felipe (@mande_eth)Photo by felipe (@mande_eth)Photo by felipe (@mande_eth)Photo by felipe (@mande_eth)Photo by felipe (@mande_eth)Photo by felipe (@mande_eth)Photo by felipe (@mande_eth)Photo by felipe (@mande_eth)Photo by felipe (@mande_eth)Photo by felipe (@mande_eth)
Excellent thread about metamorphic contracts by @0xOwenThurm ! Here is my contribution on how they can still be created for visual learners like me:
Is this the 𝗘𝗡𝗗 of metamorphic contracts!? What is EIP-6780 and what does it mean for metamorphic contracts? 🤔 Let's find out in a few seconds. 🧵
1
1
7
743
I just received my first compensation for an audit on @code4rena! 🥹😍
Just submitted my first report to @code4rena ! 🎉
5
51
2,902
Just submitted my first report to @code4rena ! 🎉
2
1
15
4,281
getting to the finish line on damnvulnerabledefi.xyz (12/15), feeling astonished by how much I've learned so far and would definitely recommend doing them for every solidity devs and junior auditors. Props to this amigo @tinchoabbate 🐐
2
4
501
dont waste too much time on 7, not worth the time in my opinion, get a hint
1
166
Uniswap cheatsheet - basic concepts Reference: github.com/runtimeverificati…
1
13
92
6,805
If you add fee (ρ) to this model, each swap would increase the x.y value. Those increments would mint new liquidity tokens to liquidity holders (liquidity providers) based on their shares. New x.y > k value is calculated as follows:
1
3
723
A bad actor can send a transaction from your wallet if you sign a message like this. Let's reproduce this attack:
1
3
2
29
1,876
How can that even happen? let's understand how our transactions are sent. In the Ethereum JSON-RPC specification we see two methods: eth_sendTransaction eth_sendRawTransaction former is the one that triggers your metamask, asking you to confirm the tx, the latter don't
1
1
347
This thread explains a vulnerability on signature verification. (v, r, s) and (v, r, -s mod(n)) are valid signatures for the same message hash 🚩 n comes from secp256k1 specs github.com/ethereum/go-ether… Openzeppelin address this on ECDSA library by accepting only the lower s value.
🤯 The clearest, most comprehensive thread on signature malleability of all time! It’s a hefty claim, I know. But if you give me the chance, I will not disappoint. ✊ 🎩🔮 Allow me to demystify this age-old attack 💫 Let’s hop in 👇
2
6
1,116
This 15 byte sized contract calculates the sum of two numbers. I created it using only EVM opcodes, no solidity and no compilation involved. Goerli: goerli.etherscan.io/address/… Come see how I did it
3
24
97
14,814
To be able to deploy a contract having its bytecode rather than the solidity code you need to manually send a transaction to the null address passing the bytecode on the data field. This is actually how every contract is deployed under the hood.
1
1
3
654
Understanding the contract creation bytecode 📋 To deploy a contract you have to send a transaction to the null address (not to be confused with 0x000... address) with the contract creation bytecode as the transaction data = <init code><contract bytecode><constructor arguments>
1
5
1
38
5,669
Init bytecode, also called constructor bytecode, is the code that is executed in the contract creation transaction. It is meant to resolve your constructor logic, apply the results to your contract bytecode and return the runtime bytecode, the one that gets stored on the chain.
1
1
252
learning foundry 🔥🔨 it feels good to do everything in solidity
1
5
236
Here on my example: on the not indexed event, LOG1 is being called on top of the following stack: 0x00...80 (offset) 0x00...20 (size) 0x49...91 (topic) it is getting the address value from memory so LOG1 is actually costing 1006 because of the memory expansion
Replying to @0xmonsoon
At the beginning this thread might have read like one where I introduce you to some EVM quirk and use it explain the scenario. But no. I don't know why this is happening. Have spent a couple of hours looking but not been able to figure it out. Please explain it to me anon 😭😭
2
1
3
593
on the indexed event, LOG2 is being called on top of the stack: 0x00...80 (offset) 0x00...00 (size) 0x2f..59 (topic 1 - hash signature) 0x00..e3 (topic 2 - address) not using memory this time, so no additional cost for memory expansion: 1125 gas cost
1
1
152
That's a very clever way to implement a reentrancy guard 🤔 Reading a variable from storage twice costs different amount of gas each time because the slot will be warm after the first read.
This is the coolest thing I've seen today. Reentrancy guard that reverts if the slot is warm. Author: @rage_pit @transmissions11 Can we use this in the golf-course!?
1
173
I just joined @code4rena as a warden 🫡 I am still early on my studies but let's start getting used to the contests 🔥
1
6
392
An outstanding article about the EVM stack, worth a read
It’s out! 🪂 🎉 Part 4 of the All About Solidity Data Locations subseries Some cool learnings: - how block scopes work {} (the mystery unraveled) - what is the « call stack » vs the « stack » - fixing « stack too deep » error #Solidity #SmartContracts betterprogramming.pub/solidi…
1
2
215
@JeanCavallera I would love to see one example of the stack underflow in practice. I tried some inline assembly but couldn't reproduce this
1
1
119
Shouldn't it throw the compiler error "Stack too deep" ? 🤔 How was this code compiled with solidity 0.8.17 and the function was able to access items deeper than index 16 in the stack?
1
3
312
That's because you can change the way the EVM compiles your contract. Instead of going straight from solidity to EVM opcodes you can use the "intermediate representation in Yul" by adding "viaIR": true to your compiler_config.json docs.soliditylang.org/en/v0.…
2
3
249
Arithmetic overflow/underflow, the unchecked block and how you can save gas on math operations. In solidity version < 0.8 there is no arithmetic check and if an overflow happens the variable simply cycle back to zero and in an underflow it goes to the maximum possible value.
1
7
305
But in solidity version 0.8.x, there is a check on math operations and if an overflow or underflow happens it reverts the transaction instead. This new check execution is not cheap though, that's one of the reasons it was also shipped alongside with the unchecked block
1
3
52
Have you ever seen a stack overflow on EVM? I guess you wouldn't find it everyday in the wild. But let's push through the limits and see how it shows up, shall we?🤠 Let's start by creating a function with 1022 local variables.
2
2
1
9
720
The EVM stack has 1024 slots. How many of these slots can we use to store local variables? In our 1022 variables function, it is already showing "stack limit reached" when we try to call it, but if we remove one, having now a 1021 variables function, the transaction succeeds.
1
2
86
Have you ever ran into this compile error? That happens when your function declares too much local variables, right? Not really... Your function can have hundreds of local variables but you can only access the last 16 of them because we only have the opcodes DUP1 to DUP16
2
3
1
14
1,278
In this example you can access variable a_5 and you will see a DUP16 instruction on the EVM stack, but if you try to access a_4 you get the said compile error because the opcode DUP17 doesn't exist, so this data is unreachable from line 43.
1
4
224
Two functions doing the same thing, but the latter is 100+ gas more expensive🤔 The EVM will take a shortcut on the first function and use the opcode SELFBALANCE (5 gas) to evaluate address(this).balance
2
1
20
1,814
But for the second function it will first evaluate (address(this)) using the opcode ADDRESS (2 gas) and then calling BALANCE (100 gas). But can you explain why it also did a PUSH20 0xfff... + AND with the ADDRESS before calling BALANCE ?
3
1
381
61 0100 60 40 52 (61) PUSH2 0x0100 (60) PUSH1 0x40 (52) MSTORE It tells us that the memory between 0x80 and 0x00ff are in use (4x 32bytes) and they store the 4 immutable variables: _factoryV2, _positionManager, factoryV3, _WETH
Replying to @0xmonsoon
13/n This is usually the case but there do exist contracts which don't start with 0x6080604052. Like the Uniswap V3 Router 2: etherscan.io/address/0x68b34… Can you figure out why anon?
2
174