The One Question bounty closes Thursday 10 December.

Join in
We Them Media logo We Them Media Support us

Students Share Their Experience With Smart Contract Security Class Week 13

The picture loads from YouTube. The player loads only when you press Play. Turn on captions in the player if you need them.

A Cohort 9 student summarises week 13 on smart contract security and gas. They name practice platforms and audit firms, then explain gas savings such as caching storage, packing variables and custom errors, and vulnerabilities such as reentrancy and reading private storage, and thank their mentor.

Not by We Them Media Channel: Web3Bridge. Published Tuesday 28 November 2023.

Titles are the owner’s. It plays from their channel.

Transcript

This transcript may contain errors. This video belongs to Web3Bridge. Letters mark each change of speaker.

These are the speakers’ own words. We have not checked their claims.

0:09 A: Web3 Bridge Cohort 9, sponsored by Base.

0:11 B: I'll give you a summary of week 13 here at Web3 Bridge. Week 13, we were introduced to smart contract security and amendments. We went further to show the different platforms to improve our knowledge of smart contract security. We looked at Solidity where you have various reports of different audits compiled.

0:41 C: We were introduced to Solidity, we were introduced to Ethernaut, we were introduced to NodeGuardian. These are all platforms to actually advance your smart contract security knowledge. We were also introduced to Platforms like CodeArena, Sequoia, and all these security, advanced contract security firms that actually aid smart contract developers to improve their knowledge in smart contract security.

1:12 D: Gas optimization is basically a way to reduce the amount of gas we use. We can reduce the amount of gas we can use while executing our smart contract functions. So one of them is by reducing access to storage. If you can actually store a state variable In your function by caching it to like a memory instead of you like, um, accessing the storage or reading from storage back and forth over and over. You can actually cache it in memory, have that as a memory variable. You can also pack state- you can also pack, um, variables in slots instead of using a unit 1 to 256. Unit 128 or Unit 8 as well. If you see that, oh, this particular, um, this particular value would necessarily pass Unit 128. And these are the downsides because the EVM has to unpack if you unpack, and that also requires, um, gas. So you shouldn't pack variables loosely. So most of the time, for it to work, you should pack variables. If These variables have to be accessed together. Most of the time, it's always the same particular variable in the scope.

2:29 B: We looked at the fact that if I- in terms of errors, custom errors cause cheaper gas than using a normal require statement with strings. So if you write your custom error, it costs cheaper gas than using a require statement. Then we looked at the fact that when you have to call an external call, should be cached, that is when you need to call them multiple times. It's better you just cache them once, and every time you reference it back, you are not going to pay, just for the first time that it was cached.

3:02 D: We also looked at different vulnerabilities smart contracts can have. Then we have CTS. This CTS actually exposed me to different vulnerabilities, e.g., the reentrancy Reentrancy is saying that a particular contract calls into another contract and executes a function. While the function is being executed, another function is being executed as well in the contract. The reentrancy can be overcome by you making a state change before making an external call. E.g., you can actually update your state during multiplication, so update your state, change before you do a transfer or something. And, um, it is also advised not to store sensitive data on the blockchain. Okay, you may say that, okay, maybe something you see like a private variable or private visibility, this does not mean that your contract, your, the storage cannot be accessed, or the value in that source can actually be accessed by just querying the data on by using Assembly or Ethers.js or Web3.js. We also had a vulnerability where we were asked to check for when a smart contract has zero code. I mean, that was a bit difficult. I was not like- I didn't have that knowledge prior. So when we solved that system, I realized that at the construction time, the contract has zero code. And I'm actually so grateful to our mentor, Winsimura. She has been so, so good in our development journey, smart contract development journey. It's been so great. Thank you to Web3 Bridge. Thank you. Bye.

4:53 A: Web3 Bridge Cohort 9, sponsored by Base.

More from this hub

Something wrong, or a video you want off this page? Write to wethem.xyz@gmail.com and it is fixed or taken down within 48 hours.