-
Notifications
You must be signed in to change notification settings - Fork 110
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add more content from notes + update README
- Loading branch information
Showing
8 changed files
with
121 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"tabWidth": 2, | ||
"useTabs": false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# All About Conversions | ||
|
||
## Explicit conversion | ||
|
||
### From address to Contract or Interface type: | ||
|
||
- [] write content based on the following links: | ||
- https://stackoverflow.com/questions/71041850/is-there-a-difference-between-casting-to-interface-and-to-a-contract-instance | ||
- https://github.com/ethereum/solidity/issues/12622 | ||
|
||
# References | ||
|
||
- [Stackoverflow - Is there a difference between casting to an interface or to a contract instance?](https://stackoverflow.com/questions/71041850/is-there-a-difference-between-casting-to-interface-and-to-a-contract-instance) | ||
- [Explicit downcast does not work for inherited contracts/interfaces - Issue #12622 - Solidity Github](https://github.com/ethereum/solidity/issues/12622) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# All About Overriding | ||
|
||
Overriding function visibility. You can override the visibility of a function: | ||
- from external to public ✅ | ||
- but not from public to external ❌ | ||
|
||
Therefore, the function visibility can be overriding by opening it up, from only being called by the external world to also being able to call the function from within the contract (through inheritance). | ||
|
||
This should therefore be considered a must do when writing smart contracts when it comes to security. You should mark the functions to the most restricted visibility first, and then open up the visibility by overriding. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
## All About Smart Contract Security | ||
|
||
> This page should be much larger, and probably its own repository overtime. The scope of smart contract and solidity security is too big for one markdown page. | ||
Security / Ethical Hacking | ||
|
||
You can do this (mainnet hard fork) as suggested by Hadrien in the comments. | ||
|
||
https://twitter.com/paulrberg/status/1574375484120616961?s=46&t=ZSDpK77I_lTaaZNacgpUEA | ||
|
||
https://blog.ethereum.org/2016/06/10/smart-contract-security/ | ||
|
||
Upgradeability: be careful when the contract get upgraded that it is initialised properly. | ||
|
||
Use Pausable on the contract, to pause any interaction while making fixes, or if it got exploited. | ||
|
||
Visibility: keep things closed, and open it up. | ||
|
||
Be very careful with initialize(…) functions!!! | ||
|
||
You should never audit your own code. You should get a new pair of eyes, because you are developing and you are in a particular mindset, so you are creating the bug. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,14 @@ | ||
# All About Calldata | ||
|
||
## Upcoming content | ||
|
||
- [] Explain why you can’t use calldata inside internal functions. For instance if you constructed something in memory (e.g: a struct), and try to pass it to an internal function that specify calldata in a parameter. it will not compile. Explain why (good example). | ||
- [] Explain how to retrieve some part of the calldata, using array slices and calldata offset. | ||
- [] Explain what is happening under the hood for the following examples. | ||
- Function takes calldata parameter. A variable inside is defined as calldata. What are the opcodes and what happen under the hood? | ||
- Function takes calldata parameter. A variable inside defined as memory. What are the opcodes, what is happening under the hood? | ||
- [] Explain why it is cheaper to use calldata instead of memory (in a function arguments, different number of opcodes + differences). | ||
- [] Calldata is not a special place in memory. It’s its own location. Explain this and make it clear. | ||
## References | ||
|
||
- [Solidity `msg.sender`](https://medium.com/@devrann.simsek/solidity-msg-sender-9072c1561966) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# All About Code | ||
|
||
## Introduction | ||
|
||
Code as a data location refers the contract bytecode. Once a contract has been deployed, its code cannot be changed. Therefore, data and variables stored into code are read only and not editable. | ||
|
||
The code is made of bytes (unlike storage that is made of “slots”). | ||
|
||
## How to store variables in the contract's code? | ||
|
||
You can define variables to be stored inside the contract bytecode using either the keyword `constant` or `immutable`. | ||
|
||
More details below. | ||
|
||
## Immutable | ||
|
||
Variables defined as `immutable` can be defined only during deployment via the constructor. | ||
|
||
Only variables of direct type can go into code as immutable. Meaning variables like `uintN`, `bytesN` or `address`. | ||
|
||
Variables of types array cannot be defined as `immutable` at the moment. It is currently not supported. | ||
|
||
It is impossible to predict where immutable variables will be placed in the code (= comtract’s code/bytecode). (Hypothesis: this might especially be the case if the optimizer is on, and depending on its settings). | ||
|
||
An important thing to note is that immutable variables will not appear in the code if they are never read from (in the contract logic / execution or functions). So they will not appear anywhere in the code if they are simply defined in the contract, but not used anywhere in the contract. | ||
Immutables are simply inline into the code wherever they are read from. Therefore if the constant is never read from, it’s value isn’t stored anywhere in the code. | ||
|
||
|
||
## Layout of code | ||
|
||
The code has no notion of “slots”; the variables are simply placed wherever the compiler places them, among the code. | ||
|
||
Immutables in code are padded, but they have unusual padding. | ||
|
||
> Prior to Solidity 0.8.9, padding worked a bit differently in code; in code, all types were zero-padded, even if they would ordinarily be sign-padded. This did not affect which side they are padded on. | ||
## Finding variables inside the contract bytecode | ||
|
||
You can use the Solidity compiler’s `immutableReferences` output to determine this information. To understand the Data layout of code, and how to access the variables defined inside it, we rely on the compiler output. | ||
|
||
# References | ||
|
||
- https://ethereum.stackexchange.com/questions/107894/storing-immutable-state-in-contract-data | ||
|