Closed Sword-Smith closed 3 years ago
A similar check should disallow activate
from being called more than once.
I have added the following functions to EvmCompiler.hs
.
throwIfNotActivated :: [EvmOpcode]
throwIfNotActivated = [push $ storageAddress CreationTimestamp,
SLOAD,
ISZERO,
JUMPITO "global_throw"]
throwIfActivated :: [EvmOpcode]
throwIfActivated = [push $ storageAddress CreationTimestamp,
SLOAD,
JUMPITO "global_throw"]
One example of a usecase is pay
:
pay :: Compiler [EvmOpcode]
pay = do
memExpCode <- concatMap executeMemExp <$> reader getMemExps
transferCallCode <- executeTransferCalls
return $
[ JUMPDESTFROM "pay_method" ]
++ throwIfNotActivated
++ memExpCode
++ transferCallCode
++ emitEvent "Paid"
++ [ STOP ]
I have done similarly for activate
and mint
.
The commit: https://github.com/Sword-Smith/Daggerc2.0/commit/9da4173ba9d87556c69372f87fe84e7a90bcf226
Great. Did you also add throwIfActivated
to the activate
method?
We would also like tests of this.
Great. Did you also add
throwIfActivated
to theactivate
method?
Yes
activateABI :: Compiler [EvmOpcode]
activateABI = do
m <- mint
return $
[JUMPDESTFROM "activate_method"]
++ throwIfActivated
-- start any timers
++ saveTimestampToStorage
-- transferFrom and mint
++ emitEvent "Activated"
-- mintABI methods jumps in here.
++ [JUMPDESTFROM "mint_method"]
++ throwIfNotActivated
++ m
-- finalize
++ [ STOP ]
We would also like tests of this.
Alright, coming up.
We would like tests of this
Conceivably incomplete: https://github.com/einar-io/geth_tools/commit/e8351666d1056438d1b0eaf1dd93a3251f8f9576
Seems complete
Do we need this check in
pay
, inmint
, or any other place? To check if the contract is activated, we should check if the timestamp word in storage is zero? If it is not zero, the contract is considered activated.