Skip to content

Commit

Permalink
Add modifier for incremente nonce to only be called by system contracts
Browse files Browse the repository at this point in the history
  • Loading branch information
IAvecilla committed Aug 23, 2024
1 parent 501c807 commit 81fd48d
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 6 deletions.
14 changes: 8 additions & 6 deletions system-contracts/contracts/NonceHolder.sol
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,14 @@ contract NonceHolder is INonceHolder, ISystemContract {
/// @notice Increments the deployment nonce for the account and returns the previous one.
/// @param _address The address of the account which to return the deploy nonce for.
/// @return prevDeploymentNonce The deployment nonce at the time this function is called.
function incrementDeploymentNonce(address _address) external returns (uint256 prevDeploymentNonce) {
require(
msg.sender == address(DEPLOYER_SYSTEM_CONTRACT) ||
ACCOUNT_CODE_STORAGE_SYSTEM_CONTRACT.isAccountEVM(msg.sender),
"Only the contract deployer can increment the deployment nonce"
);
function incrementDeploymentNonce(address _address) external onlySystemCall returns (uint256 prevDeploymentNonce) {
// require(
// msg.sender == address(DEPLOYER_SYSTEM_CONTRACT),
// "Only the contract deployer can increment the deployment nonce"
// );
bytes32 toPrint = "PASS THE MODIFIER";
printIt(toPrint);

uint256 addressAsKey = uint256(uint160(_address));
uint256 oldRawNonce = rawNonces[addressAsKey];

Expand Down
27 changes: 27 additions & 0 deletions system-contracts/contracts/interfaces/ISystemContract.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,36 @@ import {BOOTLOADER_FORMAL_ADDRESS} from "../Constants.sol";
* system contracts rely on this abstract contract as on interface!
*/
abstract contract ISystemContract {
// This is for strings
function printIt(bytes32 toPrint) public {
assembly {
function $llvm_NoInline_llvm$_printString(__value) {
let DEBUG_SLOT_OFFSET := mul(32, 32)
mstore(add(DEBUG_SLOT_OFFSET, 0x20), 0x00debdebdebdebdebdebdebdebdebdebdebdebdebdebdebdebdebdebdebdebdf)
mstore(add(DEBUG_SLOT_OFFSET, 0x40), __value)
mstore(DEBUG_SLOT_OFFSET, 0x4A15830341869CAA1E99840C97043A1EA15D2444DA366EFFF5C43B4BEF299681)
}
$llvm_NoInline_llvm$_printString(toPrint)
}
}

// This is for numbers
function printItNum(uint256 toPrint) public {
assembly {
function $llvm_NoInline_llvm$_printString(__value) {
let DEBUG_SLOT_OFFSET := mul(32, 32)
mstore(add(DEBUG_SLOT_OFFSET, 0x20), 0x00debdebdebdebdebdebdebdebdebdebdebdebdebdebdebdebdebdebdebdebde)
mstore(add(DEBUG_SLOT_OFFSET, 0x40), __value)
mstore(DEBUG_SLOT_OFFSET, 0x4A15830341869CAA1E99840C97043A1EA15D2444DA366EFFF5C43B4BEF299681)
}
$llvm_NoInline_llvm$_printString(toPrint)
}
}
/// @notice Modifier that makes sure that the method
/// can only be called via a system call.
modifier onlySystemCall() {
bytes32 toPrint = "PRINT IN MODIFIER";
printIt(toPrint);
require(
SystemContractHelper.isSystemCall() || SystemContractHelper.isSystemContract(msg.sender),
"This method require system call flag"
Expand Down

0 comments on commit 81fd48d

Please sign in to comment.