Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions components/Editor/examples.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,12 @@ PUSH1 32
PUSH1 0
RETURN`,
],
Huff: [
`#define macro MAIN() = takes (0) returns (0) {
0x5361772d6d6f6e2026204e6174616c6965 0x00 mstore // Store a value in memory.
0x11 0x0f return // Return 17 bytes starting from memory pointer 15.
}`,
],
}

export default examples
12 changes: 12 additions & 0 deletions components/Editor/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { bufferToHex } from '@ethereumjs/util'
import { encode, decode } from '@kunigi/string-compression'
import cn from 'classnames'
import copy from 'copy-to-clipboard'
import { compile } from 'huffc-js'
import { useRouter } from 'next/router'
import Select, { OnChangeValue } from 'react-select'
import SCEditor from 'react-simple-code-editor'
Expand Down Expand Up @@ -398,6 +399,17 @@ const Editor = ({ readOnly = false }: Props) => {
}
loadInstructions(cleanBytecode)
startExecution(cleanBytecode, _callValue, _callData)
} else if (codeType === CodeType.Huff) {
const huffFileName = 'main.huff'
const compiledHuff = compile({
files: {
[huffFileName]: code,
},
sources: [huffFileName],
})
const { bytecode } = compiledHuff.contracts.get(huffFileName)
loadInstructions(bytecode)
startExecution(bytecode, _callValue, _callData)
} else {
setIsCompiling(true)
log('Starting compilation...')
Expand Down
1 change: 1 addition & 0 deletions components/Editor/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ export enum CodeType {
Solidity = 'Solidity',
Bytecode = 'Bytecode',
Mnemonic = 'Mnemonic',
Huff = 'Huff',
}

export enum ValueUnit {
Expand Down
27 changes: 25 additions & 2 deletions next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,13 @@ module.exports = withPlausibleProxy()({
include: [dir],
use: [
defaultLoaders.babel,
{ loader: 'ts-loader', options: { transpileOnly: true } }
]
{ loader: 'ts-loader', options: { transpileOnly: true } },
],
})
config.experiments = {
asyncWebAssembly: true,
layers: true,
}

config.resolve.fallback = {
fs: false,
Expand All @@ -35,3 +39,22 @@ module.exports = withPlausibleProxy()({
return config
},
})

class WasmChunksFixPlugin {
apply(compiler) {
compiler.hooks.thisCompilation.tap('WasmChunksFixPlugin', (compilation) => {
compilation.hooks.processAssets.tap(
{ name: 'WasmChunksFixPlugin' },
(assets) =>
Object.entries(assets).forEach(([pathname, source]) => {
if (!pathname.match(/\.wasm$/)) return
compilation.deleteAsset(pathname)

const name = pathname.split('/')[1]
const info = compilation.assetsInfo.get(pathname)
compilation.emitAsset(name, source, info)
}),
)
})
}
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"gray-matter": "^4.0.3",
"highlight.js": "^11.3.1",
"highlightjs-solidity": "^2.0.1",
"huffc-js": "^0.3.0",
"kbar": "^0.1.0-beta.16",
"lodash.debounce": "^4.0.8",
"next": "12",
Expand Down
3 changes: 3 additions & 0 deletions util/string.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ hljsDefineSolidity(hljs)
hljs.registerLanguage('mnemonic', hljsDefineMnemonic)
hljs.registerLanguage('bytecode', hljsDefineBytecode)

// Add Huff to Highlight
hljs.registerLanguage('huff', hljsDefineMnemonic)

/**
* Checks whether text is empty.
*/
Expand Down
107 changes: 5 additions & 102 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2174,64 +2174,6 @@
"@webassemblyjs/helper-numbers" "1.11.1"
"@webassemblyjs/helper-wasm-bytecode" "1.11.1"

"@webassemblyjs/floating-point-hex-parser@1.11.1":
version "1.11.1"
resolved "https://registry.npmjs.org/@webassemblyjs/floating-point-hex-parser/-/floating-point-hex-parser-1.11.1.tgz"
integrity sha512-iGRfyc5Bq+NnNuX8b5hwBrRjzf0ocrJPI6GWFodBFzmFnyvrQ83SHKhmilCU/8Jv67i4GJZBMhEzltxzcNagtQ==

"@webassemblyjs/helper-api-error@1.11.1":
version "1.11.1"
resolved "https://registry.npmjs.org/@webassemblyjs/helper-api-error/-/helper-api-error-1.11.1.tgz"
integrity sha512-RlhS8CBCXfRUR/cwo2ho9bkheSXG0+NwooXcc3PAILALf2QLdFyj7KGsKRbVc95hZnhnERon4kW/D3SZpp6Tcg==

"@webassemblyjs/helper-buffer@1.11.1":
version "1.11.1"
resolved "https://registry.npmjs.org/@webassemblyjs/helper-buffer/-/helper-buffer-1.11.1.tgz"
integrity sha512-gwikF65aDNeeXa8JxXa2BAk+REjSyhrNC9ZwdT0f8jc4dQQeDQ7G4m0f2QCLPJiMTTO6wfDmRmj/pW0PsUvIcA==

"@webassemblyjs/helper-numbers@1.11.1":
version "1.11.1"
resolved "https://registry.npmjs.org/@webassemblyjs/helper-numbers/-/helper-numbers-1.11.1.tgz"
integrity sha512-vDkbxiB8zfnPdNK9Rajcey5C0w+QJugEglN0of+kmO8l7lDb77AnlKYQF7aarZuCrv+l0UvqL+68gSDr3k9LPQ==
dependencies:
"@webassemblyjs/floating-point-hex-parser" "1.11.1"
"@webassemblyjs/helper-api-error" "1.11.1"
"@xtuc/long" "4.2.2"

"@webassemblyjs/helper-wasm-bytecode@1.11.1":
version "1.11.1"
resolved "https://registry.npmjs.org/@webassemblyjs/helper-wasm-bytecode/-/helper-wasm-bytecode-1.11.1.tgz"
integrity sha512-PvpoOGiJwXeTrSf/qfudJhwlvDQxFgelbMqtq52WWiXC6Xgg1IREdngmPN3bs4RoO83PnL/nFrxucXj1+BX62Q==

"@webassemblyjs/helper-wasm-section@1.11.1":
version "1.11.1"
resolved "https://registry.npmjs.org/@webassemblyjs/helper-wasm-section/-/helper-wasm-section-1.11.1.tgz"
integrity sha512-10P9No29rYX1j7F3EVPX3JvGPQPae+AomuSTPiF9eBQeChHI6iqjMIwR9JmOJXwpnn/oVGDk7I5IlskuMwU/pg==
dependencies:
"@webassemblyjs/ast" "1.11.1"
"@webassemblyjs/helper-buffer" "1.11.1"
"@webassemblyjs/helper-wasm-bytecode" "1.11.1"
"@webassemblyjs/wasm-gen" "1.11.1"

"@webassemblyjs/ieee754@1.11.1":
version "1.11.1"
resolved "https://registry.npmjs.org/@webassemblyjs/ieee754/-/ieee754-1.11.1.tgz"
integrity sha512-hJ87QIPtAMKbFq6CGTkZYJivEwZDbQUgYd3qKSadTNOhVY7p+gfP6Sr0lLRVTaG1JjFj+r3YchoqRYxNH3M0GQ==
dependencies:
"@xtuc/ieee754" "^1.2.0"

"@webassemblyjs/leb128@1.11.1":
version "1.11.1"
resolved "https://registry.npmjs.org/@webassemblyjs/leb128/-/leb128-1.11.1.tgz"
integrity sha512-BJ2P0hNZ0u+Th1YZXJpzW6miwqQUGcIHT1G/sf72gLVD9DZ5AdYTqPNbHZh6K1M5VmKvFXwGSWZADz+qBWxeRw==
dependencies:
"@xtuc/long" "4.2.2"

"@webassemblyjs/utf8@1.11.1":
version "1.11.1"
resolved "https://registry.npmjs.org/@webassemblyjs/utf8/-/utf8-1.11.1.tgz"
integrity sha512-9kqcxAEdMhiwQkHpkNiorZzqpGrodQQ2IGrHHxCy+Ozng0ofyMA0lTqiLkVs1uzTRejX+/O0EOT7KxqVPuXosQ==

"@webassemblyjs/wasm-edit@1.11.1":
version "1.11.1"
resolved "https://registry.npmjs.org/@webassemblyjs/wasm-edit/-/wasm-edit-1.11.1.tgz"
Expand All @@ -2246,27 +2188,6 @@
"@webassemblyjs/wasm-parser" "1.11.1"
"@webassemblyjs/wast-printer" "1.11.1"

"@webassemblyjs/wasm-gen@1.11.1":
version "1.11.1"
resolved "https://registry.npmjs.org/@webassemblyjs/wasm-gen/-/wasm-gen-1.11.1.tgz"
integrity sha512-F7QqKXwwNlMmsulj6+O7r4mmtAlCWfO/0HdgOxSklZfQcDu0TpLiD1mRt/zF25Bk59FIjEuGAIyn5ei4yMfLhA==
dependencies:
"@webassemblyjs/ast" "1.11.1"
"@webassemblyjs/helper-wasm-bytecode" "1.11.1"
"@webassemblyjs/ieee754" "1.11.1"
"@webassemblyjs/leb128" "1.11.1"
"@webassemblyjs/utf8" "1.11.1"

"@webassemblyjs/wasm-opt@1.11.1":
version "1.11.1"
resolved "https://registry.npmjs.org/@webassemblyjs/wasm-opt/-/wasm-opt-1.11.1.tgz"
integrity sha512-VqnkNqnZlU5EB64pp1l7hdm3hmQw7Vgqa0KF/KCNO9sIpI6Fk6brDEiX+iCOYrvMuBWDws0NkTOxYEb85XQHHw==
dependencies:
"@webassemblyjs/ast" "1.11.1"
"@webassemblyjs/helper-buffer" "1.11.1"
"@webassemblyjs/wasm-gen" "1.11.1"
"@webassemblyjs/wasm-parser" "1.11.1"

"@webassemblyjs/wasm-parser@1.11.1":
version "1.11.1"
resolved "https://registry.npmjs.org/@webassemblyjs/wasm-parser/-/wasm-parser-1.11.1.tgz"
Expand All @@ -2279,24 +2200,6 @@
"@webassemblyjs/leb128" "1.11.1"
"@webassemblyjs/utf8" "1.11.1"

"@webassemblyjs/wast-printer@1.11.1":
version "1.11.1"
resolved "https://registry.npmjs.org/@webassemblyjs/wast-printer/-/wast-printer-1.11.1.tgz"
integrity sha512-IQboUWM4eKzWW+N/jij2sRatKMh99QEelo3Eb2q0qXkvPRISAj8Qxtmw5itwqK+TTkBuUIE45AxYPToqPtL5gg==
dependencies:
"@webassemblyjs/ast" "1.11.1"
"@xtuc/long" "4.2.2"

"@xtuc/ieee754@^1.2.0":
version "1.2.0"
resolved "https://registry.npmjs.org/@xtuc/ieee754/-/ieee754-1.2.0.tgz"
integrity sha512-DX8nKgqcGwsc0eJSqYt5lwP4DH5FlHnmuWWBRy7X0NcaGR0ZtuyeESgMwTYVEtxmsNGY+qit4QYT/MIYTOTPeA==

"@xtuc/long@4.2.2":
version "4.2.2"
resolved "https://registry.npmjs.org/@xtuc/long/-/long-4.2.2.tgz"
integrity sha512-NuHqBY1PB/D8xU6s/thBgOAiAP7HOYDQ32+BFZILJ8ivkUkAHQnWfn6WhL79Owj1qmUnoN/YPhktdIoucipkAQ==

JSONStream@^1.0.3, JSONStream@^1.3.2:
version "1.3.5"
resolved "https://package-cluster.production.groovehq.com/JSONStream/-/JSONStream-1.3.5.tgz"
Expand Down Expand Up @@ -4552,6 +4455,11 @@ html-void-elements@^1.0.0:
resolved "https://package-cluster.production.groovehq.com/html-void-elements/-/html-void-elements-1.0.5.tgz"
integrity sha512-uE/TxKuyNIcx44cIWnjr/rfIATDH7ZaOMmstu0CwhFG1Dunhlp4OC6/NMbhiwoq5BpW0ubi303qnEk/PZj614w==

huffc-js@^0.3.0:
version "0.3.0"
resolved "https://registry.yarnpkg.com/huffc-js/-/huffc-js-0.3.0.tgz#2c7a39dedc39d04bffffe36e96df1c40c8337b36"
integrity sha512-x5eWC3oUNZjszBQbrdcgew5oEKxYujDiTLkeYr/sVtVsSG/Kv323PlieajccDHoNgaNE0VL1RyZkoPu6pLA+jA==

husky@^7.0.2:
version "7.0.2"
resolved "https://package-cluster.production.groovehq.com/husky/-/husky-7.0.2.tgz"
Expand Down Expand Up @@ -5907,11 +5815,6 @@ react-transition-group@^4.3.0:
loose-envify "^1.4.0"
prop-types "^15.6.2"

react-usestateref@^1.0.8:
version "1.0.8"
resolved "https://registry.yarnpkg.com/react-usestateref/-/react-usestateref-1.0.8.tgz#b40519af0d6f3b3822c70eb5db80f7d47f1b1ff5"
integrity sha512-whaE6H0XGarFKwZ3EYbpHBsRRCLZqdochzg/C7e+b6VFMTA3LS3K4ZfpI4NT40iy83jG89rGXrw70P9iDfOdsA==

react-virtual@^2.8.2:
version "2.8.2"
resolved "https://package-cluster.production.groovehq.com/react-virtual/-/react-virtual-2.8.2.tgz"
Expand Down