Skip to content

Commit

Permalink
docs: fixed bytecode compression example (#1013)
Browse files Browse the repository at this point in the history
## What ❔
Updated the bytecode compression explanation example, to be valid and
working.

In the connecting contracts PR:
matter-labs/era-contracts#193 I added a test
that checks the bytecode and runs the `publishCompressBytecode` function
with the bytecode from this example.

## Why ❔
The previous example was not valid, it could confuse newcomers, because
the example had different bytecode compared to what was described.

## Checklist
- [x] PR title corresponds to the body of PR (we generate changelog
entries from PRs).
- [x] Tests for the changes have been added / updated.
- [x] Documentation comments have been added / updated.
- [x] Code has been formatted via `zk fmt` and `zk lint`.
- [x] Spellcheck has been run via `zk spellcheck`.
- [x] Linkcheck has been run via `zk linkcheck`.
  • Loading branch information
benceharomi committed Apr 18, 2024
1 parent f6f49b7 commit d28d45d
Showing 1 changed file with 30 additions and 9 deletions.
39 changes: 30 additions & 9 deletions docs/guides/advanced/compression.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,31 +15,52 @@ that the compression is correct before sending to L1.

## Example

Original bytecode
Original bytecode:

```
0x000000000000000A000000000000000D000000000000000A000000000000000C000000000000000B000000000000000A000000000000000D000000000000000A000000000000000D000000000000000A000000000000000B000000000000000B
```

Split to 8-byte chunks:

```
000000000000000A 000000000000000D 000000000000000A 000000000000000C
000000000000000B 000000000000000B 000000000000000D 000000000000000A
000000000000000B 000000000000000A 000000000000000D 000000000000000A
000000000000000D 000000000000000A 000000000000000B 000000000000000B
```

Dictionary would be:

```
0 -> 0xA (count: 3)
1 -> 0xD (count: 2, first seen: 1)
2 -> 0xB (count: 2, first seen: 4)
0 -> 0xA (count: 5)
1 -> 0xD (count: 3, first seen: 1)
2 -> 0xB (count: 3, first seen: 4)
3 -> 0xC (count: 1)
```

Note that '1' maps to '0xD', as it occurs twice, and first occurrence is earlier than first occurrence of 0xB, that also
occurs twice.
Note that `1` maps to `0xD`, as it occurs three times, and first occurrence is earlier than first occurrence of `0xB`,
that also occurs three times.

Compressed bytecode:

```
0008 0000 000000000000000A 000000000000000D 000000000000000B 000000000000000C
0x0004000000000000000A000000000000000D000000000000000B000000000000000C000000010000000300020000000100000001000000020002
```

Split into three parts:

1. `length_of_dict` is stored in the first 2 bytes
2. dictionary entries are stored in the next `8 * length_of_dict` bytes
3. 2-byte indices are stored in the rest of the bytes

```
0004
000000000000000A 000000000000000D 000000000000000B 000000000000000C
0000 0001 0000 0003 0002 0002 0001 0000
0000 0001 0000 0003
0002 0000 0001 0000
0001 0000 0002 0002
```

## Server Side Operator
Expand Down

0 comments on commit d28d45d

Please sign in to comment.