Smart contracts that can be killed by arbitrary addresses
Smart contracts that can reach a state in which they cannot release ether
Smart contracts that can be made to release ether to arbitrary addresses
functionchangeOwner(address_newOwner)publiconlyBy(owner){owner=_newOwner;}
modifieronlyBy(address_account){require(msg.sender==_account);_;}
enumStages{SafeStageDangerStage,FinalStage}uintpubliccreationTime=now;Stagespublicstage=Stages.SafeStage;functionnextStage()internal{stage=Stages(uint(stage)+1);}modifierstageTimeConfirmation(){if(stage==Stages.SafeStage&&now>=creationTime+10days)nextStage();_;}functiona()publicstageTimeConfirmation// More code goes here{}
3 0x80 mload add 0x80 mstore
functionf(uint_in)publicpurereturns(uintout){out=1;}functionf(uint_in,bytes32_key)publicpurereturns(uintout){out=2;}
uint32a=0x12345678;uint16b=uint16(a);// Variable b is 0x5678 now
defconvert(expr,context):output_type=expr.args[1].sifoutput_typeinconversion_table:returnconversion_table[output_type](expr,context)else:raiseException("Conversion to {} is invalid.".format(output_type))
conversion_table={'int128':to_int128,'uint256':to_unint256,'decimal':to_decimal,'bytes32':to_bytes32,}
@signature(('int128','uint256','bytes32','bytes'),'str_literal')defto_int128(expr,args,kwargs,context):in_node=args[0]typ,len=get_type(in_node)iftypin('int128','uint256','bytes32'):ifin_node.typ.is_literalandnotSizeLimits.MINNUM<=in_node.value<=SizeLimits.MAXNUM:raiseInvalidLiteralException("Number out of range: {}".format(in_node.value),expr)returnLLLnode.from_list(['clamp',['mload',MemoryPositions.MINNUM],in_node,['mload',MemoryPositions.MAXNUM]],typ=BaseType('int128'),pos=getpos(expr))else:returnbyte_array_to_num(in_node,expr,'int128')
What is the current state/condition of the Ethereum state variables?
What effects will this smart contract code have on the condition of the state variables upon execution? That is, what will be affected, and what will not be affected? Are these effects congruent with the smart contract’s intentions?
After the first two considerations have been exhaustively dealt with, it is time to run the code. Before deployment, logically step through the code and consider all of the possible permanent outcomes, consequences, and scenarios of executing the code, including interactions with other contracts.
@privateThe @private decorator makes the function inaccessible from outside the contract.
@publicThe @public decorator makes the function both visible and executable publicly. For example, even the Ethereum wallet will display such functions when viewing the contract.
@constantFunctions with the @constant decorator are not allowed to change state variables. In fact, the compiler will reject the entire program (with an appropriate error) if the function tries to change a state variable.
@payableOnly functions with the @payable decorator are allowed to transfer value.
pragmasolidity^0.4.0;contractordering{functiontopFunction()externalreturns(bool){initiatizedBelowTopFunction=this.lowerFunction();returninitiatizedBelowTopFunction;}boolinitiatizedBelowTopFunction;boollowerFunctionVar;functionlowerFunction()externalreturns(bool){lowerFunctionVar=true;returnlowerFunctionVar;}}
# Declare a variable called theBooltheBool:public(bool)# Declare a function called topFunction@publicdeftopFunction()->bool:# Assign a value to the already declared function called theBoolself.theBool=Truereturnself.theBool# Declare a function called lowerFunction@publicdeflowerFunction():# Call the already declared function called topFunctionassertself.topFunction()
token:address(ERC20)
vyper ~/hello_world.vy
vyper -f json ~/hello_world.v.py
The state variables in a given smart contract are stored in Ethereum’s global state trie; a smart contract can only store, read, and modify data in relation to that particular contract’s address (i.e., smart contracts cannot read or write to other smart contracts).
A smart contract can also write to Ethereum’s chain data through log events. While Vyper initially employed the __log__ syntax for declaring these events, an update has been made that brings its event declaration more in line with Solidity’s original syntax. For example, Vyper’s declaration of an event called MyLog was originally MyLog: 1log2({arg1: indexed(bytes[3])}). The syntax has now become MyLog: event({arg1: indexed(bytes[3])}). It is important to note that the execution of the log event in Vyper was, and still is, as follows: log.MyLog("123").