Skip to content

Commit

Permalink
Fix commands and descriptions
Browse files Browse the repository at this point in the history
  • Loading branch information
Agusx1211 committed Feb 12, 2024
1 parent df35bd3 commit ecb56c1
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 15 deletions.
67 changes: 62 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ Usage:
Available Commands:
completion Generate the autocompletion script for the specified shell
encode_any Compress any calldata: <hex>
encode_call Compress a call to a contract: <data> <to>
encode_calls Compress a sequence of calls: <data> <to> <data> <to> ... <data> <to>
encode_sequence_tx Compress a sequence of transactions
encode-any Compress any calldata: <hex>
encode-call Compress a call to a contract: <data> <to>
encode-calls Compress multiple calls to many contracts: <data> <to> <data> <to> ... <data> <to>
encode-sequence-tx Compress a Sequence Wallet transaction
extras Additional encoding methods, used for testing and debugging.
help Help about any command
Expand Down Expand Up @@ -106,7 +106,7 @@ Storage indexes can be enabled using the following flags:
- `--contract <address>` An instance of the `decompressor.huff` contract to use for storage indexes.
- `--provider <provider>` The provider from which to fetch the pointers.

Notice that a cache on `/tmp/czip-indexes-<chain-id>.json` is automatically created to avoid fetching the same pointers multiple times.
Notice that a cache on `/tmp/czip-cache/czip-indexes-<chain-id>.json` is automatically created to avoid fetching the same pointers multiple times. The cache dir can be changed using the `--cache-dir` flag.

### Example

Expand All @@ -120,6 +120,63 @@ Notice that a cache on `/tmp/czip-indexes-<chain-id>.json` is automatically crea
> 0x0837012700020203fc270003
```

## Compression gains

The compression gains are highly dependent on the ratio of computation cost to calldata cost of a given network. It is most effective on "rollup" style L2s, but it can also achieve some small gains on some other networks.

| Network | Decompressor Address | Savings |
|---------------|--------------------------------------------|----------|
| Arbitrum | 0x8C5CF0a201C1F0C1517a23699BE48070724e7a70 | ~50% |
| Optimism | 0x8C5CF0a201C1F0C1517a23699BE48070724e7a70 | ~50% |
| Base | 0x8C5CF0a201C1F0C1517a23699BE48070724e7a70 | ~50% |
| Arbitrum Nova | 0x8C5CF0a201C1F0C1517a23699BE48070724e7a70 | ~15% |
| Polygon | -- | Negative |
| Ethereum | -- | Negative |
| Polygon zkEVM | -- | Negative |

The following benchmarking transactions are from the Arbitrum network, they show savings of ~50% in gas costs. The savings account for the cost of the decompressor contract, notice that they use an older version of the compressor, but the inner workings are the same.

![Sending ETH cost comparation](https://ipfs.io/ipfs/QmbJ3rZRdUyie8bpF7tbDHK5acqU7ncigsNLqJvW6qZViu?filename=Compressed%20ETH%20transactions%20-%20Sequence%20wallet.svg)

```
Send ETH uncompressed (1st):
0xa0efbb458309f1ccc14035a53e20c36155d722b1c5d991bfa7c43a21174ec468
Send ETH compressed + write storage (1st):
0x9a34d5787b0dd6fba248ebeb407d51526445b496f45f2b4f6ff1d56875f04f7c
Send ETH compressed (1st):
0x6197b0770cdb3efcdb252bf3932ff9964e3467906a7ac1de6361e2d9fe1bb84e
Send ETH uncompressed (2nd):
0x7b519df3f10a0e0ae507d6d18d775f1ed80e65c76df06e5632f402903cd9afb8
Send ETH compressed + write storage (2nd):
0x1680bae9b790bb54d522ebc033da92cb5261b73c27058767c55011957083ea41
Send ETH compressed + write storage (2nd):
0x1ccc93227065df0b9d6acc64504280ad7e55b5823b90111a0b6477c881291de4
```

![Sending ETH cost comparation](https://ipfs.io/ipfs/QmNXyKPgcba7a4bFAMzRsQS3GSgykSD2FkpD9Qpk2FE2oV?filename=Compressed%20ERC20%20transactions%20-%20Sequence%20wallet.svg)

```
Send ERC20 uncompressed:
0x0559ea8161e9cfed3298091d1f7626fe551bd40a38d2ff65d2340a52203e582a
Send ERC20 compressed + write storage:
0xbbf1d0250c37155f2da1d72cc01ff68fb5ccd4b4834a4accf53caf9374e64e3b
Send ERC20 compressed:
0x07e3b4de0b2cd3c8c531e90f32afc7a5dc3691b399ae4ab33d833b3e10741d05
Approve ERC20 uncompressed:
0x03c5f3d5c5a556439215c751a0d84b838266e9ec2481f862a912943e1bc309d6
Aprove ERC20 compressed:
0x7186dcf623d6bf5436691d28c649215900c4c71c2061863b0388786e07299428
```

## Decompressor contract

The `decompressor.huff` serves as the decompressor for all data. It has been carefully designed to be as efficient as possible. It also serves the role of a "repository"; it can store `address` and `bytes32` values that can later be referenced using a pointer.
Expand Down
12 changes: 6 additions & 6 deletions compressor/cmd/czip-compressor/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func useBuffer(method uint, cmd *cobra.Command) (*compressor.Buffer, error) {
}

var encodeAnyCmd = &cobra.Command{
Use: "encode_any",
Use: "encode-any",
Short: "Compress any calldata: <hex>",
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
Expand All @@ -98,8 +98,8 @@ var encodeAnyCmd = &cobra.Command{

func addEncodeCallsCommands(cmd *cobra.Command) {
encodeCallsCmd := &cobra.Command{
Use: "encode_calls",
Short: "Compress a sequence of calls: <data> <to> <data> <to> ... <data> <to>",
Use: "encode-calls",
Short: "Compress multiple calls to many contracts: <data> <to> <data> <to> ... <data> <to>",
}
encodeCallsCmd.AddCommand(&cobra.Command{
Use: "decode",
Expand Down Expand Up @@ -159,7 +159,7 @@ func writeCallsForMethod(cmd *cobra.Command, method uint, args []string) {

func addEncodeCallCommands(cmd *cobra.Command) {
encodeCallCmd := &cobra.Command{
Use: "encode_call",
Use: "encode-call",
Short: "Compress a call to a contract: <data> <to>",
}
encodeCallCmd.AddCommand(&cobra.Command{
Expand Down Expand Up @@ -211,8 +211,8 @@ func writeCallForMethod(cmd *cobra.Command, method uint, args []string) {

func addEncodeSequenceCommands(cmd *cobra.Command) {
encodeSequenceCmd := &cobra.Command{
Use: "encode_sequence_tx",
Short: "Compress a sequence of transactions",
Use: "encode-sequence-tx",
Short: "Compress a Sequence Wallet transaction",
}
encodeSequenceCmd.AddCommand(&cobra.Command{
Use: "decode",
Expand Down
8 changes: 4 additions & 4 deletions test/utils/compressor.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ library Compressor {
function encodeAny(Vm _vm, bytes memory _data) internal pure returns (CommandBuffer memory) {
string[] memory inputs = new string[](3);
inputs[0] = "./compressor/bin/czip-compressor";
inputs[1] = "encode_any";
inputs[1] = "encode-any";
inputs[2] = _vm.toString(_data);
return CommandBuffer(_vm, inputs);
}
Expand All @@ -29,7 +29,7 @@ library Compressor {
function encodeSequenceTx(Vm _vm, string memory _action, address _wallet, bytes memory _data) internal pure returns (CommandBuffer memory) {
string[] memory inputs = new string[](5);
inputs[0] = "./compressor/bin/czip-compressor";
inputs[1] = "encode_sequence_tx";
inputs[1] = "encode-sequence-tx";
inputs[2] = _action;
inputs[3] = _vm.toString(_data);
inputs[4] = _vm.toString(_wallet);
Expand All @@ -39,7 +39,7 @@ library Compressor {
function encodeCall(Vm _vm, string memory _action, address _wallet, bytes memory _data) internal pure returns (CommandBuffer memory) {
string[] memory inputs = new string[](5);
inputs[0] = "./compressor/bin/czip-compressor";
inputs[1] = "encode_call";
inputs[1] = "encode-call";
inputs[2] = _action;
inputs[3] = _vm.toString(_data);
inputs[4] = _vm.toString(_wallet);
Expand All @@ -54,7 +54,7 @@ library Compressor {
function encodeCalls(Vm _vm, string memory _action, Call[] memory _calls) internal pure returns (CommandBuffer memory) {
string[] memory inputs = new string[](3 + _calls.length * 2);
inputs[0] = "./compressor/bin/czip-compressor";
inputs[1] = "encode_calls";
inputs[1] = "encode-calls";
inputs[2] = _action;

for (uint i = 0; i < _calls.length; i++) {
Expand Down

0 comments on commit ecb56c1

Please sign in to comment.