Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update cost #111

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open

Update cost #111

wants to merge 8 commits into from

Conversation

syntrust
Copy link
Contributor

@syntrust syntrust commented Sep 13, 2024

Add a dust cost for the update required by #36.

A constant UPDATE_COST is added meaning how much should be charged to update a KV entry or blob. Using constant to be compatible with the currently deployed contract, and may change to immutable later.

The estimated value of 120,000 Gwei is derived from the maximum possible gas cost of a putBlobs batch transaction with a size of 4,872 for the same key, but containing only one blob. In this scenario, the gas used is 29,454,363, which means approximately the gas cost per kv update is 29454363 / 4872 = 6045.

Assuming a gas price of 10 Gwei and a blob fee of 1 wei per gas unit,
(10000000000 * 29454363 + 1 * 131072) / 4872 = 60456 Gwei

Round to 60000 and doubled to be on the safe side.

If the DoSer does not care about the gas cost, an extra charge doubles the cost to prevent the attack. On the other hand, a price less than one-tenth of adding a new entry (storageCost = 1,500,000 Gwei) justifies the updates with good reason.

@syntrust syntrust marked this pull request as ready for review September 13, 2024 04:14
@qzhodl qzhodl requested a review from ping-ke September 13, 2024 08:53
@@ -34,6 +34,9 @@ contract DecentralizedKV is OwnableUpgradeable {
/// https://github.com/ethereum-optimism/optimism/blob/develop/op-service/eth/blob.go#L16
uint256 internal constant MAX_OPTIMISM_BLOB_DATA_SIZE = (4 * 31 + 3) * 1024 - 4;

/// @notice Cost to update the value of an entry (TODO: change to immutable)
uint256 internal constant UPDATE_COST = 150000000000000;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe it would be compatible if we use immutable here and upgrade the implementation of the current contract.

contracts/DecentralizedKV.sol Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants