[Solidity] 230620 study
Chapter 1: Immutability of Contracts
- 한 번 체인에 등록된 Contract는 수정할 수 없다.
- Security를 포함한 특정 영역에서 문제점을 발견하게 돼도 수정 불가능
- 문제점을 수정반영한 contract를 새로 deploy하고 해당 contract의 address를 사용하여 서비스를 제공해야 한다
Chapter 2: Ownable Contracts
external,public으로 지정한 함수에는 private한 정보나 실행을 담아두면 안된다. 만약external혹은public으로 유지해야 하는 경우,constructor()와ownable을 통해 함수 실행자의 권한을 확인한 후 함수를 실행할 수 있다.
Chapter 3: onlyOwner Function Modifier
- modifier는 함수 정의의 맨 마지막에 정의된다
- modifier가 달린 function을 call하는 경우, modifier가 먼저 실행된 후 modifier 내의
_;를 만나면 다시 function을 실행 - Best use-cases: 함수를 실행하기 전에 quick require check를 하기 위해 modifier를 넣는다. 잘못된 접근으로 함수가 실행되는 것을 막기 위함
Chapter 4: Gas
- Struct Packing:
uint32, uint, uint32보다uint, uint32, uint32가 more cost efficient
Chapter 5: Time Units
Chapter 6: Zombie Cooldowns
function functionName(arg1, arg2, ...) external view returns(dataType) modifier- 함수 선언할 때 들어가는 선언자들 익숙해지기
Chapter 7: Public Funcions & Security
- malfunction 할 수 있는 여지가 있는 코드는 public을 제외한 다른 선언자로 변경할 것.
Chapter 8: More on Function Modifiers
Chapter 9: Zombie Modifier
calldata도memory와 같은 data storage의 종류이다.
Chapter 10: Saving Gas With view Functions
- Gas optimization 차원에서,
view함수는 gas를 발생시키지 않는다.- 정확하게 말하자면 user에 의해 externally called 된 경우만을 말한다.
- internally called 되면
view함수더라도 모든 EVM node에 의해 계산되기 때문에 gas가 발생한다.
Chapter 11: Storage is Expensive
- keyword
memorydoes not write anything to storage, but create a new array inside a function- exist until the end of the function call
Chapter 12: For loops
- C랑 같음