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

Charge for the actual size of the contract in ccp opcode #637

Merged
merged 7 commits into from
Nov 20, 2023

Conversation

xgreenx
Copy link
Collaborator

@xgreenx xgreenx commented Nov 17, 2023

Duplicates #598 but for ccp

@xgreenx xgreenx requested a review from a team November 17, 2023 12:52
@xgreenx xgreenx self-assigned this Nov 17, 2023
Copy link
Contributor

@bvrooman bvrooman left a comment

Choose a reason for hiding this comment

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

One small spelling fix and a general comment. Once you apply the spelling fix, it's good to go.

fuel-vm/src/interpreter/blockchain.rs Outdated Show resolved Hide resolved
Comment on lines 217 to 218
self.gas_charge(gas_cost.base())?;
gas_cost.set_base(0);
Copy link
Contributor

@bvrooman bvrooman Nov 17, 2023

Choose a reason for hiding this comment

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

I know we already use this pattern where we:

  1. Charge the base of the dependent cost
  2. Set the base of the dependent cost to 0
  3. Charge the variable amount of the dependent cost

In general, I do not think this pattern makes a lot of sense. The structure of DependentCost doesn't line up with how it's used: We basically split the one dependent cost into both a fixed cost and dependent cost so we can charge at different times. We break encapsulation by reading and charging base as a fixed cost, then we mutate base to 0, which means CodeCopyCtx (and other places we do this) requires a nonstandard mutated DependentCost input, but there's no type safety or documentation to let developers know. All of this breaks the principle of least surprise.

Maybe we could break up dependent costs into both a DependentCost and fixed cost, where dependent cost is just the variable amount and the fixed cost is the base. This way, we have type safety and no gymnastics to fit our two-stage charging pattern.

Copy link
Collaborator Author

@xgreenx xgreenx Nov 17, 2023

Choose a reason for hiding this comment

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

I tried to minimise the number of changes, but if you want to, its okay to do=) Updated in the 7d9cfdd

@@ -80,20 +80,27 @@ fn test_load_contract() -> IoResult<(), Infallible> {
fn test_code_copy() -> IoResult<(), Infallible> {
Copy link
Member

Choose a reason for hiding this comment

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

Is there any coverage that needs to be added to the blockchain tests? Like we have all these for ldc here. Specifically, it might be good to have a test that covers the case where contract size is larger than $rD and show the cost is proportional to the contract that is being copied rather than the bytes specified.

Copy link
Collaborator Author

@xgreenx xgreenx Nov 17, 2023

Choose a reason for hiding this comment

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

But the test already is doing that=)
image

image

The test is done in the same way as it was done for test_load_contract(test above)

xgreenx and others added 3 commits November 17, 2023 21:02
@xgreenx xgreenx added this pull request to the merge queue Nov 20, 2023
Merged via the queue into master with commit a6899c6 Nov 20, 2023
37 checks passed
@xgreenx xgreenx deleted the bugfix/charge-ccp-actual-size branch November 20, 2023 12:31
@xgreenx xgreenx mentioned this pull request Nov 20, 2023
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.

4 participants