how can i restrict my smart contract getting invoked by any account in the network.can i tell the EVM itself to check(validate the account) is allowed to invoke the smart contract even before entering the smart contract for execution
As the contract developer, you can choose to program your contract functions to only be accessible by certain accounts. However, this can only be done as a part of the smart contract execution, not beforehand. It would not be possible today to add such a restriction before any of the contract logic is run.
This is commonly seen in smart contracts with the
OnlyOwner modifier which gets used on functions which should only be called by the "owner" of the contract.
You can see the
OnlyOwner modifer being defined here: OpenZeppelin - Ownable.sol
Ultimately, the code is quite simple, it adds the following requirement:
require(msg.sender == _owner);
This line will fail if the calling address does not match the
_owner value that has been previously defined.
You could add code similar to this in front of any of your functions to make those function calls fail if unauthorized users try to access it. You can imagine turning the
_owner variable into an array or mapping of addresses who are authorized to call the functions, and then you would update your modifier to check whether the
msg.sender is authorized based on that list.