Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: automatically generate Vm.sol from cheatcodes.json #487

Merged
merged 13 commits into from
Dec 22, 2023

Conversation

DaniPopes
Copy link
Member

@DaniPopes DaniPopes commented Dec 20, 2023

More automation good. See foundry-rs/foundry#5998.

Draft until next nightly for better formatting.

Changes

If any of these changes are not wanted I can patch them out individually.

Other

  • Only doc and group header (// == GROUP ==) comments are preserved

ABI

Using Solc v0.8.23:

(not up to date, just showing that there are no unwanted changes)

Vm

solc src/Vm.sol --combined-json abi | jq '.contracts["src/Vm.sol:Vm"].abi' > Vm.abi.json
diff --git a/Vm.abi.json b/Vm.abi.json
index 63c2c88..ba8ca65 100644
--- a/Vm.abi.json
+++ b/Vm.abi.json
@@ -268,6 +268,19 @@
     "stateMutability": "pure",
     "type": "function"
   },
+  {
+    "inputs": [
+      {
+        "internalType": "address",
+        "name": "target",
+        "type": "address"
+      }
+    ],
+    "name": "cool",
+    "outputs": [],
+    "stateMutability": "nonpayable",
+    "type": "function"
+  },
   {
     "inputs": [
       {
@@ -616,6 +629,69 @@
     "stateMutability": "nonpayable",
     "type": "function"
   },
+  {
+    "inputs": [
+      {
+        "internalType": "string",
+        "name": "mnemonic",
+        "type": "string"
+      },
+      {
+        "internalType": "string",
+        "name": "derivationPath",
+        "type": "string"
+      },
+      {
+        "internalType": "uint32",
+        "name": "index",
+        "type": "uint32"
+      },
+      {
+        "internalType": "string",
+        "name": "language",
+        "type": "string"
+      }
+    ],
+    "name": "deriveKey",
+    "outputs": [
+      {
+        "internalType": "uint256",
+        "name": "privateKey",
+        "type": "uint256"
+      }
+    ],
+    "stateMutability": "pure",
+    "type": "function"
+  },
+  {
+    "inputs": [
+      {
+        "internalType": "string",
+        "name": "mnemonic",
+        "type": "string"
+      },
+      {
+        "internalType": "uint32",
+        "name": "index",
+        "type": "uint32"
+      },
+      {
+        "internalType": "string",
+        "name": "language",
+        "type": "string"
+      }
+    ],
+    "name": "deriveKey",
+    "outputs": [
+      {
+        "internalType": "uint256",
+        "name": "privateKey",
+        "type": "uint256"
+      }
+    ],
+    "stateMutability": "pure",
+    "type": "function"
+  },
   {
     "inputs": [
       {

VmSafe

solc src/Vm.sol --combined-json abi | jq '.contracts["src/Vm.sol:VmSafe"].abi' > VmSafe.abi.json
diff --git a/VmSafe.abi.json b/VmSafe.abi.json
index 4b7f0f5..3764458 100644
--- a/VmSafe.abi.json
+++ b/VmSafe.abi.json
@@ -379,6 +379,69 @@
     "stateMutability": "nonpayable",
     "type": "function"
   },
+  {
+    "inputs": [
+      {
+        "internalType": "string",
+        "name": "mnemonic",
+        "type": "string"
+      },
+      {
+        "internalType": "string",
+        "name": "derivationPath",
+        "type": "string"
+      },
+      {
+        "internalType": "uint32",
+        "name": "index",
+        "type": "uint32"
+      },
+      {
+        "internalType": "string",
+        "name": "language",
+        "type": "string"
+      }
+    ],
+    "name": "deriveKey",
+    "outputs": [
+      {
+        "internalType": "uint256",
+        "name": "privateKey",
+        "type": "uint256"
+      }
+    ],
+    "stateMutability": "pure",
+    "type": "function"
+  },
+  {
+    "inputs": [
+      {
+        "internalType": "string",
+        "name": "mnemonic",
+        "type": "string"
+      },
+      {
+        "internalType": "uint32",
+        "name": "index",
+        "type": "uint32"
+      },
+      {
+        "internalType": "string",
+        "name": "language",
+        "type": "string"
+      }
+    ],
+    "name": "deriveKey",
+    "outputs": [
+      {
+        "internalType": "uint256",
+        "name": "privateKey",
+        "type": "uint256"
+      }
+    ],
+    "stateMutability": "pure",
+    "type": "function"
+  },
   {
     "inputs": [
       {

@DaniPopes DaniPopes marked this pull request as draft December 20, 2023 22:10
@mds1
Copy link
Collaborator

mds1 commented Dec 20, 2023

Nice, this is great! I haven't reviewed the code yet but a few comments based on the description:

  1. The interface ID changed since new cheats were added, but it's possible it also changed due to a mismatch between what forge-std had as Safe vs. what foundry had as Safe. Any thoughts on how we can verify if such a mismatch existed?
  2. I intentionally did not add vm.cool because after it was merged I noticed upstream implementation was incorrect, and we haven't yet merged a fix. We should either fix it or remove that cheat, instead of adding it here.
  3. The ordering of the AccountAccessKind is a breaking change for users (e.g. assertEq(uint(accessKind), x) now fails). So it may be preferable to change the order upstream instead to preserve the interface
  4. I've founding the grouping/comments in Vm.sol nicely self-documenting to avoid having to reference the book during development to find all cheats of a given group, etc. If we preserve this by adding comments for group names / other metadata that would be ideal IMO.

@DaniPopes DaniPopes marked this pull request as ready for review December 21, 2023 08:58
@mds1
Copy link
Collaborator

mds1 commented Dec 22, 2023

  1. I think those ABI diffs are outdated since the Vm interface ID remained unchanged, so I'm guessing all the ABI methods in the PR description are actually VmSafe changes (and vm.cool was removed)

Regarding the rest, thanks! Will review this today

@mds1 mds1 merged commit 87a2a0a into foundry-rs:master Dec 22, 2023
3 checks passed
@DaniPopes DaniPopes deleted the dani/auto-vm branch December 22, 2023 23:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants