Skip to content
This repository has been archived by the owner on Sep 9, 2024. It is now read-only.

Commit

Permalink
Merge pull request #10 from huff-language/fix-regex
Browse files Browse the repository at this point in the history
Format readme
  • Loading branch information
Maddiaa0 authored Jul 26, 2022
2 parents 14c2087 + 92d9f1b commit 91deefc
Show file tree
Hide file tree
Showing 9 changed files with 70 additions and 21 deletions.
40 changes: 35 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,47 @@
# VSCode Huff

**NOTE: Requires path installations of [huffc](https://github.com/huff-language/huff-rs) and [hevm](https://github.com/dapphub/dapptools/tree/master/src/hevm) from [dapptools](https://github.com/dapphub/dapptools) before use.**
**NOTE: Debugger requires path installations of [huffc](https://github.com/huff-language/huff-rs) and [hevm](https://github.com/dapphub/dapptools/tree/master/src/hevm) from [dapptools](https://github.com/dapphub/dapptools) before use.**

Features at a glances:
- Advanced language support
- Syntax Highlighting
- Hover cards detailing gas usage
- Code Generation

#### Hevm Powered Debugging
Step through execution of your contracts from external calls, or even individual macros. Manipulate the stack inputs when your macro starts and even override storage slots. Star power your productivity.
## Hevm Powered Debugging
Step through execution of your contracts from external calls, or even individual macros. Manipulate the stack inputs when your macro starts and even override storage slots. Star power your productivity.
This is particularly useful for debugging your macros individually. For more e2e debugging, the foundry debugger is an excellent tool.

**How it works:**
Open up any .huff file and press `Load Interface` to prepare external functions, enter in your calldata parameters and hit debug to get started.

![function debugging window](./resources/Function_selector.png)

#### Code Generation
The example above is for an erc721 mint function, entering from the function debugger will allow you to step through execution from the MAIN entrypoint. To select another function, click the drop down and select another function! The drop down will be populated with functions that are defined at the top of the file that you are currently debugging.

### Macro Debugging
Macro debugging is the tool's most useful feature. Clicking `Load Macros` will load the macros of the currently open file.
If the macro has no `takes` arguments then the window will look like this:


![function debugging window](./resources/macro_window.png)


You can choose to add arbitrary hex `calldata` to the debugger instance by selecting the `With Calldata` checkbox.

#### Defining `takes` parameters:
![function debugging window](./resources/macro_with_takes_params.png)


If the selected macro has `takes(n)` then n windows will appear to allow setting of the stack before execution.

#### Overriding storage:
![function debugging window](./resources/storage_overrides.png)


`Storage Overrides` allows you to test your macro with arbitrary overrides for specified storage slots! To use, select the `Storage Overrides` checkbox, then add as many slots as you require. Upon execution, the slots will be set to the values that you have defined. You can quickly toggle this feature off by unselecting the `Storage Overrides` checkbox.

## Code Generation
**Switch table generation**
Generate the MAIN macro switch table with jumps from just the interface definition. No more visiting keccak online or using `cast sig xxx` to copy function selectors into your code. Just write the interface and let us handle the rest.

Expand All @@ -27,5 +54,8 @@ Similarly to switch table generation above. Forget about calculating the keccak
Usage:
`commandPallete -> Huff: Generate interface signature from interface`

#### Hover Cards
## Hover Cards
Hovering the cursor over an opcode will explain what operation it performs, the minimum amount of gas it uses, as well as a link to evm.codes to read more about it.

## Currently not supported
[] Constructor Arguments.
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
{
"name": "huff-language",
"version": "0.0.18",
"displayName": "huff",
"version": "0.0.22",
"displayName": "Huff",
"preview": true,
"icon": "resources/huff.png",
"description": "VSCode syntax highlighting for huff programming language.",
"keywords": [
"ethereum",
Expand Down Expand Up @@ -43,7 +45,7 @@
"esbuild": "npm run esbuild-base -- --sourcemap",
"esbuild-watch": "npm run esbuild-base -- --sourcemap --watch"
},
"main": "./src/extension.js",
"main": "./out/main.js",
"extensionKind": [
"ui",
"workspace"
Expand Down
Binary file added resources/Function_selector.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/huff.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/macro_window.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/macro_with_takes_params.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/storage_overrides.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
28 changes: 18 additions & 10 deletions src/features/debugger/debuggerUtils.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const vscode = require("vscode");
const commandExists = require("command-exists");
const fs = require("fs");
const {execSync} = require("child_process");
const {execSync, exec} = require("child_process");


/**Deploy Contract
Expand All @@ -24,19 +24,27 @@ function deployContract(
checkStateRepoExistence(config.statePath, cwd)
}

const command = `hevm exec
--code ${bytecode} \
--address ${config.hevmContractAddress} \
--create \
--caller ${config.hevmCaller} \
--gas 0xffffffff \
${(config.stateChecked || config.storageChecked) ? "--state " + cwd + "/" + config.statePath : ""}
`
const command = `hevm exec --code ${bytecode} --address ${config.hevmContractAddress} --create --caller ${config.hevmCaller} --gas 0xffffffff ${(config.stateChecked || config.storageChecked) ? "--state " + cwd + "/" + config.statePath : ""}`
console.log(command)

// cache command
writeHevmCommand(command, config.tempHevmCommandFilename, cwd);

// execute command
return execSync("`cat " + cwd + "/" + config.tempHevmCommandFilename + "`");
// const result = execSync("`cat " + cwd + "/" + config.tempHevmCommandFilename + "`", {cwd: cwd});
try{
const result = execSync(command)
console.log(result)
return result
}catch (e) {
console.log("deployment failure")
console.log(e.message)
console.log("e.stdout", e.stdout.toString());
console.log("e.stderr", e.stderr.toString());
console.log("e.pid", e.pid);
console.log("e.signal", e.signal);
console.log("e.status", e.status);
}
}


Expand Down
15 changes: 12 additions & 3 deletions src/features/debugger/function/debugger.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const fs = require("fs");
const createKeccakHash = require('keccak');
const path = require("path");

// TODO: use a slimmer abicoder
const { AbiCoder } = require("@ethersproject/abi");
Expand Down Expand Up @@ -58,14 +59,22 @@ async function startDebugger(cwd, currentFile, imports, functionSelector, argsAr
* @returns
*/
function flattenFile(cwd, currentFile, imports){
// Get relative path of files
const dirPath = currentFile.split("/").slice(0,-1).join("/")
const paths = imports.map(importPath => `${cwd}/${dirPath}${importPath.replace(/#include\s?"./, "").replace('"', "")}`);

// Get absolute paths
const paths = imports.map(importPath => path.join(`${cwd}/${dirPath}`,importPath.replace(/#include\s?"/, "").replace('"', "")));
paths.push(cwd+ "/" + currentFile);
const files = paths.map(path => fs.readFileSync(path)

// Read file contents
const files = paths.map(path => {
console.log(path)
return fs.readFileSync(path)
.toString()
}
);

// remove include
// Flatten and remove imports
return `${files.join("\n")}`.replace(/#include\s".*"/gsm, "");
}

Expand Down

0 comments on commit 91deefc

Please sign in to comment.