From 61ce27f4ac8e399fceff5d452f5e420ba9a6d24d Mon Sep 17 00:00:00 2001 From: Denis Date: Mon, 10 Jul 2023 18:34:17 +0300 Subject: [PATCH 1/5] Update readme --- README.md | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index b82e8fc..2f75acb 100644 --- a/README.md +++ b/README.md @@ -29,13 +29,13 @@ It's algorithm for compress data. It's checks all cases with bitmasks from Decom It calculates all the possible applications of different masks for each byte of the code, and then iterates over all the options using dynamic programming and chooses the best option. ## Contract Overview -This contract provides a `DecompressorExtension` abstract contract that extends `Ownable` from the OpenZeppelin library. It decompresses compressed calldata. It contains the following functions: +This contract provides a `DecompressorExtension` abstract contract that decompresses compressed calldata. It contains the following functions: - `getData`: retrieves data from the contract's dictionary and returns it in an array. -- `setData`: sets a single value in the contract's dictionary. -- `setDataArray`: sets multiple values in the contract's dictionary. - `decompress`: decompresses data stored in the contract using a compression algorithm. - `decompressed`: returns the decompressed data as bytes. +- `_setData`: sets a single value in the contract's dictionary. +- `_setDataArray`: sets multiple values in the contract's dictionary. ### Usage To use this contract, you must create a new contract that inherits from `DecompressorExtension`. @@ -44,20 +44,18 @@ To use this contract, you must create a new contract that inherits from `Decompr To use the `getData` function, call it with a beginning and ending index, which will return an array of data values from the dictionary. First 2 positions are reserved with `msg.sender`and `address(this)`, so you can't get it. -#### `setData` -To use the `setData` function, call it with an offset and a value. This function can only be called by the owner of the contract. -First 2 positions are reserved with `msg.sender`and `address(this)`, so you can't set it. - -#### `setDataArray` -To use the `setDataArray` function, call it with an offset and an array of values. This function can only be called by the owner of the contract. -First 2 positions are reserved with `msg.sender`and `address(this)`, so you can't set it. - #### `decompress` To use the `decompress` function, send a transaction to the contract with compressed data as input. This function will delegate call the `decompressed` function, which returns the decompressed data as bytes. #### `decompressed` To use the `decompressed` function, call it directly. This function returns the decompressed data as bytes. +#### `_setData` +The `_setData` is an internal function used within the contract or its inheritors. It sets a value in the dictionary at a specified offset, excluding the first two reserved slots for `msg.sender` and `address(this)`. + +#### `_setDataArray` +The `_setDataArray` is an internal function used within the contract or its inheritors. It's used to set an array of values in the dictionary starting from a specified offset. The first two slots, reserved for `msg.sender` and `address(this)`, are excluded from this operation. + ## JS Compress script To use compress script use `compress` method @@ -67,7 +65,7 @@ const { compress } = require('@1inch/calldata-compressor/js/compressor.js'); ### Description of `compress` function -You have to fill dictionary, which you want to use in compress/decompress processes, using `setDataArray` or `setData` methods before use `compress` method. If you do not do this, then the compression will be without taking into account the dictionary. +You have to fill dictionary, which you want to use in compress/decompress processes, using some functions `_setDataArray` or `_setData` methods before use `compress` method. If you do not do this, then the compression will be without taking into account the dictionary. This is an asynchronous function that takes four parameters: 1. `calldata` - This parameter is expected to contain some data that needs to be compressed. From ef7c61df3ee39344c5ea20c5a90f2f2a431acfcb Mon Sep 17 00:00:00 2001 From: Denis Date: Mon, 10 Jul 2023 18:35:07 +0300 Subject: [PATCH 2/5] Add note about frontrunning via dict setters --- contracts/DecompressorExtension.sol | 1 + 1 file changed, 1 insertion(+) diff --git a/contracts/DecompressorExtension.sol b/contracts/DecompressorExtension.sol index 4f4856b..3a50390 100644 --- a/contracts/DecompressorExtension.sol +++ b/contracts/DecompressorExtension.sol @@ -6,6 +6,7 @@ pragma solidity ^0.8.0; * @title DecompressorExtension * @dev A contract that implements a decompression algorithm to be used in conjunction with compressed data. * You should implement in your contract a function that makes use of the internal methods `_setData`, `_setDataArray` for data addition to the dictionary. + * NOTE: It is important to implement a delay when using the `_setData` and `_setDataArray` methods in your transactions. This delay helps to guard against the possibility of frontrunning, which can occur when the state of the dictionary changes during the execution of a transaction. */ abstract contract DecompressorExtension { /** From 631c04acf056bc3463806205524a4cdde7864548 Mon Sep 17 00:00:00 2001 From: Denis Date: Mon, 10 Jul 2023 18:41:34 +0300 Subject: [PATCH 3/5] Fix typo --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 2f75acb..f69e8e4 100644 --- a/README.md +++ b/README.md @@ -65,7 +65,7 @@ const { compress } = require('@1inch/calldata-compressor/js/compressor.js'); ### Description of `compress` function -You have to fill dictionary, which you want to use in compress/decompress processes, using some functions `_setDataArray` or `_setData` methods before use `compress` method. If you do not do this, then the compression will be without taking into account the dictionary. +You have to fill dictionary, which you want to use in compress/decompress processes, using some functions with `_setDataArray` or `_setData` methods before use `compress` method. If you do not do this, then the compression will be without taking into account the dictionary. This is an asynchronous function that takes four parameters: 1. `calldata` - This parameter is expected to contain some data that needs to be compressed. From 3c6054a8b2783a3358c4ebb61f5e12064120a93a Mon Sep 17 00:00:00 2001 From: Denis Date: Thu, 13 Jul 2023 12:16:31 +0300 Subject: [PATCH 4/5] Add notice about gas consuption --- contracts/DecompressorExtension.sol | 1 + 1 file changed, 1 insertion(+) diff --git a/contracts/DecompressorExtension.sol b/contracts/DecompressorExtension.sol index 3a50390..a913496 100644 --- a/contracts/DecompressorExtension.sol +++ b/contracts/DecompressorExtension.sol @@ -7,6 +7,7 @@ pragma solidity ^0.8.0; * @dev A contract that implements a decompression algorithm to be used in conjunction with compressed data. * You should implement in your contract a function that makes use of the internal methods `_setData`, `_setDataArray` for data addition to the dictionary. * NOTE: It is important to implement a delay when using the `_setData` and `_setDataArray` methods in your transactions. This delay helps to guard against the possibility of frontrunning, which can occur when the state of the dictionary changes during the execution of a transaction. + * @notice This extension could result in a much higher gas consumption than expected and could potentially lead to significant memory expansion costs. Be sure to properly estimate these aspects to avoid unforeseen expenses. */ abstract contract DecompressorExtension { /** From 0be9cb1e985f510118da1933074046dbe045ce6c Mon Sep 17 00:00:00 2001 From: Denis Date: Thu, 13 Jul 2023 12:24:25 +0300 Subject: [PATCH 5/5] Bump version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 82aca55..e01b462 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@1inch/calldata-compressor", - "version": "0.0.3", + "version": "0.0.4", "description": "1inch calldata compressor", "repository": { "type": "git",