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

contracts: add gaspad and gasused precompiles #205

Merged
merged 3 commits into from
Oct 31, 2023
Merged

Conversation

CedarMist
Copy link
Member

@CedarMist CedarMist commented Oct 16, 2023

Unfortunately this has different semantics than was initially intended as the initial gas cost for the calldata is added after the transaction is executed.

This means that there will be a 12 gas difference, even after padding, between every NULL and non-NULL byte of the calldata. While this has a very small impact and won't reveal too much sensitive information, it will still reveal some information about the encrypted calldata.

A suggested workaround is to add bytes calldata fuz argument and filling it with one non-zero byte for every zero byte in the other arguments.

@CedarMist CedarMist self-assigned this Oct 16, 2023
@CedarMist CedarMist requested review from matevz and aefhm October 17, 2023 10:48
@CedarMist CedarMist added the contracts Pull requests that update sapphire-contracts label Oct 28, 2023
@matevz
Copy link
Member

matevz commented Oct 30, 2023

I'm considering the threat model of the gas attacks. By using the new gaspad(), an external observer really cannot know how much gas the actual transaction spent. But, by calling gaspad() on an adversarial node, the attacker could see that the call was being made (the attacker knows the location of the gaspad() function inside the sapphire runtime), but he cannot determine how much gas was padded. Am I correct?

@CedarMist
Copy link
Member Author

I'm not sure about the threat model for an adversarial node.

Copy link
Member

@matevz matevz left a comment

Choose a reason for hiding this comment

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

Can you make the naming consistent with the rust code?

contracts/contracts/Sapphire.sol Outdated Show resolved Hide resolved
contracts/contracts/Sapphire.sol Outdated Show resolved Hide resolved
contracts/contracts/Sapphire.sol Outdated Show resolved Hide resolved
@CedarMist CedarMist requested a review from matevz October 30, 2023 18:31
Copy link
Member

@matevz matevz left a comment

Choose a reason for hiding this comment

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

We should also add this to:

@CedarMist CedarMist merged commit bcecd07 into main Oct 31, 2023
@CedarMist CedarMist deleted the CedarMist/gaspad branch October 31, 2023 09:18
github-actions bot added a commit that referenced this pull request Oct 31, 2023
…edarMist/gaspad

contracts: add gaspad and gasused precompiles bcecd07
github-actions bot added a commit that referenced this pull request Oct 31, 2023
…darMist/gaspad

contracts: add gaspad and gasused precompiles bcecd07
contracts/test/gas.ts Show resolved Hide resolved
contracts/test/gas.ts Show resolved Hide resolved
contracts/test/gas.ts Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contracts Pull requests that update sapphire-contracts
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants