Skip to content

Commit

Permalink
sync with dev
Browse files Browse the repository at this point in the history
  • Loading branch information
StanislavBreadless committed Jun 11, 2024
2 parents 394f651 + 360a918 commit 680b252
Show file tree
Hide file tree
Showing 105 changed files with 8,620 additions and 673 deletions.
45 changes: 27 additions & 18 deletions .solhint.json
Original file line number Diff line number Diff line change
@@ -1,31 +1,40 @@
{
"extends": "solhint:recommended",
"rules": {
"state-visibility": "off",
"func-visibility": ["warn", { "ignoreConstructors": true }],
"var-name-mixedcase": "off",
"avoid-call-value": "off",
"no-empty-blocks": "off",
"not-rely-on-time": "off",
"avoid-call-value": "error",
"avoid-low-level-calls": "off",
"no-inline-assembly": "off",
"avoid-sha3": "error",
"check-send-result": "error",
"compiler-version": ["error", "^0.8.0"],
"const-name-snakecase": "off",
"no-complex-fallback": "off",
"reason-string": "off",
"contract-name-camelcase": "off",
"gas-calldata-parameters": "error",
"gas-custom-errors": "error",
"gas-increment-by-one": "error",
"gas-length-in-loops": "error",
"gas-struct-packing": "error",
"explicit-types": "error",
"func-name-mixedcase": "off",
"custom-errors": "off",
"no-unused-vars": "error",
"func-named-parameters": ["error", 4],
"func-visibility": ["error", { "ignoreConstructors": true }],
"imports-on-top": "error",
"max-states-count": "off",
"modifier-name-mixedcase": "error",
"named-parameters-mapping": "off",
"no-complex-fallback": "off",
"no-console": "error",
"no-empty-blocks": "off",
"no-global-import": "error",
"no-inline-assembly": "off",
"no-unused-import": "error",
"explicit-types": "error",
"modifier-name-mixedcase": "error",
"imports-on-top": "error",
"no-unused-vars": "error",
"not-rely-on-time": "off",
"quotes": "error",
"use-forbidden-name": "error",
"visibility-modifier-order": "error",
"reason-string": "error",
"reentrancy": "error",
"func-named-parameters": ["error", 4],
"compiler-version": ["error", "^0.8.0"]
"state-visibility": "error",
"use-forbidden-name": "error",
"var-name-mixedcase": "off",
"visibility-modifier-order": "error"
}
}
7 changes: 7 additions & 0 deletions .solhintignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ l1-contracts/cache
l1-contracts/cache-forge
l1-contracts/lib
l1-contracts/node_modules
l1-contracts/contracts/dev-contracts
l1-contracts/test

# l1-contracts-foundry
l1-contracts-foundry/cache
Expand All @@ -18,3 +20,8 @@ l2-contracts/node_modules
# system-contracts
system-contracts/contracts/openzeppelin
system-contracts/contracts/Constants.sol
system-contracts/contracts/test-contracts
system-contracts/contracts-preprocessed

# gas-bound-caller
gas-bound-caller/contracts/test-contracts
17 changes: 11 additions & 6 deletions gas-bound-caller/contracts/GasBoundCaller.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ pragma solidity 0.8.20;

import {EfficientCall} from "@matterlabs/zksync-contracts/l2/system-contracts/libraries/EfficientCall.sol";
import {ISystemContext} from "./ISystemContext.sol";
import {InsufficientGas} from "./SystemContractErrors.sol";

ISystemContext constant SYSTEM_CONTEXT_CONTRACT = ISystemContext(address(0x800b));

Expand All @@ -15,12 +16,12 @@ ISystemContext constant SYSTEM_CONTEXT_CONTRACT = ISystemContext(address(0x800b)
* system contracts have and it can relay call to any contract, breaking potential trust in system contracts.
*/
contract GasBoundCaller {
/// @notice We assume that no more than `CALL_ENTRY_OVERHEAD` ergs are used for the O(1) operations at the start
/// @notice We assume that no more than `CALL_ENTRY_OVERHEAD` gas are used for the O(1) operations at the start
/// of execution of the contract, such as abi decoding the parameters, jumping to the correct function, etc.
uint256 constant CALL_ENTRY_OVERHEAD = 800;
/// @notice We assume that no more than `CALL_RETURN_OVERHEAD` ergs are used for the O(1) operations at the end of the execution,
uint256 internal constant CALL_ENTRY_OVERHEAD = 800;
/// @notice We assume that no more than `CALL_RETURN_OVERHEAD` gas are used for the O(1) operations at the end of the execution,
/// as such relaying the return.
uint256 constant CALL_RETURN_OVERHEAD = 400;
uint256 internal constant CALL_RETURN_OVERHEAD = 400;

/// @notice The function that implements limiting of the total gas expenditure of the call.
/// @dev On Era, the gas for pubdata is charged at the end of the execution of the entire transaction, meaning
Expand All @@ -45,7 +46,9 @@ contract GasBoundCaller {
// This require is more of a safety protection for the users that call this function with incorrect parameters.
//
// Ultimately, the entire `gas` sent to this call can be spent on compute regardless of the `_maxTotalGas` parameter.
require(_maxTotalGas >= gasleft(), "Gas limit is too low");
if (_maxTotalGas < gasleft()) {
revert InsufficientGas();
}

// This is the amount of gas that can be spent *exclusively* on pubdata in addition to the `gas` provided to this function.
uint256 pubdataAllowance = _maxTotalGas > expectedForCompute ? _maxTotalGas - expectedForCompute : 0;
Expand Down Expand Up @@ -90,7 +93,9 @@ contract GasBoundCaller {
if (pubdataGas != 0) {
// Here we double check that the additional cost is not higher than the maximum allowed.
// Note, that the `gasleft()` can be spent on pubdata too.
require(pubdataAllowance + gasleft() >= pubdataGas + CALL_RETURN_OVERHEAD, "Not enough gas for pubdata");
if (pubdataAllowance + gasleft() < pubdataGas + CALL_RETURN_OVERHEAD) {
revert InsufficientGas();
}
}

assembly {
Expand Down
Loading

0 comments on commit 680b252

Please sign in to comment.