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

[SECHD-20276] Extend Functions contracts to support ZKSync #15594

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from

Conversation

KodeyThomas
Copy link
Contributor

This PR extends the existing Functions contracts to support ZKSync.

The current contracts had to be modified in order to support ZKSync due to the ChainSpecificUtil library containing an opcode ZKSync did not support.

In addition to this, I've implemented the L1 fee share logic within the billing logic.

Finally, the GasBoundCaller has been used (in a similar vein to the automation changes) to prevent users from publishing too much pubdata

Copy link
Contributor

github-actions bot commented Dec 10, 2024

Static analysis results are available

Hey @KodeyThomas, you can view Slither reports in the job summary here or download them as artifact here.
Please check them before merging and make sure you have addressed all issues.

@KodeyThomas KodeyThomas changed the title Extend Functions contracts to support ZKSync [INTAUTO-272] Extend Functions contracts to support ZKSync Dec 10, 2024
@KodeyThomas KodeyThomas changed the title [INTAUTO-272] Extend Functions contracts to support ZKSync [SECHD-20276] Extend Functions contracts to support ZKSync Dec 11, 2024
Copy link
Contributor

github-actions bot commented Dec 11, 2024

AER Report: CI Core

aer_workflow , commit , Scheduled Run Frequency , Detect Changes , Clean Go Tidy & Generate , Flakeguard Root Project / Get Tests To Run , lint , Core Tests (go_core_tests) , Core Tests (go_core_tests_integration) , Core Tests (go_core_ccip_deployment_tests) , Flakeguard Deployment Project , Core Tests (go_core_race_tests) , Core Tests (go_core_fuzz) , Flakeguard Root Project / Run Tests , Flakeguard Root Project / Report , Flakey Test Detection , SonarQube Scan

1. Go toolchain not available:[Aggregate Flakeguard Results]

Source of Error:
Aggregate Flakeguard Results	2024-12-11T14:00:54.6750435Z go: download go1.23 for linux/arm64: toolchain not available
Aggregate Flakeguard Results	2024-12-11T14:00:54.6776040Z ##[error]Process completed with exit code 1.

Why: The error occurred because the Go toolchain for version 1.23 on the linux/arm64 architecture is not available. This could be due to an incorrect version specification or a missing toolchain for the specified architecture.

Suggested fix: Verify the availability of the Go toolchain for the specified version and architecture. If unavailable, either use a different version or architecture, or ensure the correct toolchain is installed and accessible.

@KodeyThomas KodeyThomas marked this pull request as ready for review December 11, 2024 13:58
@KodeyThomas KodeyThomas requested review from a team as code owners December 11, 2024 13:58

uint256 pubdataGasSpent;
if (success) {
(, pubdataGasSpent) = abi.decode(returnData, (bytes, uint256));
Copy link
Contributor

Choose a reason for hiding this comment

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

i understand that we want to limit the return data size to MAX_CALLBACK_RETURN_BYTES. This limit is pretty small? i am not sure if it's a case for revert or we can continue the execution.

if the delegatecall is successful but the return data size is too big, will that make pubdataGasSpent unpredictable?

/// @dev The exisiting library used within other functions contracts contains opcodes not supported by ZKSync
library ZKSyncChainSpecificUtil {
function _getCurrentTxL1GasFees() internal view returns (uint256 l1FeeWei) {
ISystemContext systemContext = ISystemContext(SYSTEM_CONTEXT);
Copy link
Contributor

Choose a reason for hiding this comment

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

can you make this systemContext a constant or immutable on this lib?

/// @NOTE: Basis Points are 1/100th of 1%, divide by 10_000 to bring back to original units

uint256 executionGas = s_config.gasOverheadBeforeCallback + s_config.gasOverheadAfterCallback + callbackGasLimit;
uint256 l1FeeWei = ZKSyncChainSpecificUtil._getCurrentTxL1GasFees();
Copy link
Contributor

Choose a reason for hiding this comment

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

i see 2 use cases of _getCurrentTxL1GasFees to get L1 fee. i am not sure if this will give the correct value.
bc we will not know the exact gas cost for updating storage until the entire transaction is executed.
i have this document for auditors and this section explains certain concepts.

traditionally, automation estimates the gas cost by (the upkeep gas limit + L1 gas cost). however, we cannot reliably estimate the L1 gas cost due to the reason above. we have to forward all the gas to gas bound caller to bound the gas usage. this means the max gas usage will simply be the gas limit. so you can see the l1 cost here is 0.
if functions were to follow the similar path and use gas bound caller with callback gas limit, we need to basically provide the gas cost estimation based on the gas limit for the function callback and use 0 for l1 gas cost.

ISystemContext systemContext = ISystemContext(SYSTEM_CONTEXT);

// blob_gas_price_on_l1 * gas_per_byte ~= gas_price_on_l2 * l2_gas_PerPubdataByte
return systemContext.gasPrice() * systemContext.gasPerPubdataByte();
Copy link
Contributor

@FelixFan1992 FelixFan1992 Dec 12, 2024

Choose a reason for hiding this comment

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

i feel this is not doing what the func sig indicates?

what we have here is L2 gas price * L2 gas per L1 pubdata / byte so it still needs the number of bytes current tx will be updating, in order to correctly represent L1 gas cost in L2 world. however, this brings us back to the problem where it's impossible to know how many L1 bytes will be updated beforehand.

in case you need a reference for these functions, this is the precompiles code

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