foundry-rs / book

A book on all things Foundry, available at https://book.getfoundry.sh.
https://book.getfoundry.sh
Apache License 2.0
813 stars 645 forks source link

feat: add a `CREATE3` tutorial #1059

Open Genesis3800 opened 11 months ago

Genesis3800 commented 11 months ago

I totally understand if this feels repetitive since I also wrote the CREATE2 article, but I genuinely feel there are nuances that justify writing a tutorial on CREATE3, since there is no actual 'CREATE3' opcode. I recently got this in my DMs. image

Also I could not find a proper end-to-end tutorial on CREATE3. I could work with the solady or solmate libraries to write a tutorial for a CREATE3 factory implementation.

If given the go ahead, I'll make this my best work ever.

Genesis3800 commented 11 months ago

Hey @onbjerg , @Evalir , bump pls πŸ˜„

I'm totally cool with a rejection too no joke, just proposed this cause I felt there's a gap.

P.S: If we do this, I wanna include sections on deploying ,and then verifying the contracts deployed through a create3 factory too.

mattsse commented 11 months ago

more tutorials good!

Genesis3800 commented 11 months ago

more tutorials good!

Damn damn damn, this makes me so stoked. I'll still wait a bit for anyone else to get their comments in. Will take this up after the weekend if nothing more is commented. CC: @mds1 maybe you could want a say in this?

Evalir commented 11 months ago

feel free to take it @Genesis3800 !

mds1 commented 11 months ago

One thought is that there's probably a few create3 implementations. I'm working with @pcaversaccio to make the one in https://github.com/pcaversaccio/createx a canonical oneβ€”I'm biased of course, but hopefully within ~2 weeks that one will be deployed and maybe that's the one we should reference and use in the tutorial.

Could you also give an outline of what you're planning to include? As you'll see in the docs/comments for CreateX, there are a few security concerns to be around of with create3 that we need to cover

Genesis3800 commented 11 months ago

Damn, that's a news and a half @mds1 . Best of luck. I am open to waiting for your implementation to get finalised while I prep with as much of the tutorial as I can on my own.

Here's an outline of what I was planning:

  1. Introduction - What is CREATE3 and why bother with a CREATE3 implementation despite having the opcode CREATE2?

  2. CREATE3 factory - Go over a CREATE3 factory implementation. I like a factory contract instead of a library in a tutorial since the factory is easier to plug and play for the end user. I will go over the code in the same way as the CREATE2 article, step by step.

  3. Testing - Writing a couple of basic tests that work with 3 simple contracts: the factory, a barebones increment counter contract, and a barebones decrement counter contract. We will show that the CREATE3 factory deploys both of them to the same address by showing that the test will fail to deploy the second of the 2 contracts if supplied with the same salt.

  4. Deploying and Verifying - Deploy and verify both of the barebone contracts to two different chains at the same address as a proof of implementation.

What do you think?

P.S: @pcaversaccio I would love the chance to work with you, even if indirectly so. You're one of my favs in the space.

pcaversaccio commented 11 months ago

Damn, that's a news and a half @mds1 . Best of luck. I am open to waiting for your implementation to get finalised while I prep with as much of the tutorial as I can on my own.

FWIW, we froze the code 2 days ago :); so you can use our reference implementation if you want.

Here's an outline of what I was planning:

  1. Introduction - What is CREATE3 and why bother with a CREATE3 implementation despite having the opcode CREATE2?
  2. CREATE3 factory - Go over a CREATE3 factory implementation. I like a factory contract instead of a library in a tutorial since the factory is easier to plug and play for the end user. I will go over the code in the same way as the CREATE2 article, step by step.
  3. Testing - Writing a couple of basic tests that work with 3 simple contracts: the factory, a barebones increment counter contract, and a barebones decrement counter contract. We will show that the CREATE3 factory deploys both of them to the same address by showing that the test will fail to deploy the second of the 2 contracts if supplied with the same salt.
  4. Deploying and Verifying - Deploy and verify both of the barebone contracts to two different chains at the same address as a proof of implementation.

What do you think?

One important part to mention is that since we live in a cross-chain world, CREATE3 deployments can be frontrun with another implementation code on another chain by anyone (as long as the factory itself is deployed on the other chain) if not protected by the factory. I.e. the salt value in CREATE3 deployments ensures that the proxy is deployed on the same address, but doesn't ensure that the implementation logic with that logic stays the same across different chains. CreateX offers protection mechanisms against this.

P.S: @pcaversaccio I would love the chance to work with you, even if indirectly so. You're one of my favs in the space.

Very much appreciate the kind words :) - happy to help review the CREATE3 tutorial if that helps.

Genesis3800 commented 11 months ago

FWIW, we froze the code 2 days ago :); so you can use our reference implementation if you want.

Ty ser, will get started with yours, even though I am not totally confident I will be able to digest the complex frontrun protections. Will try my best as before.

Very much appreciate the kind words :) - happy to help review the CREATE3 tutorial if that helps.

Yes an extra pair of eyes always helps, especially from someone like you.

@Evalir This one will take some time at least. I'll try to have a first draft in 10-15 days. I'll try to expedite as much as possible.

Genesis3800 commented 10 months ago

Hey all,

just wanted to update everyone that I am still keen on completing this assigned issue. This one is taking time because I am finding the concepts involved difficult.

I will try my best to have the first draft on CREATEX ready in about a week. BTW, @pcaversaccio congrats on the official release :)

pcaversaccio commented 10 months ago

Hey all,

just wanted to update everyone that I am still keen on completing this assigned issue. This one is taking time because I am finding the concepts involved difficult.

I will try my best to have the first draft on CREATEX ready in about a week. BTW, @pcaversaccio congrats on the official release :)

πŸ˜„ thxs; we're publicly live now https://twitter.com/pcaversaccio/status/1738153235678998855.

Genesis3800 commented 10 months ago

πŸ˜„ thxs; we're publicly live now https://twitter.com/pcaversaccio/status/1738153235678998855.

Congrats ser, you deserve it. I love how you put your insane hard work out for free for the public. I can't compete with you at this, but in good faith, I am doing my best to put out a good article on this topic. Maybe that is also a tiniest bit of help.

pcaversaccio commented 10 months ago

πŸ˜„ thxs; we're publicly live now https://twitter.com/pcaversaccio/status/1738153235678998855.

Congrats ser, you deserve it. I love how you put your insane hard work out for free for the public. I can't compete with you at this, but in good faith, I am doing my best to put out a good article on this topic. Maybe that is also a tiniest bit of help.

Never underestimate the value of good educational material! That's part of the equation on how to attract great talent.

Genesis3800 commented 10 months ago

Hey guys,

I'm terribly sorry to write this, but can I withdraw from this PR? I don't think I can do justice to this one right now with my current job being as demanding as it is. I have not been able to pick up the required concepts in a good manner either.

Apologies again :( I hate going back on my word, but it turns out I am not capable of delivering on this one. CC: @Evalir