Skip to content

Commit

Permalink
add more content from notes + update README
Browse files Browse the repository at this point in the history
  • Loading branch information
CJ42 committed Oct 4, 2022
1 parent 0bc3cd5 commit 2bb032d
Show file tree
Hide file tree
Showing 8 changed files with 121 additions and 15 deletions.
4 changes: 4 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"tabWidth": 2,
"useTabs": false
}
27 changes: 13 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,18 @@ You will find code snippets and analogies that will help you understand and impr
**All About...**

| | | |
|:--- |:--- |:--- |
| [`address`](./articles/Addresses.md) | [cryptographic functions](./articles/Cryptographic-functions.md) | [`mapping`](./articles/Mappings.md) |
| [arrays](./articles/Arrays.md) | [Data Location (`storage`, `memory`, `calldata`)](./articles/Data-Locations.md) | [`modifier`](./articles/Modifiers.md) |
| [assembly](./articles/Assembly.md) | [`enum`](./articles/Enums.md) | [numbers](./articles/Numbers.md) |
| [blocks & transaction properties](./articles/Blocks-Txs.md) | [error handling](./articles/Error-Handling.md) | [`string`](./articles/Strings.md) |
| [`bool`](./articles/Boolean.md) | [ether units](./articles/Ether-Units.md) | [style](./articles/Style.md) |
| [`bytes`](./articles/Bytes.md) | [`event`](./articles/Events.md) | [tuples](./articles/Tuples.md) |
| [comments](./articles/Comments.md) | [`function`](./articles/Functions.md) | [`struct`](./articles/Structs.md) |
| [compiler](./articles/Compiler.md) | [inheritance](./articles/Inheritance.md) | [variables (in general)](./articles/Variables.md) |
| [`constructor`](./articles/Constructors.md) | [`interface`](./articles/Interfaces.md) | |
| [control flow](./articles/Control-Flow.md) | [`library`(librarie contracts)](./articles/Libraries.md) | |

| | | |
| :---------------------------------------------------------- | :------------------------------------------------------------------------------ | :------------------------------------------------------------------------ |
| [`address`](./articles/Addresses.md) | [cryptographic functions](./articles/Cryptographic-functions.md) | [`mapping`](./articles/Mappings.md) |
| [arrays](./articles/Arrays.md) | [Data Location (`storage`, `memory`, `calldata`)](./articles/Data-Locations.md) | [`modifier`](./articles/Modifiers.md) |
| [assembly](./articles/Assembly.md) | [`enum`](./articles/Enums.md) | [numbers](./articles/Numbers.md) |
| [blocks & transaction properties](./articles/Blocks-Txs.md) | [error handling](./articles/Error-Handling.md) | [overriding (for functions, modifiers, etc...)](./articles/Overriding.md) |
| [`bool`](./articles/Boolean.md) | [ether units](./articles/Ether-Units.md) | [`string`](./articles/Strings.md) |
| [`bytes`](./articles/Bytes.md) | [`event`](./articles/Events.md) | [style](./articles/Style.md) |
| [comments](./articles/Comments.md) | [`function`](./articles/Functions.md) | [tuples](./articles/Tuples.md) |
| [compiler](./articles/Compiler.md) | [inheritance](./articles/Inheritance.md) | [`struct`](./articles/Structs.md) |
| [`constructor`](./articles/Constructors.md) | [`interface`](./articles/Interfaces.md) | [variables (in general)](./articles/Variables.md) |
| [control flow](./articles/Control-Flow.md) | [`library`(librarie contracts)](./articles/Libraries.md) | |

## References

Expand All @@ -41,4 +40,4 @@ For references related to each specific topic of the smart language, see the **R

- [Solidity `delegatecall`: usage and pitfalls](https://medium.com/@jeremythen16/solidity-delegatecall-usage-and-pitfalls-5c37eaa5bd5d)

- [EVM Development Starter Kit](https://freddycoen.medium.com/evm-starter-kit-1790bcc992ef)
- [EVM Development Starter Kit](https://freddycoen.medium.com/evm-starter-kit-1790bcc992ef)
15 changes: 15 additions & 0 deletions articles/Conversions.md
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)

7 changes: 6 additions & 1 deletion articles/Error-Handling.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,9 @@ require(bool condition, string memory message);
revert(string memory reason);
```

**revert()** will abort the execution and reverse the state. Like **require()**, it is also used to check errors on inputs or external components.
**revert()** will abort the execution and reverse the state. Like **require()**, it is also used to check errors on inputs or external components.


## References

- [try / catch (from Twitter)](https://twitter.com/cleanunicorn/status/1574808522130194432?s=46&t=ZSDpK77I_lTaaZNacgpUEA)
9 changes: 9 additions & 0 deletions articles/Overriding.md
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.
21 changes: 21 additions & 0 deletions articles/Security.md
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.
9 changes: 9 additions & 0 deletions articles/data-locations/Calldata.md
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)
44 changes: 44 additions & 0 deletions articles/data-locations/Code.md
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

0 comments on commit 2bb032d

Please sign in to comment.