Skip to content

Commit

Permalink
Add support for Vyper cbor auxdata in bytecode-utils and in VyperChec…
Browse files Browse the repository at this point in the history
…kedContract (#1783)

* Add support for Vyper cbor auxdata in bytecode-utils and consequently in VyperCheckedContract

* handle vyper incorrect semver versions, support auxdata position also for versions < 0.3.10

* Refactor Solidity and Vyper contract handling to improve auxdata extraction

- Changed `auxdataStyle` in `SolidityCheckedContract` to be a static readonly property.
- Updated bytecode decoding in both `SolidityCheckedContract` and `VyperCheckedContract` to use the static `auxdataStyle`.
- Simplified `generateCborAuxdataPositions` method in `VyperCheckedContract` by introducing a helper function for auxdata position generation.
- Added comments to clarify the use of `AuxdataStyle.SOLIDITY` for bytecode decoding in `ChainMonitor` and session state handlers.
- Ensured that `generateCborAuxdataPositions` is called when necessary in `AbstractDatabaseService` to maintain data integrity.

* add comment to explain `generateCborAuxdataPositions` return conditions

* Refactor bytecode decoding to enhance auxdata handling for Vyper versions. Updated the `decode` function to support various auxdata styles, including specific handling for Vyper versions < 0.3.10 and < 0.3.5. Improved error messages for missing auxdata in bytecode. Updated tests to reflect changes in auxdata style usage.

* Refactor bytecode decoding to replace `compiler` with `vyperVersion` in Vyper-related types and tests.
  • Loading branch information
marcocastignoli authored Dec 16, 2024
1 parent 265d2c1 commit 33ac292
Show file tree
Hide file tree
Showing 18 changed files with 545 additions and 110 deletions.
20 changes: 20 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,26 @@
"console": "integratedTerminal"
// "internalConsoleOptions": "neverOpen"
},
{
"type": "node",
"request": "launch",
"name": "Mocha - bytecode-utils",
"cwd": "${workspaceFolder}/packages/bytecode-utils",
"program": "${workspaceRoot}/node_modules/.bin/mocha",
"args": [
"-r",
"ts-node/register",
"./test/**/*.spec.ts",
"--no-timeout",
// Run a single test when debugging
// "--grep=v0.6.12",
"--exit"
],
"sourceMaps": true,
"smartStep": true,
"console": "integratedTerminal"
// "internalConsoleOptions": "neverOpen"
},
{
"type": "node",
"request": "launch",
Expand Down
5 changes: 4 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions packages/bytecode-utils/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ yarn add @ethereum-sourcify/bytecode-utils
## Usage

```ts
import { decode } from "@ethereum-sourcify/bytecode-utils";
import { decode, AuxdataStyle } from "@ethereum-sourcify/bytecode-utils";

const bytecodeRaw = "0x60806040526004361061003f5760003560e01...7265206c656e677468a2646970667358221220dceca8706b29e917dacf25fceef95acac8d90d765ac926663ce4096195952b6164736f6c634300060b0033"

decode(bytecodeRaw);
decode(bytecodeRaw, AuxdataStyle.SOLIDITY);
```

### Result
Expand Down
3 changes: 2 additions & 1 deletion packages/bytecode-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@
"@ethersproject/bytes": "5.7.0",
"base-x": "4.0.0",
"bs58": "5.0.0",
"cbor-x": "1.6.0"
"cbor-x": "1.6.0",
"semver": "^7.6.3"
},
"devDependencies": {
"@types/chai": "4.3.20",
Expand Down
Loading

0 comments on commit 33ac292

Please sign in to comment.