Update Solidity/Easy.sol
parent
3643b67ba0
commit
34d6bb39f7
|
@ -2,51 +2,49 @@
|
||||||
|
|
||||||
pragma solidity >=0.8.2 <0.9.0;
|
pragma solidity >=0.8.2 <0.9.0;
|
||||||
|
|
||||||
/**
|
|
||||||
* @title Storage
|
contract SimpleStorage {
|
||||||
* @dev Store & retrieve value in a variable
|
uint storedData;
|
||||||
* @custom:dev-run-script ./scripts/deploy_with_ethers.ts
|
|
||||||
*/
|
function set(uint x) public {
|
||||||
contract Storage {
|
storedData = x;
|
||||||
|
}
|
||||||
|
|
||||||
|
function get() public view returns (uint) {
|
||||||
|
return storedData;
|
||||||
|
}
|
||||||
|
|
||||||
|
function get_private() public view returns (uint) {
|
||||||
|
return not_get();
|
||||||
|
}
|
||||||
|
|
||||||
|
function not_get() private view returns (uint) {
|
||||||
|
return storedData;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
contract StorageExtended {
|
||||||
|
|
||||||
address private owner;
|
address private owner;
|
||||||
|
|
||||||
// event for EVM logging
|
|
||||||
event OwnerSet(address indexed oldOwner, address indexed newOwner);
|
event OwnerSet(address indexed oldOwner, address indexed newOwner);
|
||||||
|
|
||||||
// modifier to check if caller is owner
|
|
||||||
modifier isOwner() {
|
modifier isOwner() {
|
||||||
// If the first argument of 'require' evaluates to 'false', execution terminates and all
|
|
||||||
// changes to the state and to Ether balances are reverted.
|
|
||||||
// This used to consume all gas in old EVM versions, but not anymore.
|
|
||||||
// It is often a good idea to use 'require' to check if functions are called correctly.
|
|
||||||
// As a second argument, you can also provide an explanation about what went wrong.
|
|
||||||
require(msg.sender == owner, "Caller is not owner");
|
require(msg.sender == owner, "Caller is not owner");
|
||||||
_;
|
_;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
// SPoF
|
||||||
* @dev Set contract deployer as owner
|
|
||||||
*/
|
|
||||||
constructor() {
|
constructor() {
|
||||||
console.log("Owner contract deployed by:", msg.sender);
|
owner = msg.sender;
|
||||||
owner = msg.sender; // 'msg.sender' is sender of current call, contract deployer for a constructor
|
|
||||||
emit OwnerSet(address(0), owner);
|
emit OwnerSet(address(0), owner);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @dev Change owner
|
|
||||||
* @param newOwner address of new owner
|
|
||||||
*/
|
|
||||||
function changeOwner(address newOwner) public isOwner {
|
function changeOwner(address newOwner) public isOwner {
|
||||||
emit OwnerSet(owner, newOwner);
|
emit OwnerSet(owner, newOwner);
|
||||||
owner = newOwner;
|
owner = newOwner;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @dev Return owner address
|
|
||||||
* @return address of owner
|
|
||||||
*/
|
|
||||||
function getOwner() external view returns (address) {
|
function getOwner() external view returns (address) {
|
||||||
return owner;
|
return owner;
|
||||||
}
|
}
|
||||||
|
@ -54,18 +52,10 @@ contract Storage {
|
||||||
|
|
||||||
uint256 number;
|
uint256 number;
|
||||||
|
|
||||||
/**
|
|
||||||
* @dev Store value in variable
|
|
||||||
* @param num value to store
|
|
||||||
*/
|
|
||||||
function store(uint256 num) public {
|
function store(uint256 num) public {
|
||||||
number = num;
|
number = num;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @dev Return value
|
|
||||||
* @return value of 'number'
|
|
||||||
*/
|
|
||||||
function retrieve() public view returns (uint256){
|
function retrieve() public view returns (uint256){
|
||||||
return number;
|
return number;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue