From 9ca72b678f821a87d675b5e9792421480c9931b4 Mon Sep 17 00:00:00 2001 From: Emily Pillmore Date: Tue, 9 Aug 2022 14:11:13 -0600 Subject: [PATCH 01/29] update pact for pact-4.4 --- cabal.project | 3 +- src/Chainweb/Pact/Backend/Utils.hs | 2 +- src/Chainweb/Pact/TransactionExec.hs | 41 ++++++++++++++--------- src/Chainweb/Version.hs | 18 ++++++++++ test/Chainweb/Test/Pact/RemotePactTest.hs | 4 +-- 5 files changed, 48 insertions(+), 20 deletions(-) diff --git a/cabal.project b/cabal.project index 57b3e43a38..a688e3f10f 100644 --- a/cabal.project +++ b/cabal.project @@ -51,7 +51,7 @@ package vault source-repository-package type: git location: https://github.com/kadena-io/pact.git - tag: 3081be0543631e8d68938ff7be21b5d6f49acfa3 + tag: 98dc6dbe9e917f26a238b2d4ac0f8ea90d65c5be source-repository-package type: git @@ -107,4 +107,3 @@ constraints: base64-bytestring <1.1 -- TODO remove once the bounds are upgraded in pact. allow-newer: pact:direct-sqlite - diff --git a/src/Chainweb/Pact/Backend/Utils.hs b/src/Chainweb/Pact/Backend/Utils.hs index a7d0d8d5c5..c00d526a2f 100644 --- a/src/Chainweb/Pact/Backend/Utils.hs +++ b/src/Chainweb/Pact/Backend/Utils.hs @@ -119,7 +119,7 @@ domainTableName :: Domain k v -> Utf8 domainTableName = asStringUtf8 convKeySetName :: KeySetName -> Utf8 -convKeySetName (KeySetName name) = toUtf8 name +convKeySetName = toUtf8 . asString convModuleName :: Bool diff --git a/src/Chainweb/Pact/TransactionExec.hs b/src/Chainweb/Pact/TransactionExec.hs index e0a193f692..f5d1496571 100644 --- a/src/Chainweb/Pact/TransactionExec.hs +++ b/src/Chainweb/Pact/TransactionExec.hs @@ -67,6 +67,7 @@ import qualified Data.ByteString.Short as SB import Data.Decimal (Decimal, roundTo) import Data.Default (def) import Data.Foldable (for_, traverse_, foldl') +import Data.IORef (newIORef) import qualified Data.HashMap.Strict as HM import Data.Maybe (isJust) import qualified Data.Set as S @@ -171,6 +172,7 @@ applyCmd v logger pdbenv miner gasModel txCtx spv cmdIn mcache0 = ++ enablePactModuleMemcheck txCtx ++ enablePact43 txCtx ++ enablePact431 txCtx + ++ enablePact44 txCtx ) cenv = TransactionEnv Transactional pdbenv logger (ctxToPublicData txCtx) spv nid gasPrice @@ -265,6 +267,7 @@ applyGenesisCmd logger dbEnv spv cmd = , FlagDisablePact420 , FlagDisableInlineMemCheck , FlagDisablePact43 + , FlagDisablePact44 ] } txst = TransactionState @@ -275,7 +278,7 @@ applyGenesisCmd logger dbEnv spv cmd = , _txGasModel = _geGasModel freeGasEnv } - interp = initStateInterpreter + interp = initStateInterpreter id $ initCapabilities [magic_GENESIS, magic_COINBASE] go = do @@ -313,7 +316,7 @@ applyCoinbase v logger dbEnv (Miner mid mks@(MinerKeys mk)) reward@(ParsedDecima go interp cexec | otherwise = do cexec <- mkCoinbaseCmd mid mks reward - let interp = initStateInterpreter initState + let interp = initStateInterpreter id initState go interp cexec where chainweb213Pact' = chainweb213Pact v bh @@ -327,7 +330,8 @@ applyCoinbase v logger dbEnv (Miner mid mks@(MinerKeys mk)) reward@(ParsedDecima enablePact420 txCtx ++ enablePactModuleMemcheck txCtx ++ enablePact43 txCtx ++ - enablePact431 txCtx + enablePact431 txCtx ++ + enablePact44 txCtx tenv = TransactionEnv Transactional dbEnv logger (ctxToPublicData txCtx) noSPVSupport Nothing 0.0 rk 0 ec txst = TransactionState mc mempty 0 Nothing (_geGasModel freeGasEnv) @@ -524,8 +528,9 @@ applyUpgrades v cid height caches <- local (set txExecutionConfig execConfig) $ mapM applyTx txs return $ Just (HM.unions caches) - interp = initStateInterpreter $ installCoinModuleAdmin $ - initCapabilities [mkMagicCapSlot "REMEDIATE"] + interp = initStateInterpreter id + $ installCoinModuleAdmin + $ initCapabilities [mkMagicCapSlot "REMEDIATE"] applyTx tx = do infoLog $ "Running upgrade tx " <> sshow (_cmdHash tx) @@ -561,7 +566,7 @@ applyTwentyChainUpgrade v cid bh applyTx tx = do infoLog $ "Running 20-chain upgrade tx " <> sshow (_cmdHash tx) - let i = initStateInterpreter + let i = initStateInterpreter id $ initCapabilities [mkMagicCapSlot "REMEDIATE"] r <- tryAllSynchronous (runGenesis tx permissiveNamespacePolicy i) @@ -717,6 +722,10 @@ enablePact431 tc | chainweb215Pact After (ctxVersion tc) (ctxCurrentBlockHeight tc) = [] | otherwise = [FlagDisablePact431] +enablePact44 :: TxContext -> [ExecutionFlag] +enablePact44 tc + | chainweb216Pact After (ctxVersion tc) (ctxCurrentBlockHeight tc) = [] + | otherwise = [FlagDisablePact44] -- | Execute a 'ContMsg' and return the command result and module cache -- @@ -879,7 +888,7 @@ redeemGas cmd = do managedNamespacePolicy where - initState mc = initStateInterpreter + initState mc = initStateInterpreter id $ setModuleCache mc $ initCapabilities [magic_GAS] @@ -898,8 +907,8 @@ initCapabilities :: [CapSlot UserCapability] -> EvalState initCapabilities cs = set (evalCapabilities . capStack) cs def {-# INLINABLE initCapabilities #-} -initStateInterpreter :: EvalState -> Interpreter p -initStateInterpreter s = Interpreter $ (put s >>) +initStateInterpreter :: (EvalEnv e -> EvalEnv e) -> EvalState -> Interpreter e +initStateInterpreter k s = Interpreter $ \e -> local k (put s >> e) -- | Check whether the cost of running a tx is more than the allowed @@ -926,10 +935,13 @@ checkTooBigTx initialGas gasLimit next onFail gasInterpreter :: Gas -> TransactionM db (Interpreter p) gasInterpreter g = do mc <- use txCache - return $ initStateInterpreter - $ set evalLogGas (Just [("GTxSize",g)]) -- enables gas logging - $ set evalGas g - $ setModuleCache mc def + ior <- liftIO $ newIORef g + let st = def + & evalLogGas ?~ [("GTxSize",g)] -- enables gas logging + & setModuleCache mc + ig = set eeGas ior + return $ initStateInterpreter ig st + -- | Initial gas charged for transaction size -- ignoring the size of a continuation proof, if present @@ -1019,8 +1031,7 @@ mkEvalEnv nsp msg = do <$> view (txGasLimit . to fromIntegral) <*> view txGasPrice <*> use txGasModel - - return $ setupEvalEnv (_txDbEnv tenv) Nothing (_txMode tenv) + liftIO $ setupEvalEnv (_txDbEnv tenv) Nothing (_txMode tenv) msg initRefStore genv nsp (_txSpvSupport tenv) (_txPublicData tenv) (_txExecutionConfig tenv) diff --git a/src/Chainweb/Version.hs b/src/Chainweb/Version.hs index c248a1ad11..b3c494331c 100644 --- a/src/Chainweb/Version.hs +++ b/src/Chainweb/Version.hs @@ -65,6 +65,7 @@ module Chainweb.Version , chainweb213Pact , chainweb214Pact , chainweb215Pact +, chainweb216Pact -- ** BlockHeader Validation Guards , slowEpochGuard @@ -984,6 +985,23 @@ chainweb215Pact aoa v h = case aoa of go f (FastTimedCPM g) | g == petersonChainGraph = f 35 go f _ = f 10 +-- | Pact and coin contract changes for Chainweb 2.15 +-- +chainweb216Pact + :: AtOrAfter + -> ChainwebVersion + -> BlockHeight + -> Bool +chainweb216Pact aoa v h = case aoa of + At -> go (==) v h + After -> go (<) v h + where + go f Mainnet01 = f 2766650 -- TODO + go f Testnet04 = f 2295457 -- TODO + go f Development = f 185 + go f (FastTimedCPM g) | g == petersonChainGraph = f 40 + go f _ = f 20 + -- -------------------------------------------------------------------------- -- -- Header Validation Guards -- diff --git a/test/Chainweb/Test/Pact/RemotePactTest.hs b/test/Chainweb/Test/Pact/RemotePactTest.hs index fc34a86c34..795dca93d7 100644 --- a/test/Chainweb/Test/Pact/RemotePactTest.hs +++ b/test/Chainweb/Test/Pact/RemotePactTest.hs @@ -678,7 +678,7 @@ allocationTest iot nio = testCaseSteps "genesis allocation tests" $ \step -> do $ M.fromList [ (FieldKey "account", PLiteral $ LString "allocation00") , (FieldKey "balance", PLiteral $ LDecimal 1_099_995.84) -- balance = (1k + 1mm) - gas - , (FieldKey "guard", PGuard $ GKeySetRef (KeySetName "allocation00")) + , (FieldKey "guard", PGuard $ GKeySetRef (KeySetName "allocation00" Nothing)) ] ttl = 2 * 24 * 60 * 60 @@ -703,7 +703,7 @@ allocationTest iot nio = testCaseSteps "genesis allocation tests" $ \step -> do $ M.fromList [ (FieldKey "account", PLiteral $ LString "allocation02") , (FieldKey "balance", PLiteral $ LDecimal 1_099_995.13) -- 1k + 1mm - gas - , (FieldKey "guard", PGuard $ GKeySetRef (KeySetName "allocation02")) + , (FieldKey "guard", PGuard $ GKeySetRef (KeySetName "allocation02" Nothing)) ] From 34ad004b737285396ba82aa6f60a4ec8b0dad0b5 Mon Sep 17 00:00:00 2001 From: Jose Date: Wed, 10 Aug 2022 12:43:13 -0400 Subject: [PATCH 02/29] set up initial gas environment --- src/Chainweb/Pact/TransactionExec.hs | 75 +++++++++++---------- test/Chainweb/Test/Pact/Checkpointer.hs | 4 +- test/Chainweb/Test/Pact/TransactionTests.hs | 2 +- 3 files changed, 44 insertions(+), 37 deletions(-) diff --git a/src/Chainweb/Pact/TransactionExec.hs b/src/Chainweb/Pact/TransactionExec.hs index f5d1496571..da1aa63b2c 100644 --- a/src/Chainweb/Pact/TransactionExec.hs +++ b/src/Chainweb/Pact/TransactionExec.hs @@ -67,7 +67,7 @@ import qualified Data.ByteString.Short as SB import Data.Decimal (Decimal, roundTo) import Data.Default (def) import Data.Foldable (for_, traverse_, foldl') -import Data.IORef (newIORef) +import Data.IORef import qualified Data.HashMap.Strict as HM import Data.Maybe (isJust) import qualified Data.Set as S @@ -278,7 +278,7 @@ applyGenesisCmd logger dbEnv spv cmd = , _txGasModel = _geGasModel freeGasEnv } - interp = initStateInterpreter id + interp = initStateInterpreter $ initCapabilities [magic_GENESIS, magic_COINBASE] go = do @@ -316,7 +316,7 @@ applyCoinbase v logger dbEnv (Miner mid mks@(MinerKeys mk)) reward@(ParsedDecima go interp cexec | otherwise = do cexec <- mkCoinbaseCmd mid mks reward - let interp = initStateInterpreter id initState + let interp = initStateInterpreter initState go interp cexec where chainweb213Pact' = chainweb213Pact v bh @@ -347,7 +347,7 @@ applyCoinbase v logger dbEnv (Miner mid mks@(MinerKeys mk)) reward@(ParsedDecima go interp cexec = evalTransactionM tenv txst $! do cr <- catchesPactError $! - applyExec' interp cexec mempty chash managedNamespacePolicy + applyExec' 0 interp cexec mempty chash managedNamespacePolicy case cr of Left e @@ -417,9 +417,9 @@ applyLocal logger dbEnv gasModel txCtx spv cmdIn mc execConfig = interp <- gasInterpreter gas0 cr <- catchesPactError $! case m of Exec em -> - applyExec interp em signers chash managedNamespacePolicy + applyExec gas0 interp em signers chash managedNamespacePolicy Continuation cm -> - applyContinuation interp cm signers chash managedNamespacePolicy + applyContinuation gas0 interp cm signers chash managedNamespacePolicy case cr of Left e -> jsonErrorResult e "applyLocal" @@ -453,7 +453,7 @@ readInitModules logger dbEnv txCtx = mkCmd = buildExecParsedCode (Just (v, h)) Nothing run msg cmd = do er <- catchesPactError $! - applyExec' interp cmd [] chash permissiveNamespacePolicy + applyExec' 0 interp cmd [] chash permissiveNamespacePolicy case er of Left e -> die $ msg <> ": failed: " <> sshow e Right r -> case _erOutput r of @@ -528,7 +528,7 @@ applyUpgrades v cid height caches <- local (set txExecutionConfig execConfig) $ mapM applyTx txs return $ Just (HM.unions caches) - interp = initStateInterpreter id + interp = initStateInterpreter $ installCoinModuleAdmin $ initCapabilities [mkMagicCapSlot "REMEDIATE"] @@ -566,7 +566,7 @@ applyTwentyChainUpgrade v cid bh applyTx tx = do infoLog $ "Running 20-chain upgrade tx " <> sshow (_cmdHash tx) - let i = initStateInterpreter id + let i = initStateInterpreter $ initCapabilities [mkMagicCapSlot "REMEDIATE"] r <- tryAllSynchronous (runGenesis tx permissiveNamespacePolicy i) @@ -607,9 +607,9 @@ runPayload cmd nsp = do case payload of Exec pm -> - applyExec interp pm signers chash nsp + applyExec g0 interp pm signers chash nsp Continuation ym -> - applyContinuation interp ym signers chash nsp + applyContinuation g0 interp ym signers chash nsp where signers = _pSigners $ _cmdPayload cmd @@ -625,9 +625,9 @@ runGenesis -> TransactionM p (CommandResult [TxLog Value]) runGenesis cmd nsp interp = case payload of Exec pm -> - applyExec interp pm signers chash nsp + applyExec 0 interp pm signers chash nsp Continuation ym -> - applyContinuation interp ym signers chash nsp + applyContinuation 0 interp ym signers chash nsp where signers = _pSigners $ _cmdPayload cmd chash = toUntypedHash $ _cmdHash cmd @@ -636,14 +636,15 @@ runGenesis cmd nsp interp = case payload of -- | Execute an 'ExecMsg' and Return the result with module cache -- applyExec - :: Interpreter p + :: Gas + -> Interpreter p -> ExecMsg ParsedCode -> [Signer] -> Hash -> NamespacePolicy -> TransactionM p (CommandResult [TxLog Value]) -applyExec interp em senderSigs hsh nsp = do - EvalResult{..} <- applyExec' interp em senderSigs hsh nsp +applyExec initialGas interp em senderSigs hsh nsp = do + EvalResult{..} <- applyExec' initialGas interp em senderSigs hsh nsp debug $ "gas logs: " <> sshow _erLogGas logs <- use txLogs rk <- view txRequestKey @@ -657,13 +658,14 @@ applyExec interp em senderSigs hsh nsp = do -- wrapping it up in a JSON result. -- applyExec' - :: Interpreter p + :: Gas + -> Interpreter p -> ExecMsg ParsedCode -> [Signer] -> Hash -> NamespacePolicy -> TransactionM p EvalResult -applyExec' interp (ExecMsg parsedCode execData) senderSigs hsh nsp +applyExec' initialGas interp (ExecMsg parsedCode execData) senderSigs hsh nsp | null (_pcExps parsedCode) = throwCmdEx "No expressions found" | otherwise = do @@ -674,6 +676,7 @@ applyExec' interp (ExecMsg parsedCode execData) senderSigs hsh nsp <&> disablePact420Natives pactFlags <&> disablePact43Natives pactFlags <&> disablePact431Natives pactFlags + setEnvGas initialGas eenv er <- liftIO $! evalExec interp eenv parsedCode @@ -730,14 +733,15 @@ enablePact44 tc -- | Execute a 'ContMsg' and return the command result and module cache -- applyContinuation - :: Interpreter p + :: Gas + -> Interpreter p -> ContMsg -> [Signer] -> Hash -> NamespacePolicy -> TransactionM p (CommandResult [TxLog Value]) -applyContinuation interp cm senderSigs hsh nsp = do - EvalResult{..} <- applyContinuation' interp cm senderSigs hsh nsp +applyContinuation initialGas interp cm senderSigs hsh nsp = do + EvalResult{..} <- applyContinuation' initialGas interp cm senderSigs hsh nsp debug $ "gas logs: " <> sshow _erLogGas logs <- use txLogs rk <- view txRequestKey @@ -745,17 +749,22 @@ applyContinuation interp cm senderSigs hsh nsp = do return $! (CommandResult rk _erTxId (PactResult (Right (last _erOutput))) _erGas (Just logs) _erExec Nothing) _erEvents + +setEnvGas :: Gas -> EvalEnv e -> TransactionM p () +setEnvGas initialGas = liftIO . views eeGas (`writeIORef` initialGas) + -- | Execute a 'ContMsg' and return just eval result, not wrapped in a -- 'CommandResult' wrapper -- applyContinuation' - :: Interpreter p + :: Gas + -> Interpreter p -> ContMsg -> [Signer] -> Hash -> NamespacePolicy -> TransactionM p EvalResult -applyContinuation' interp cm@(ContMsg pid s rb d _) senderSigs hsh nsp = do +applyContinuation' initialGas interp cm@(ContMsg pid s rb d _) senderSigs hsh nsp = do pactFlags <- asks _txExecutionConfig @@ -763,6 +772,7 @@ applyContinuation' interp cm@(ContMsg pid s rb d _) senderSigs hsh nsp = do <&> disablePact40Natives pactFlags <&> disablePact420Natives pactFlags <&> disablePact43Natives pactFlags + setEnvGas initialGas eenv er <- liftIO $! evalContinuation interp eenv cm @@ -800,7 +810,7 @@ buyGas isPactBackCompatV16 cmd (Miner mid mks) = go interp mc = Interpreter $ \_input -> put (initState mc) >> run (pure <$> eval buyGasTerm) - result <- applyExec' (interp mcache) buyGasCmd + result <- applyExec' 0 (interp mcache) buyGasCmd (_pSigners $ _cmdPayload cmd) bgHash managedNamespacePolicy case _erExec result of @@ -883,12 +893,12 @@ redeemGas cmd = do fee <- gasSupplyOf <$> use txGasUsed <*> view txGasPrice - _crEvents <$> applyContinuation (initState mcache) (redeemGasCmd fee gid) + _crEvents <$> applyContinuation 0 (initState mcache) (redeemGasCmd fee gid) (_pSigners $ _cmdPayload cmd) (toUntypedHash $ _cmdHash cmd) managedNamespacePolicy where - initState mc = initStateInterpreter id + initState mc = initStateInterpreter $ setModuleCache mc $ initCapabilities [magic_GAS] @@ -907,8 +917,8 @@ initCapabilities :: [CapSlot UserCapability] -> EvalState initCapabilities cs = set (evalCapabilities . capStack) cs def {-# INLINABLE initCapabilities #-} -initStateInterpreter :: (EvalEnv e -> EvalEnv e) -> EvalState -> Interpreter e -initStateInterpreter k s = Interpreter $ \e -> local k (put s >> e) +initStateInterpreter :: EvalState -> Interpreter e +initStateInterpreter s = Interpreter (put s >>) -- | Check whether the cost of running a tx is more than the allowed @@ -935,12 +945,9 @@ checkTooBigTx initialGas gasLimit next onFail gasInterpreter :: Gas -> TransactionM db (Interpreter p) gasInterpreter g = do mc <- use txCache - ior <- liftIO $ newIORef g - let st = def - & evalLogGas ?~ [("GTxSize",g)] -- enables gas logging - & setModuleCache mc - ig = set eeGas ior - return $ initStateInterpreter ig st + return $ initStateInterpreter + $ set evalLogGas (Just [("GTxSize",g)]) -- enables gas logging + $ setModuleCache mc def -- | Initial gas charged for transaction size diff --git a/test/Chainweb/Test/Pact/Checkpointer.hs b/test/Chainweb/Test/Pact/Checkpointer.hs index 06884cc062..c18ee64acc 100644 --- a/test/Chainweb/Test/Pact/Checkpointer.hs +++ b/test/Chainweb/Test/Pact/Checkpointer.hs @@ -605,7 +605,7 @@ runExec :: CheckpointEnv -> PactDbEnv'-> Maybe Value -> Text -> IO EvalResult runExec cp (PactDbEnv' pactdbenv) eData eCode = do execMsg <- buildExecParsedCode Nothing {- use latest parser version -} eData eCode evalTransactionM cmdenv cmdst $ - applyExec' defaultInterpreter execMsg [] h' permissiveNamespacePolicy + applyExec' 0 defaultInterpreter execMsg [] h' permissiveNamespacePolicy where h' = H.toUntypedHash (H.hash "" :: H.PactHash) cmdenv = TransactionEnv Transactional pactdbenv (_cpeLogger cp) def @@ -615,7 +615,7 @@ runExec cp (PactDbEnv' pactdbenv) eData eCode = do runCont :: CheckpointEnv -> PactDbEnv' -> PactId -> Int -> IO EvalResult runCont cp (PactDbEnv' pactdbenv) pactId step = do evalTransactionM cmdenv cmdst $ - applyContinuation' defaultInterpreter contMsg [] h' permissiveNamespacePolicy + applyContinuation' 0 defaultInterpreter contMsg [] h' permissiveNamespacePolicy where contMsg = ContMsg pactId step False Null Nothing diff --git a/test/Chainweb/Test/Pact/TransactionTests.hs b/test/Chainweb/Test/Pact/TransactionTests.hs index 8f0b3553cd..c9099998bd 100644 --- a/test/Chainweb/Test/Pact/TransactionTests.hs +++ b/test/Chainweb/Test/Pact/TransactionTests.hs @@ -249,7 +249,7 @@ testCoinbase797DateFix = testCaseSteps "testCoinbase791Fix" $ \step -> do txst = TransactionState mempty mempty 0 Nothing (_geGasModel freeGasEnv) CommandResult _ _ (PactResult pr) _ _ _ _ _ <- evalTransactionM tenv txst $! - applyExec defaultInterpreter localCmd [] h permissiveNamespacePolicy + applyExec 0 defaultInterpreter localCmd [] h permissiveNamespacePolicy testResult pr From 76d5ae64add5a429ae5d48961724e8dda8a920b8 Mon Sep 17 00:00:00 2001 From: Jose Date: Wed, 10 Aug 2022 14:48:42 -0400 Subject: [PATCH 03/29] wip fix tests --- cabal.project | 2 +- pact/coin-contract/coin.repl | 4 ++-- pact/coin-contract/v3/coin-v3.repl | 1 + pact/coin-contract/v4/coin-v4.repl | 4 ++-- pact/coin-contract/v5/coin-v5.repl | 4 ++-- pact/namespaces/ns.pact | 1 - pact/namespaces/ns.repl | 1 + src/Chainweb/Pact/TransactionExec.hs | 3 ++- src/Chainweb/Rosetta/Utils.hs | 28 ++++++++++++++-------------- src/Chainweb/Version.hs | 2 +- 10 files changed, 26 insertions(+), 24 deletions(-) diff --git a/cabal.project b/cabal.project index 3949ca5214..502c991b46 100644 --- a/cabal.project +++ b/cabal.project @@ -54,7 +54,7 @@ package yet-another-logger source-repository-package type: git location: https://github.com/kadena-io/pact.git - tag: 98dc6dbe9e917f26a238b2d4ac0f8ea90d65c5be + tag: abb70b6c46cfcdf83f841f43fb797c0324119737 source-repository-package type: git diff --git a/pact/coin-contract/coin.repl b/pact/coin-contract/coin.repl index 0e87cdf6b6..f3ca808d67 100644 --- a/pact/coin-contract/coin.repl +++ b/pact/coin-contract/coin.repl @@ -1,5 +1,5 @@ ;; Enable the table gas model -(env-exec-config ["DisableInlineMemCheck", "DisablePact43"]) +(env-exec-config ["DisableInlineMemCheck", "DisablePact43", "DisablePact44", "PreserveNamespaceUpgrade"]) (env-gasmodel "table") (env-gaslimit 30000) @@ -521,7 +521,7 @@ "success")) ; make sure chain-id is enforced in the yield -(env-exec-config ['DisablePact40, 'DisableInlineMemCheck, 'DisablePact43]) +(env-exec-config ['DisablePact40, 'DisableInlineMemCheck, 'DisablePact43, "DisablePact44", "PreserveNamespaceUpgrade"]) (expect-failure "create side of cross-chain transfer fails yield on wrong chain" "does not match (chain" diff --git a/pact/coin-contract/v3/coin-v3.repl b/pact/coin-contract/v3/coin-v3.repl index 0582b11300..d90be81706 100644 --- a/pact/coin-contract/v3/coin-v3.repl +++ b/pact/coin-contract/v3/coin-v3.repl @@ -3,6 +3,7 @@ , "coin-load-gas": 3413 }) (load "../v2/coin.repl") +(env-exec-config ["DisablePact44", "PreserveNamespaceUpgrade"]) ;; ====================================================== ;; test transfer, gas events diff --git a/pact/coin-contract/v4/coin-v4.repl b/pact/coin-contract/v4/coin-v4.repl index 36d1c7b2b3..b413ef3a37 100644 --- a/pact/coin-contract/v4/coin-v4.repl +++ b/pact/coin-contract/v4/coin-v4.repl @@ -1,5 +1,5 @@ ;; Enable the table gas model -(env-exec-config ["DisableInlineMemCheck", "DisablePact43"]) +(env-exec-config ["DisableInlineMemCheck", "DisablePact43", "DisablePact44", "PreserveNamespaceUpgrade"]) (env-gasmodel "table") (env-gaslimit 150000) @@ -12,7 +12,7 @@ 840 (env-gas)) (commit-tx) -(env-exec-config []) +(env-exec-config ["DisablePact44", "PreserveNamespaceUpgrade"]) (env-gasmodel "table") (env-gas 0) (env-gaslog) (begin-tx) diff --git a/pact/coin-contract/v5/coin-v5.repl b/pact/coin-contract/v5/coin-v5.repl index b146572cf8..b7a97944a7 100644 --- a/pact/coin-contract/v5/coin-v5.repl +++ b/pact/coin-contract/v5/coin-v5.repl @@ -1,5 +1,5 @@ ;; Enable the table gas model -(env-exec-config ["DisableInlineMemCheck", "DisablePact43"]) +(env-exec-config ["DisableInlineMemCheck", "DisablePact43", "DisablePact44"]) (env-gasmodel "table") (env-gaslimit 150000) @@ -12,7 +12,7 @@ 840 (env-gas)) (commit-tx) -(env-exec-config []) +(env-exec-config ["DisablePact44"]) (env-gasmodel "table") (env-gas 0) (env-gaslog) (begin-tx) diff --git a/pact/namespaces/ns.pact b/pact/namespaces/ns.pact index ac61e95090..54a5992373 100644 --- a/pact/namespaces/ns.pact +++ b/pact/namespaces/ns.pact @@ -1,4 +1,3 @@ - (define-keyset 'ns-admin-keyset (read-keyset 'ns-admin-keyset)) (define-keyset 'ns-operate-keyset (read-keyset 'ns-genesis-keyset)) diff --git a/pact/namespaces/ns.repl b/pact/namespaces/ns.repl index 741f152024..7bcb99b77f 100644 --- a/pact/namespaces/ns.repl +++ b/pact/namespaces/ns.repl @@ -1,3 +1,4 @@ +(env-exec-config ["DisablePact44", "PreserveNamespaceUpgrade"]) (begin-tx) (env-data { 'ns-admin-keyset: ["admin"] diff --git a/src/Chainweb/Pact/TransactionExec.hs b/src/Chainweb/Pact/TransactionExec.hs index bc0759402b..9bc2542d92 100644 --- a/src/Chainweb/Pact/TransactionExec.hs +++ b/src/Chainweb/Pact/TransactionExec.hs @@ -268,6 +268,7 @@ applyGenesisCmd logger dbEnv spv cmd = , FlagDisableInlineMemCheck , FlagDisablePact43 , FlagDisablePact44 + , FlagPreserveNamespaceUpgrade ] } txst = TransactionState @@ -728,7 +729,7 @@ enablePact431 tc enablePact44 :: TxContext -> [ExecutionFlag] enablePact44 tc | chainweb216Pact After (ctxVersion tc) (ctxCurrentBlockHeight tc) = [] - | otherwise = [FlagDisablePact44] + | otherwise = [FlagDisablePact44, FlagPreserveNamespaceUpgrade] -- | Execute a 'ContMsg' and return the command result and module cache -- diff --git a/src/Chainweb/Rosetta/Utils.hs b/src/Chainweb/Rosetta/Utils.hs index 03fec29556..07f0dfe35b 100644 --- a/src/Chainweb/Rosetta/Utils.hs +++ b/src/Chainweb/Rosetta/Utils.hs @@ -299,7 +299,7 @@ instance FromJSON ConstructionTx where -- performs balance and k:account checks. transferTx :: (AccountId, P.ParsedDecimal, P.KeySet) - -> (AccountId, P.ParsedDecimal, P.KeySet) + -> (AccountId, P.ParsedDecimal, P.KeySet) -> Either RosettaError ConstructionTx transferTx (acct1, bal1, ks1) (acct2, bal2, ks2) | acct1 == acct2 = @@ -421,7 +421,7 @@ getSuggestedFee tx someMaxFees someMult = do fee = kdaToRosettaAmount $! calcKDAFee gasLimit gasPrice pure (gasLimit, gasPrice, fee) - + where ------------ -- Defaults @@ -432,7 +432,7 @@ getSuggestedFee tx someMaxFees someMult = do -- - https://explorer.chainweb.com/testnet/tx/g8dxg1CAM3eZ5S-rk51N27N8-nKEW3Wg_cyk5moqmBg -- - https://explorer.chainweb.com/testnet/tx/IGVzaRkTHOSMIiHM7q8bPxrATW5b5SEhoCqE6tPkVFA -- - https://explorer.chainweb.com/testnet/tx/cK0B0XOkOlMDR32GloR0GQvjAWAJ9mvNPZwQDalPr6c - defGasUnitsTransferCreate = 700 + defGasUnitsTransferCreate = 1000 -- See Chainweb.Chainweb.Configuration for latest min gas minGasPrice = Decimal 8 1 @@ -471,7 +471,7 @@ getSuggestedFee tx someMaxFees someMult = do minFeeNeeded = calcKDAFee estimatedGasLimit (P.GasPrice $ P.ParsedDecimal minGasPrice) - + estimatedGasLimit = P.GasLimit $ P.ParsedInteger $! case tx of ConstructTransfer {} -> defGasUnitsTransferCreate @@ -512,7 +512,7 @@ getSuggestedFee tx someMaxFees someMult = do P.GasLimit (P.ParsedInteger units) = gasLimit P.GasPrice (P.ParsedDecimal price) = gasPrice fee = fromIntegral units * price - + -------------------------------------------------------------------------------- -- /metadata @@ -711,7 +711,7 @@ createSigningPayloads (EnrichedCommand cmd _ _) = map f where hashBase16 = P.toB16Text $! P.unHash $! P.toUntypedHash $! _cmdHash cmd - + f (signer, acct) = RosettaSigningPayload { _rosettaSigningPayload_address = Nothing , _rosettaSigningPayload_accountIdentifier = Just acct @@ -732,7 +732,7 @@ txToOps txInfo = case txInfo of [ op (_accountId_address from) (negate amt) fromGuard 0 , op (_accountId_address to) amt toGuard 1 ] - + where op name delta guard idx = o { _operation_status = "" } @@ -743,7 +743,7 @@ txToOps txInfo = case txInfo of (toAcctLog name delta guard) idx [] - + toAcctLog name delta guard = AccountLog { _accountLogKey = name , _accountLogBalanceDelta = BalanceDelta delta @@ -770,7 +770,7 @@ matchSigs matchSigs sigs signers = do sigMap <- HM.fromList <$> mapM sigAndAddr sigs mapM (match sigMap) signers - + where match :: HM.HashMap T.Text UserSig @@ -781,16 +781,16 @@ matchSigs sigs signers = do note (stringRosettaError RosettaInvalidSignature $ "Missing signature for public key=" ++ show (_siPubKey signer)) $ HM.lookup addr m - + sigAndAddr (RosettaSignature _ (RosettaPublicKey pk ct) sigTyp sig) = do _ <- toRosettaError RosettaInvalidSignature $! P.parseB16TextOnly sig sigScheme <- sigToScheme sigTyp pkScheme <- getScheme ct when (sigScheme /= pkScheme) (Left $ stringRosettaError RosettaInvalidSignature $ - "Expected the same Signature and PublicKey type for Signature=" ++ show sig) + "Expected the same Signature and PublicKey type for Signature=" ++ show sig) - let userSig = P.UserSig sig + let userSig = P.UserSig sig addr <- toPactPubKeyAddr pk pkScheme pure (addr, userSig) @@ -1002,7 +1002,7 @@ parseOp (Operation i _ typ stat someAcct someAmt _ someMeta) = do prevOwn @?= currOwn -- ensure that the ownership wasn't rotated ownership <- hushResult (fromJSON currOwn) @?? "Only Pact KeySet is supported for account ownership" - + pure (acct, P.ParsedDecimal amtDelta, ownership) where @@ -1011,7 +1011,7 @@ parseOp (Operation i _ typ stat someAcct someAmt _ someMeta) = do Left $ stringRosettaError RosettaInvalidOperation $ "Operation id=" ++ show i ++ ": " ++ msg (Just a) @?? _ = pure a - + (@?=) :: (Show a, Eq a) => a -> a diff --git a/src/Chainweb/Version.hs b/src/Chainweb/Version.hs index fcbfa533e2..f8b172b16f 100644 --- a/src/Chainweb/Version.hs +++ b/src/Chainweb/Version.hs @@ -998,7 +998,7 @@ chainweb216Pact aoa v h = case aoa of go f Mainnet01 = f 2988358 -- 2022-09-02 00:00:00+00:00 go f Testnet04 = f 2516927 -- 2022-09-01 12:00:00+00:00 go f Development = f 215 - go f (FastTimedCPM g) | g == petersonChainGraph = f 36 + go f (FastTimedCPM g) | g == petersonChainGraph = f 1000000 go f _ = f 16 -- -------------------------------------------------------------------------- -- From 9f51bc16ae8b9d1aa386a050661750a1f58f44e9 Mon Sep 17 00:00:00 2001 From: Jose Date: Wed, 10 Aug 2022 15:15:36 -0400 Subject: [PATCH 04/29] fix rosetta gas bound --- src/Chainweb/Rosetta/Utils.hs | 2 +- src/Chainweb/Version.hs | 2 +- test/Chainweb/Test/Pact/Checkpointer.hs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Chainweb/Rosetta/Utils.hs b/src/Chainweb/Rosetta/Utils.hs index 07f0dfe35b..50c24fc204 100644 --- a/src/Chainweb/Rosetta/Utils.hs +++ b/src/Chainweb/Rosetta/Utils.hs @@ -432,7 +432,7 @@ getSuggestedFee tx someMaxFees someMult = do -- - https://explorer.chainweb.com/testnet/tx/g8dxg1CAM3eZ5S-rk51N27N8-nKEW3Wg_cyk5moqmBg -- - https://explorer.chainweb.com/testnet/tx/IGVzaRkTHOSMIiHM7q8bPxrATW5b5SEhoCqE6tPkVFA -- - https://explorer.chainweb.com/testnet/tx/cK0B0XOkOlMDR32GloR0GQvjAWAJ9mvNPZwQDalPr6c - defGasUnitsTransferCreate = 1000 + defGasUnitsTransferCreate = 2500 -- See Chainweb.Chainweb.Configuration for latest min gas minGasPrice = Decimal 8 1 diff --git a/src/Chainweb/Version.hs b/src/Chainweb/Version.hs index f8b172b16f..d24d5c603f 100644 --- a/src/Chainweb/Version.hs +++ b/src/Chainweb/Version.hs @@ -998,7 +998,7 @@ chainweb216Pact aoa v h = case aoa of go f Mainnet01 = f 2988358 -- 2022-09-02 00:00:00+00:00 go f Testnet04 = f 2516927 -- 2022-09-01 12:00:00+00:00 go f Development = f 215 - go f (FastTimedCPM g) | g == petersonChainGraph = f 1000000 + go f (FastTimedCPM g) | g == petersonChainGraph = f 53 go f _ = f 16 -- -------------------------------------------------------------------------- -- diff --git a/test/Chainweb/Test/Pact/Checkpointer.hs b/test/Chainweb/Test/Pact/Checkpointer.hs index c18ee64acc..fea07c2c76 100644 --- a/test/Chainweb/Test/Pact/Checkpointer.hs +++ b/test/Chainweb/Test/Pact/Checkpointer.hs @@ -609,7 +609,7 @@ runExec cp (PactDbEnv' pactdbenv) eData eCode = do where h' = H.toUntypedHash (H.hash "" :: H.PactHash) cmdenv = TransactionEnv Transactional pactdbenv (_cpeLogger cp) def - noSPVSupport Nothing 0.0 (RequestKey h') 0 def + noSPVSupport Nothing 0.0 (RequestKey h') 0 (mkExecutionConfig [FlagDisablePact44]) cmdst = TransactionState mempty mempty 0 Nothing (_geGasModel freeGasEnv) runCont :: CheckpointEnv -> PactDbEnv' -> PactId -> Int -> IO EvalResult From 6a052aac5574cfd95b48e7b6ef2ed2a955a3f63d Mon Sep 17 00:00:00 2001 From: Jose Date: Wed, 10 Aug 2022 15:16:26 -0400 Subject: [PATCH 05/29] update pin to latest master --- cabal.project | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cabal.project b/cabal.project index 502c991b46..4804678bb9 100644 --- a/cabal.project +++ b/cabal.project @@ -54,7 +54,7 @@ package yet-another-logger source-repository-package type: git location: https://github.com/kadena-io/pact.git - tag: abb70b6c46cfcdf83f841f43fb797c0324119737 + tag: c07fa8a65f6c02acbf72ada94cb0b0a3741f6dc8 source-repository-package type: git From ea2c89900d0cbcdae6e2526d83dd852f04c142cc Mon Sep 17 00:00:00 2001 From: Jose Date: Wed, 10 Aug 2022 15:45:51 -0400 Subject: [PATCH 06/29] Fix spcae mistake in ns.pact --- pact/namespaces/ns.pact | 1 + 1 file changed, 1 insertion(+) diff --git a/pact/namespaces/ns.pact b/pact/namespaces/ns.pact index 54a5992373..ac61e95090 100644 --- a/pact/namespaces/ns.pact +++ b/pact/namespaces/ns.pact @@ -1,3 +1,4 @@ + (define-keyset 'ns-admin-keyset (read-keyset 'ns-admin-keyset)) (define-keyset 'ns-operate-keyset (read-keyset 'ns-genesis-keyset)) From 3ac3196466a7c3ebe696b790de998d1f71724c00 Mon Sep 17 00:00:00 2001 From: Emily Pillmore Date: Wed, 10 Aug 2022 15:52:40 -0600 Subject: [PATCH 07/29] get started on pactinprocapi test --- test/Chainweb/Test/Pact/PactInProcApi.hs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/test/Chainweb/Test/Pact/PactInProcApi.hs b/test/Chainweb/Test/Pact/PactInProcApi.hs index 9db5710949..96de8408aa 100644 --- a/test/Chainweb/Test/Pact/PactInProcApi.hs +++ b/test/Chainweb/Test/Pact/PactInProcApi.hs @@ -129,6 +129,7 @@ tests rdb = ScheduledTest testName go , multiChainTest getGasModel "pact43UpgradeTest" pact43UpgradeTest , multiChainTest getGasModel "pact431UpgradeTest" pact431UpgradeTest , multiChainTest getGasModel "chainweb215Test" chainweb215Test + , multiChainTest getGasModel "chainweb216Test" chainweb216Test ] where test logLevel f = @@ -951,6 +952,24 @@ pact420UpgradeTest bdb mpRefIO pact = do "(zip (+) [1 2 3] [4 5 6])" ] +chainweb216Test + :: TestBlockDb + -> IO (IORef MemPoolAccess) + -> WebPactExecutionService + -> IO () +chainweb216Test bdb mpRefIO pact = do + -- This test should handles for format and try as well as + -- keyset format changes and disallowances across fork boundaries. + -- + -- Namely, to test keys properly, we should: + -- + -- 1. Make sure keys defined before and after + -- fork boundaries pass enforcement. + -- + -- 2. Keys defined after the fork are only + -- definable if a namespace is present. + -- + pure () pact4coin3UpgradeTest :: TestBlockDb -> IO (IORef MemPoolAccess) -> WebPactExecutionService -> IO () pact4coin3UpgradeTest bdb mpRefIO pact = do From 7ea8f31cddfbf7c3b93fd231789012612972850d Mon Sep 17 00:00:00 2001 From: Jose Date: Fri, 12 Aug 2022 13:13:20 -0400 Subject: [PATCH 08/29] wip tests to pre/post fork conditions in define-keyset --- test/Chainweb/Test/Pact/PactInProcApi.hs | 118 ++++++++++++++++++++++- 1 file changed, 117 insertions(+), 1 deletion(-) diff --git a/test/Chainweb/Test/Pact/PactInProcApi.hs b/test/Chainweb/Test/Pact/PactInProcApi.hs index 96de8408aa..1c137e15a4 100644 --- a/test/Chainweb/Test/Pact/PactInProcApi.hs +++ b/test/Chainweb/Test/Pact/PactInProcApi.hs @@ -8,6 +8,8 @@ {-# LANGUAGE TypeApplications #-} {-# LANGUAGE ViewPatterns #-} {-# LANGUAGE PatternSynonyms #-} +{-# LANGUAGE FlexibleContexts #-} +{-# LANGUAGE DerivingVia #-} -- | -- Module: Chainweb.Test.PactInProcApi @@ -969,7 +971,121 @@ chainweb216Test bdb mpRefIO pact = do -- 2. Keys defined after the fork are only -- definable if a namespace is present. -- - pure () + + -- run past genesis, upgrades + forM_ [(1::Int)..52] $ const runCut' + setOneShotMempool mpRefIO preForkBlock + runCut' + + pwo53 <- getPWO bdb cid + tx53_0 <- txResult "pwo53" 0 pwo53 + assertEqual "Pre-fork format gas" 11 + (tx53_0 ^. crGas) + + tx53_1 <- txResult "pwo53" 1 pwo53 + assertEqual "Pre-fork try" 9 + (tx53_1 ^. crGas) + + tx53_2 <- txResult "pwo53" 2 pwo53 + assertEqual "Should pass when defining a non-namespaced keyset" + (Just (PLiteral (LBool True))) + (tx53_2 ^? crResult . to _pactResult . _Right) + + tx53_3 <- txResult "pwo53" 3 pwo53 + -- Note, keysets technically are not namespaced pre-fork, the new parser isn't applied + assertEqual "Should pass when defining a \"namespaced\" keyset pre fork" + (Just (PLiteral (LBool True))) + (tx53_3 ^? crResult . to _pactResult . _Right) + + + setOneShotMempool mpRefIO postForkBlock + runCut' + + pwo54 <- getPWO bdb cid + tx54_0 <- txResult "pwo54" 0 pwo54 + assertEqual "Post-fork format gas increase" 38 + (tx54_0 ^. crGas) + + tx54_1 <- txResult "pwo54" 1 pwo54 + assertEqual "Post-fork try should charge a bit more gas" 10 + (tx54_1 ^. crGas) + + tx54_2 <- txResult "pwo54" 2 pwo54 + assertEqual "Should fail when defining a non-namespaced keyset post fork" + (Just "incorrect keyset name format") + (tx54_2 ^? crResult . to _pactResult . _Left . to peDoc) + + tx54_3 <- txResult "pwo54" 3 pwo54 + assertEqual "Pass when defining a namespaced keyset post fork" + (Just "asdf") + (tx54_3 ^? crResult . to _pactResult . _Left . to peDoc) + + tx54_4 <- txResult "pwo54" 4 pwo54 + assertEqual "Should work in enforcing a namespaced keyset created prefork" + (Just (PLiteral (LBool True))) + (tx54_4 ^? crResult . to _pactResult . _Right) + + tx54_5 <- txResult "pwo54" 5 pwo54 + assertEqual "Should work in enforcing a non-namespaced keyset created prefork" + (Just (PLiteral (LBool True))) + (tx54_5 ^? crResult . to _pactResult . _Right) + where + runCut' = runCut testVersion bdb pact (offsetBlockTime second) zeroNoncer noMiner + defineNonNamespacedPreFork = mconcat + [ "(namespace 'free)" + , "(define-keyset \'k123)" + , "(enforce-guard (keyset-ref-guard \'k123))" + ] + defineNamespacedPreFork = mconcat + [ "(namespace 'free)" + , "(define-keyset \"free.k123\")" + , "(enforce-guard (keyset-ref-guard \"free.k123\"))" + ] + defineNonNamespacedPostFork = mconcat + [ "(namespace 'free)" + , "(define-keyset \'k456)" + ] + defineNamespacedPostFork = mconcat + [ "(namespace 'free)" + , "(define-keyset \"free.k456\")" + , "(enforce-guard (keyset-ref-guard \"free.k456\"))" + ] + enforceNamespacedFromPreFork = "(enforce-guard (keyset-ref-guard \"free.k123\"))" + enforceNonNamespacedFromPreFork = "(enforce-guard (keyset-ref-guard \"k123\"))" + tryGas = "(try (+ 1 1) (enforce false \"abc\"))" + formatGas = "(format \"{}-{}\" [1234567, 890111213141516])" + preForkBlock = mempty { + mpaGetBlock = \_ _ _ _ bh -> if _blockChainId bh == cid then do + t0 <- buildSimpleCmd bh formatGas + t1 <- buildSimpleCmd bh tryGas + t2 <- buildSimpleCmd bh defineNonNamespacedPreFork + t3 <- buildSimpleCmd bh defineNamespacedPreFork + return $! V.fromList [t0,t1,t2,t3] + else return mempty + } + postForkBlock = mempty { + mpaGetBlock = \_ _ _ _ bh -> if _blockChainId bh == cid then do + t0 <- buildSimpleCmd bh formatGas + t1 <- buildSimpleCmd bh tryGas + t2 <- buildSimpleCmd bh defineNonNamespacedPostFork + t3 <- buildSimpleCmd bh defineNamespacedPostFork + t4 <- buildSimpleCmd bh enforceNamespacedFromPreFork + t5 <- buildSimpleCmd bh enforceNonNamespacedFromPreFork + return $! V.fromList [t0,t1,t2,t3,t4,t5] + else return mempty + } + buildSimpleCmd bh code = buildCwCmd + $ set cbSigners [mkSigner' sender00 []] + $ set cbChainId (_blockChainId bh) + $ set cbCreationTime (toTxCreationTime $ _bct $ _blockCreationTime bh) + $ set cbGasLimit 10000 + $ mkCmd code + $ mkExec code + $ object + [ "k123" .= map fst [sender00] + , "k456" .= map fst [sender00] + , "free.k123" .= map fst [sender00] + , "free.k456" .= map fst [sender00]] pact4coin3UpgradeTest :: TestBlockDb -> IO (IORef MemPoolAccess) -> WebPactExecutionService -> IO () pact4coin3UpgradeTest bdb mpRefIO pact = do From 12914a2ea747cb5b8dbf98585eabd92df56fe403 Mon Sep 17 00:00:00 2001 From: Jose Date: Fri, 12 Aug 2022 14:40:26 -0400 Subject: [PATCH 09/29] all tests pre-post fork --- cabal.project | 2 +- src/Chainweb/Pact/TransactionExec.hs | 3 +-- test/Chainweb/Test/Pact/PactInProcApi.hs | 25 +++++++++++++++--------- 3 files changed, 18 insertions(+), 12 deletions(-) diff --git a/cabal.project b/cabal.project index 4804678bb9..9f445b82bc 100644 --- a/cabal.project +++ b/cabal.project @@ -54,7 +54,7 @@ package yet-another-logger source-repository-package type: git location: https://github.com/kadena-io/pact.git - tag: c07fa8a65f6c02acbf72ada94cb0b0a3741f6dc8 + tag: 512fa12b213dc27335e1cbbcca8f53989bdb42c6 source-repository-package type: git diff --git a/src/Chainweb/Pact/TransactionExec.hs b/src/Chainweb/Pact/TransactionExec.hs index 9bc2542d92..bc0759402b 100644 --- a/src/Chainweb/Pact/TransactionExec.hs +++ b/src/Chainweb/Pact/TransactionExec.hs @@ -268,7 +268,6 @@ applyGenesisCmd logger dbEnv spv cmd = , FlagDisableInlineMemCheck , FlagDisablePact43 , FlagDisablePact44 - , FlagPreserveNamespaceUpgrade ] } txst = TransactionState @@ -729,7 +728,7 @@ enablePact431 tc enablePact44 :: TxContext -> [ExecutionFlag] enablePact44 tc | chainweb216Pact After (ctxVersion tc) (ctxCurrentBlockHeight tc) = [] - | otherwise = [FlagDisablePact44, FlagPreserveNamespaceUpgrade] + | otherwise = [FlagDisablePact44] -- | Execute a 'ContMsg' and return the command result and module cache -- diff --git a/test/Chainweb/Test/Pact/PactInProcApi.hs b/test/Chainweb/Test/Pact/PactInProcApi.hs index 1c137e15a4..e463e94589 100644 --- a/test/Chainweb/Test/Pact/PactInProcApi.hs +++ b/test/Chainweb/Test/Pact/PactInProcApi.hs @@ -1017,8 +1017,8 @@ chainweb216Test bdb mpRefIO pact = do tx54_3 <- txResult "pwo54" 3 pwo54 assertEqual "Pass when defining a namespaced keyset post fork" - (Just "asdf") - (tx54_3 ^? crResult . to _pactResult . _Left . to peDoc) + (Just (PLiteral (LBool True))) + (tx54_3 ^? crResult . to _pactResult . _Right) tx54_4 <- txResult "pwo54" 4 pwo54 assertEqual "Should work in enforcing a namespaced keyset created prefork" @@ -1029,22 +1029,28 @@ chainweb216Test bdb mpRefIO pact = do assertEqual "Should work in enforcing a non-namespaced keyset created prefork" (Just (PLiteral (LBool True))) (tx54_5 ^? crResult . to _pactResult . _Right) + + tx54_6 <- txResult "pwo54" 6 pwo54 + assertEqual "Should fail in defining a keyset outside a namespace" + (Just "Cannot define keysets outside of a namespace") + (tx54_6 ^? crResult . to _pactResult . _Left . to peDoc) where runCut' = runCut testVersion bdb pact (offsetBlockTime second) zeroNoncer noMiner defineNonNamespacedPreFork = mconcat - [ "(namespace 'free)" - , "(define-keyset \'k123)" + [ "(define-keyset \'k123)" , "(enforce-guard (keyset-ref-guard \'k123))" ] defineNamespacedPreFork = mconcat - [ "(namespace 'free)" - , "(define-keyset \"free.k123\")" + [ "(define-keyset \"free.k123\")" , "(enforce-guard (keyset-ref-guard \"free.k123\"))" ] - defineNonNamespacedPostFork = mconcat + defineNonNamespacedPostFork1 = mconcat [ "(namespace 'free)" , "(define-keyset \'k456)" ] + defineNonNamespacedPostFork2 = mconcat + [ "(define-keyset \'k456)" + ] defineNamespacedPostFork = mconcat [ "(namespace 'free)" , "(define-keyset \"free.k456\")" @@ -1067,11 +1073,12 @@ chainweb216Test bdb mpRefIO pact = do mpaGetBlock = \_ _ _ _ bh -> if _blockChainId bh == cid then do t0 <- buildSimpleCmd bh formatGas t1 <- buildSimpleCmd bh tryGas - t2 <- buildSimpleCmd bh defineNonNamespacedPostFork + t2 <- buildSimpleCmd bh defineNonNamespacedPostFork1 t3 <- buildSimpleCmd bh defineNamespacedPostFork t4 <- buildSimpleCmd bh enforceNamespacedFromPreFork t5 <- buildSimpleCmd bh enforceNonNamespacedFromPreFork - return $! V.fromList [t0,t1,t2,t3,t4,t5] + t6 <- buildSimpleCmd bh defineNonNamespacedPostFork2 + return $! V.fromList [t0,t1,t2,t3,t4,t5, t6] else return mempty } buildSimpleCmd bh code = buildCwCmd From f3c7ec298f4c80bb524003ba0df62bb74f5a8c7d Mon Sep 17 00:00:00 2001 From: Jose Date: Fri, 12 Aug 2022 14:46:51 -0400 Subject: [PATCH 10/29] update pin with latest master --- cabal.project | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cabal.project b/cabal.project index 9f445b82bc..67745691de 100644 --- a/cabal.project +++ b/cabal.project @@ -54,7 +54,7 @@ package yet-another-logger source-repository-package type: git location: https://github.com/kadena-io/pact.git - tag: 512fa12b213dc27335e1cbbcca8f53989bdb42c6 + tag: 855caab10d24fb3ec622c25781165c64c7d72630 source-repository-package type: git From ab14aa93c5c75d91e55d1fc031dd5d09f9a8420f Mon Sep 17 00:00:00 2001 From: Edmund Noble Date: Mon, 15 Aug 2022 09:07:45 -0400 Subject: [PATCH 11/29] Remove now nonexistent flag --- pact/coin-contract/coin.repl | 4 ++-- pact/coin-contract/v3/coin-v3.repl | 2 +- pact/coin-contract/v4/coin-v4.repl | 4 ++-- pact/namespaces/ns.repl | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/pact/coin-contract/coin.repl b/pact/coin-contract/coin.repl index f3ca808d67..4f0ae2943f 100644 --- a/pact/coin-contract/coin.repl +++ b/pact/coin-contract/coin.repl @@ -1,5 +1,5 @@ ;; Enable the table gas model -(env-exec-config ["DisableInlineMemCheck", "DisablePact43", "DisablePact44", "PreserveNamespaceUpgrade"]) +(env-exec-config ["DisableInlineMemCheck", "DisablePact43", "DisablePact44"]) (env-gasmodel "table") (env-gaslimit 30000) @@ -521,7 +521,7 @@ "success")) ; make sure chain-id is enforced in the yield -(env-exec-config ['DisablePact40, 'DisableInlineMemCheck, 'DisablePact43, "DisablePact44", "PreserveNamespaceUpgrade"]) +(env-exec-config ['DisablePact40, 'DisableInlineMemCheck, 'DisablePact43, "DisablePact44"]) (expect-failure "create side of cross-chain transfer fails yield on wrong chain" "does not match (chain" diff --git a/pact/coin-contract/v3/coin-v3.repl b/pact/coin-contract/v3/coin-v3.repl index d90be81706..6470b44ca7 100644 --- a/pact/coin-contract/v3/coin-v3.repl +++ b/pact/coin-contract/v3/coin-v3.repl @@ -3,7 +3,7 @@ , "coin-load-gas": 3413 }) (load "../v2/coin.repl") -(env-exec-config ["DisablePact44", "PreserveNamespaceUpgrade"]) +(env-exec-config ["DisablePact44"]) ;; ====================================================== ;; test transfer, gas events diff --git a/pact/coin-contract/v4/coin-v4.repl b/pact/coin-contract/v4/coin-v4.repl index b413ef3a37..e96ba52d6f 100644 --- a/pact/coin-contract/v4/coin-v4.repl +++ b/pact/coin-contract/v4/coin-v4.repl @@ -1,5 +1,5 @@ ;; Enable the table gas model -(env-exec-config ["DisableInlineMemCheck", "DisablePact43", "DisablePact44", "PreserveNamespaceUpgrade"]) +(env-exec-config ["DisableInlineMemCheck", "DisablePact43", "DisablePact44"]) (env-gasmodel "table") (env-gaslimit 150000) @@ -12,7 +12,7 @@ 840 (env-gas)) (commit-tx) -(env-exec-config ["DisablePact44", "PreserveNamespaceUpgrade"]) +(env-exec-config ["DisablePact44"]) (env-gasmodel "table") (env-gas 0) (env-gaslog) (begin-tx) diff --git a/pact/namespaces/ns.repl b/pact/namespaces/ns.repl index 7bcb99b77f..bcf3d9499f 100644 --- a/pact/namespaces/ns.repl +++ b/pact/namespaces/ns.repl @@ -1,4 +1,4 @@ -(env-exec-config ["DisablePact44", "PreserveNamespaceUpgrade"]) +(env-exec-config ["DisablePact44"]) (begin-tx) (env-data { 'ns-admin-keyset: ["admin"] From 98d29e9046024b21cb440d771c3811287a4daee5 Mon Sep 17 00:00:00 2001 From: Emily Pillmore Date: Mon, 15 Aug 2022 15:09:35 -0600 Subject: [PATCH 12/29] initial rewrite --- pact/namespaces/v2/ns.pact | 112 +++++++++++++++++++++++++++++++++++++ pact/namespaces/v2/ns.repl | 87 ++++++++++++++++++++++++++++ 2 files changed, 199 insertions(+) create mode 100644 pact/namespaces/v2/ns.pact create mode 100644 pact/namespaces/v2/ns.repl diff --git a/pact/namespaces/v2/ns.pact b/pact/namespaces/v2/ns.pact new file mode 100644 index 0000000000..cf58ce7ec2 --- /dev/null +++ b/pact/namespaces/v2/ns.pact @@ -0,0 +1,112 @@ + +(define-keyset 'ns-admin-keyset (read-keyset 'ns-admin-keyset)) +(define-keyset 'ns-operate-keyset (read-keyset 'ns-genesis-keyset)) + +(module ns GOVERNANCE + "Administers definition of new namespaces in Chainweb." + + (defschema reg-entry + admin-guard:guard + active:bool) + + (deftable registry:{reg-entry}) + + (defcap GOVERNANCE () + (enforce-keyset 'ns-admin-keyset)) + + (defcap OPERATE () + (enforce-keyset 'ns-operate-keyset)) + + (defconst GUARD_SUCCESS (create-user-guard (success))) + (defconst GUARD_FAILURE (create-user-guard (failure))) + + (defun success () + true) + (defun failure () + (enforce false "Disabled")) + + (defun validate-name (name) + (enforce (!= "" name) "Empty name not allowed") + (enforce (< (length name) 64) "Name must be less than 64 characters long") + (enforce (is-charset CHARSET_LATIN1 name) + "Name must be in latin1 charset")) + + (defun validate:bool + ( ns-name:string + ns-admin:guard + ) + " Manages namespace install for Chainweb. Requires active row in registry \ + \ for NS-NAME with guard matching NS-ADMIN." + + (if (is-principal ns-name) + ( + (with-default-read registry ns-name + { 'admin-guard : ns-admin + , 'active : false } + { 'admin-guard := ag + , 'active := is-active } + + (enforce (validate-principal ns-admin ns-name) + "Invalid principal namespace namespace") + (enforce is-active "Inactive or unregistered namespace") + (enforce (= ns-admin ag) "Admin guard must match guard in registry") + + true)) + ( + (validate-name ns-name) + + (with-default-read registry (drop 2 ns-name) + { 'admin-guard : ns-admin + , 'active : false } + { 'admin-guard := ag + , 'active := is-active } + + (enforce is-active "Inactive or unregistered namespace") + (enforce (= ns-admin ag) "Admin guard must match guard in registry") + + true)))) + + (defun write-registry:string + ( ns-name:string + guard:guard + active:bool + ) + " Write entry with GUARD and ACTIVE into registry for NAME. \ + \ Guarded by operate keyset. " + + (with-capability (OPERATE) + + (if (is-principal) ns-name + ( + (write registry (drop 2 ns-name) + { 'admin-guard: guard + , 'active: active })) + ( + (validate-name ns-name) + (write registry ns-name + { 'admin-guard: guard + , 'active: active }))) + + "Register entry written")) + + (defun query:object{reg-entry} + ( ns-name:string ) + (read registry ns-name)) + + ) + +(create-table registry) + +(write-registry "kadena" + (keyset-ref-guard 'ns-operate-keyset) true) +(write-registry "user" GUARD_FAILURE true) +(write-registry "free" GUARD_FAILURE true) + +(define-namespace "kadena" + (keyset-ref-guard 'ns-operate-keyset) + (keyset-ref-guard 'ns-operate-keyset)) + +(define-namespace "user" GUARD_SUCCESS GUARD_FAILURE) +(define-namespace "free" GUARD_SUCCESS GUARD_FAILURE) +;;rotate to real operate keyset +(define-keyset 'ns-operate-keyset (read-keyset 'ns-operate-keyset)) diff --git a/pact/namespaces/v2/ns.repl b/pact/namespaces/v2/ns.repl new file mode 100644 index 0000000000..7bcb99b77f --- /dev/null +++ b/pact/namespaces/v2/ns.repl @@ -0,0 +1,87 @@ +(env-exec-config ["DisablePact44", "PreserveNamespaceUpgrade"]) +(begin-tx) +(env-data + { 'ns-admin-keyset: ["admin"] + , 'ns-operate-keyset: ["operate"] + , 'ns-genesis-keyset: { "keys": [], "pred": "="} }) + +(load "ns.pact") +(commit-tx) + +(env-namespace-policy false (ns.validate)) + +(begin-tx) +(namespace 'user) +(env-keys []) + +(module mod G + (defcap G () (enforce false "disabled")) + (defun foo () 1)) + +(namespace 'free) + +(module mod G + (defcap G () (enforce false "disabled")) + (defun foo () 2)) + +(expect-failure + "Cannot bring kadena ns into scope w/o operate admin" + (namespace 'kadena)) + +(env-keys ["operate"]) + +(namespace 'kadena) + +(module mod G + (defcap G () (enforce false "disabled")) + (defun foo () 3)) + +(commit-tx) + +(expect "user.mod works" 1 (user.mod.foo)) +(expect "free.mod works" 2 (free.mod.foo)) +(expect "kadena.mod works" 3 (kadena.mod.foo)) + +(begin-tx) +(env-keys ["operate"]) +(env-data + { 'ns-admin-keyset: ["admin"] + , 'ns-operate-keyset: ["operate"] }) + +(expect-failure "cannot redefine user" + (define-namespace 'user ns.GUARD_FAILURE ns.GUARD_FAILURE)) +(expect-failure "cannot redefine free" + (define-namespace 'free ns.GUARD_FAILURE ns.GUARD_FAILURE)) +(expect "can redefine kadena" + "Namespace defined: kadena" + (define-namespace 'kadena ns.GUARD_SUCCESS ns.GUARD_FAILURE)) + +(commit-tx) + +(begin-tx) +(env-keys []) + +(namespace 'kadena) + +(module mod2 G + (defcap G () (enforce false "disabled")) + (defun foo () 4)) +(commit-tx) + +(expect "kadena.mod2 works" 4 (kadena.mod2.foo)) + +(use ns) +(env-keys ["operate"]) +(expect-failure + "cannot register empty name" + (write-registry "" GUARD_SUCCESS true)) + +(expect-failure + "cannot register >64 length name" + (write-registry + "1234567890123456789012345678901234567890123456789012345678901234567890" + GUARD_SUCCESS true)) + +(expect-failure + "must be latin1 charset" + (write-registry "emilyπ" GUARD_SUCCESS true)) From 5736a63d323d03802c027583b50ec5664f722936 Mon Sep 17 00:00:00 2001 From: Emily Pillmore Date: Mon, 15 Aug 2022 16:04:55 -0600 Subject: [PATCH 13/29] remove unnecessary flag --- pact/namespaces/ns.repl | 2 +- pact/namespaces/v2/ns.repl | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pact/namespaces/ns.repl b/pact/namespaces/ns.repl index 7bcb99b77f..bcf3d9499f 100644 --- a/pact/namespaces/ns.repl +++ b/pact/namespaces/ns.repl @@ -1,4 +1,4 @@ -(env-exec-config ["DisablePact44", "PreserveNamespaceUpgrade"]) +(env-exec-config ["DisablePact44"]) (begin-tx) (env-data { 'ns-admin-keyset: ["admin"] diff --git a/pact/namespaces/v2/ns.repl b/pact/namespaces/v2/ns.repl index 7bcb99b77f..bcf3d9499f 100644 --- a/pact/namespaces/v2/ns.repl +++ b/pact/namespaces/v2/ns.repl @@ -1,4 +1,4 @@ -(env-exec-config ["DisablePact44", "PreserveNamespaceUpgrade"]) +(env-exec-config ["DisablePact44"]) (begin-tx) (env-data { 'ns-admin-keyset: ["admin"] From 1e502f053c602a10c00f2e163003c89b7c4af551 Mon Sep 17 00:00:00 2001 From: Jose Date: Tue, 16 Aug 2022 13:18:36 -0400 Subject: [PATCH 14/29] parser fixes --- cabal.project | 2 +- src/Chainweb/Pact/PactService/ExecBlock.hs | 15 ++++++++++----- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/cabal.project b/cabal.project index 67745691de..d69b226a30 100644 --- a/cabal.project +++ b/cabal.project @@ -54,7 +54,7 @@ package yet-another-logger source-repository-package type: git location: https://github.com/kadena-io/pact.git - tag: 855caab10d24fb3ec622c25781165c64c7d72630 + tag: ed3fb5e1294d93ab673b0b6a3899fd6711e3fe3f source-repository-package type: git diff --git a/src/Chainweb/Pact/PactService/ExecBlock.hs b/src/Chainweb/Pact/PactService/ExecBlock.hs index 9a3e1b1fd9..a8a39d823d 100644 --- a/src/Chainweb/Pact/PactService/ExecBlock.hs +++ b/src/Chainweb/Pact/PactService/ExecBlock.hs @@ -60,7 +60,7 @@ import qualified Pact.Interpreter as P import qualified Pact.Parse as P import qualified Pact.Types.Command as P import Pact.Types.Exp (ParsedCode(..)) -import Pact.Types.ExpParser (mkTextInfo) +import Pact.Types.ExpParser (mkTextInfo, ParseEnv(..)) import qualified Pact.Types.Hash as P import qualified Pact.Types.Logger as P import Pact.Types.RPC @@ -219,7 +219,7 @@ validateChainwebTxs logger v cid cp txValidationTime bh txs doBuyGas >>= runValid checkTxHash >>= runValid checkTxSigs >>= runValid checkTimes - >>= runValid (return . checkCompile) + >>= runValid (return . checkCompile v bh) checkUnique :: ChainwebTransaction -> IO (Either InsertError ChainwebTransaction) checkUnique t = do @@ -280,8 +280,12 @@ validateChainwebTxs logger v cid cp txValidationTime bh txs doBuyGas type ValidateTxs = Vector (Either InsertError ChainwebTransaction) type RunGas = ValidateTxs -> IO ValidateTxs -checkCompile :: ChainwebTransaction -> Either InsertError ChainwebTransaction -checkCompile tx = case payload of +checkCompile + :: ChainwebVersion + -> BlockHeight + -> ChainwebTransaction + -> Either InsertError ChainwebTransaction +checkCompile v bh tx = case payload of Exec (ExecMsg parsedCode _) -> case compileCode parsedCode of Left perr -> Left $ InsertErrorCompilationFailed (sshow perr) @@ -290,7 +294,8 @@ checkCompile tx = case payload of where payload = P._pPayload $ payloadObj $ P._cmdPayload tx compileCode p = - compileExps (mkTextInfo (P._pcCode p)) (P._pcExps p) + let e = ParseEnv (chainweb216Pact After v bh) + in compileExps e (mkTextInfo (P._pcCode p)) (P._pcExps p) skipDebitGas :: RunGas skipDebitGas = return From 463c780a5197b42f96fc648e84dfc387142cf548 Mon Sep 17 00:00:00 2001 From: Emily Pillmore Date: Tue, 16 Aug 2022 17:06:41 -0600 Subject: [PATCH 15/29] kludgy first implementation --- pact/namespaces/v2/ns.pact | 73 ++++++++++++++++++++++---------------- 1 file changed, 43 insertions(+), 30 deletions(-) diff --git a/pact/namespaces/v2/ns.pact b/pact/namespaces/v2/ns.pact index cf58ce7ec2..976ba8b54e 100644 --- a/pact/namespaces/v2/ns.pact +++ b/pact/namespaces/v2/ns.pact @@ -38,33 +38,37 @@ " Manages namespace install for Chainweb. Requires active row in registry \ \ for NS-NAME with guard matching NS-ADMIN." - (if (is-principal ns-name) - ( - (with-default-read registry ns-name + (let + ((parse-name + (lambda (n) + (let + ((first-two (take 2 n))) + + (cond + ((= "k#" first-two) + (+ "k:" (drop 2 n))) + ((= "w#" first-two) + (+ "w:" (+ (take 43 (drop 2 n)) (+ ":" (drop 46 n))))) + n)))) + + (name-validation + (lambda (n) + (if (is-principal n) + (validate-principal ns-admin n) + (validate-name n))))) + + (with-default-read registry ns-name { 'admin-guard : ns-admin , 'active : false } { 'admin-guard := ag , 'active := is-active } - (enforce (validate-principal ns-admin ns-name) - "Invalid principal namespace namespace") + (name-validation (parse-name ns-name)) (enforce is-active "Inactive or unregistered namespace") (enforce (= ns-admin ag) "Admin guard must match guard in registry") - true)) - ( - (validate-name ns-name) - - (with-default-read registry (drop 2 ns-name) - { 'admin-guard : ns-admin - , 'active : false } - { 'admin-guard := ag - , 'active := is-active } - - (enforce is-active "Inactive or unregistered namespace") - (enforce (= ns-admin ag) "Admin guard must match guard in registry") - - true)))) + true) + )) (defun write-registry:string ( ns-name:string @@ -74,20 +78,29 @@ " Write entry with GUARD and ACTIVE into registry for NAME. \ \ Guarded by operate keyset. " - (with-capability (OPERATE) - - (if (is-principal) ns-name - ( - (write registry (drop 2 ns-name) - { 'admin-guard: guard - , 'active: active })) - ( - (validate-name ns-name) + (if (is-principal ns-name) + (let + ((parsed-name + (cond + ((= "k:" (drop 2 ns-name)) + (+ "k#" (drop 2 ns-name))) + ((= "w:" (drop 2 ns-name)) + (+ "w#" (+ (take 43 (drop 2 ns-name)) (+ "#" (drop 46 ns-name))))) + "unsupported"))) + + (enforce (= "unsupported" parsed-name) + "Unsupported guard protocol") + + (write registry parsed-name + { 'admin-guard: guard + , 'active: active })) + + (with-capability (OPERATE) (write registry ns-name - { 'admin-guard: guard + { 'admin-guard : guard , 'active: active }))) - "Register entry written")) + "Register entry written") (defun query:object{reg-entry} ( ns-name:string ) From a0e104fae1b459bf6c548518f97d4b413b21ebc5 Mon Sep 17 00:00:00 2001 From: Emily Pillmore Date: Wed, 17 Aug 2022 12:31:52 -0600 Subject: [PATCH 16/29] WIP repl tests --- pact/namespaces/v2/ns.pact | 42 ++++++++++++++--------- pact/namespaces/v2/ns.repl | 70 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 95 insertions(+), 17 deletions(-) diff --git a/pact/namespaces/v2/ns.pact b/pact/namespaces/v2/ns.pact index 976ba8b54e..0f8557c48a 100644 --- a/pact/namespaces/v2/ns.pact +++ b/pact/namespaces/v2/ns.pact @@ -38,32 +38,35 @@ " Manages namespace install for Chainweb. Requires active row in registry \ \ for NS-NAME with guard matching NS-ADMIN." - (let + (let* ((parse-name (lambda (n) (let - ((first-two (take 2 n))) + ((take-two (take 2 n)) + (drop-two (drop 2 n))) (cond - ((= "k#" first-two) - (+ "k:" (drop 2 n))) - ((= "w#" first-two) - (+ "w:" (+ (take 43 (drop 2 n)) (+ ":" (drop 46 n))))) + ((= "k#" take-two) + (+ "k:" drop-two)) + ((= "w#" take-two) + (+ "w:" (+ (take 43 drop-two) (+ ":" (drop 46 n))))) n)))) (name-validation (lambda (n) (if (is-principal n) (validate-principal ns-admin n) - (validate-name n))))) + (validate-name n)))) - (with-default-read registry ns-name + (parsed-name (parse-name ns-name))) + + (with-default-read registry parsed-name { 'admin-guard : ns-admin , 'active : false } { 'admin-guard := ag , 'active := is-active } - (name-validation (parse-name ns-name)) + (name-validation parsed-name) (enforce is-active "Inactive or unregistered namespace") (enforce (= ns-admin ag) "Admin guard must match guard in registry") @@ -79,23 +82,28 @@ \ Guarded by operate keyset. " (if (is-principal ns-name) - (let - ((parsed-name + (let* + ((drop-two (drop 2 ns-name)) + (take-two (take 2 ns-name)) + + (parsed-name (cond - ((= "k:" (drop 2 ns-name)) - (+ "k#" (drop 2 ns-name))) - ((= "w:" (drop 2 ns-name)) - (+ "w#" (+ (take 43 (drop 2 ns-name)) (+ "#" (drop 46 ns-name))))) + ((= "k:" take-two) + (+ "k#" drop-two)) + ((= "w:" take-two) + (+ "w#" (+ (take 43 drop-two) (+ "#" (drop 44 drop-two))))) "unsupported"))) - (enforce (= "unsupported" parsed-name) - "Unsupported guard protocol") + (enforce (not (= "unsupported" parsed-name)) + "Unsupported principal guard protocol") (write registry parsed-name { 'admin-guard: guard , 'active: active })) (with-capability (OPERATE) + (validate-name ns-name) + (write registry ns-name { 'admin-guard : guard , 'active: active }))) diff --git a/pact/namespaces/v2/ns.repl b/pact/namespaces/v2/ns.repl index bcf3d9499f..31efb0983f 100644 --- a/pact/namespaces/v2/ns.repl +++ b/pact/namespaces/v2/ns.repl @@ -67,6 +67,7 @@ (defcap G () (enforce false "disabled")) (defun foo () 4)) (commit-tx) +(begin-tx) (expect "kadena.mod2 works" 4 (kadena.mod2.foo)) @@ -85,3 +86,72 @@ (expect-failure "must be latin1 charset" (write-registry "emilyπ" GUARD_SUCCESS true)) + +(commit-tx) +(begin-tx) + +(env-exec-config []) +(env-data + { "70c787fcfe6c6f4ec23d13c2e94682bc90952f7cec06c7dbac1c012b0b6678b9" : + ["70c787fcfe6c6f4ec23d13c2e94682bc90952f7cec06c7dbac1c012b0b6678b9"] + , 'multi : ["a", "b"] + , 'ns-operate-keyset: ["operate"] + , 'ns-genesis-keyset: { "keys": [], "pred": "="} + , 'ns-admin-keyset: ["admin"] + }) + +(expect + "Principal namespace creation for k: accounts succeeds" + "Register entry written" + (ns.write-registry + (create-principal + (read-keyset "70c787fcfe6c6f4ec23d13c2e94682bc90952f7cec06c7dbac1c012b0b6678b9")) + (read-keyset "70c787fcfe6c6f4ec23d13c2e94682bc90952f7cec06c7dbac1c012b0b6678b9") + true)) + +(expect + "Principal namespace creation for w: accounts succeeds" + "Register entry written" + (ns.write-registry + (create-principal (read-keyset 'multi)) + (read-keyset 'multi) + true)) + +(commit-tx) +(begin-tx) + +; write k: principal to registry +(ns.write-registry + (create-principal + (read-keyset "70c787fcfe6c6f4ec23d13c2e94682bc90952f7cec06c7dbac1c012b0b6678b9")) + (read-keyset "70c787fcfe6c6f4ec23d13c2e94682bc90952f7cec06c7dbac1c012b0b6678b9") + true) + +; write w: principal to registry +(ns.write-registry + (create-principal (read-keyset 'multi)) + (read-keyset 'multi) + true) + +(namespace "k#70c787fcfe6c6f4ec23d13c2e94682bc90952f7cec06c7dbac1c012b0b6678b9") +(module modK G + (defcap G () true) + (defun f () 1)) + +(namespace "w#9lped_9eJpCtMWt7n8KN2QzFyaN-YXrD7uFAPePPmlU#keys-all") +(module modW G + (defcap G () true) + (defun f () 2)) + +(commit-tx) +(begin-tx) + +(expect + "k: principal namespaces work" + 1 + (k#70c787fcfe6c6f4ec23d13c2e94682bc90952f7cec06c7dbac1c012b0b6678b9.modK.f)) + +(expect + "w: principal namespaces work" + 2 + (w#9lped_9eJpCtMWt7n8KN2QzFyaN-YXrD7uFAPePPmlU#keys-all.modW.f)) From 0deff95e1f14042cf04e63f78940ac568a64c67b Mon Sep 17 00:00:00 2001 From: Emily Pillmore Date: Wed, 17 Aug 2022 13:07:52 -0600 Subject: [PATCH 17/29] Add initial coverage, get code working --- pact/namespaces/v2/ns.pact | 5 ++++- pact/namespaces/v2/ns.repl | 25 ++++++++++++++++++++----- 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/pact/namespaces/v2/ns.pact b/pact/namespaces/v2/ns.pact index 0f8557c48a..e04541d9c4 100644 --- a/pact/namespaces/v2/ns.pact +++ b/pact/namespaces/v2/ns.pact @@ -60,7 +60,7 @@ (parsed-name (parse-name ns-name))) - (with-default-read registry parsed-name + (with-default-read registry ns-name { 'admin-guard : ns-admin , 'active : false } { 'admin-guard := ag @@ -97,6 +97,9 @@ (enforce (not (= "unsupported" parsed-name)) "Unsupported principal guard protocol") + (enforce (validate-principal guard ns-name) + "Invalid principal namespace protocol") + (write registry parsed-name { 'admin-guard: guard , 'active: active })) diff --git a/pact/namespaces/v2/ns.repl b/pact/namespaces/v2/ns.repl index 31efb0983f..72dc6660f7 100644 --- a/pact/namespaces/v2/ns.repl +++ b/pact/namespaces/v2/ns.repl @@ -96,8 +96,6 @@ ["70c787fcfe6c6f4ec23d13c2e94682bc90952f7cec06c7dbac1c012b0b6678b9"] , 'multi : ["a", "b"] , 'ns-operate-keyset: ["operate"] - , 'ns-genesis-keyset: { "keys": [], "pred": "="} - , 'ns-admin-keyset: ["admin"] }) (expect @@ -117,9 +115,6 @@ (read-keyset 'multi) true)) -(commit-tx) -(begin-tx) - ; write k: principal to registry (ns.write-registry (create-principal @@ -133,6 +128,26 @@ (read-keyset 'multi) true) +(define-namespace + "k#70c787fcfe6c6f4ec23d13c2e94682bc90952f7cec06c7dbac1c012b0b6678b9" + (read-keyset "70c787fcfe6c6f4ec23d13c2e94682bc90952f7cec06c7dbac1c012b0b6678b9") + (read-keyset "70c787fcfe6c6f4ec23d13c2e94682bc90952f7cec06c7dbac1c012b0b6678b9")) + +(define-namespace + "w#9lped_9eJpCtMWt7n8KN2QzFyaN-YXrD7uFAPePPmlU#keys-all" + (read-keyset 'multi) + (read-keyset 'multi)) + +(commit-tx) +(begin-tx) + +(env-keys + [ "70c787fcfe6c6f4ec23d13c2e94682bc90952f7cec06c7dbac1c012b0b6678b9" + , "a" + , "b" + ] + ) + (namespace "k#70c787fcfe6c6f4ec23d13c2e94682bc90952f7cec06c7dbac1c012b0b6678b9") (module modK G (defcap G () true) From 405d35a5b5a45be0195de64486c9112d837f04da Mon Sep 17 00:00:00 2001 From: Jose Date: Wed, 17 Aug 2022 15:09:54 -0400 Subject: [PATCH 18/29] latest pact master --- cabal.project | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cabal.project b/cabal.project index d69b226a30..b12ff54625 100644 --- a/cabal.project +++ b/cabal.project @@ -54,7 +54,7 @@ package yet-another-logger source-repository-package type: git location: https://github.com/kadena-io/pact.git - tag: ed3fb5e1294d93ab673b0b6a3899fd6711e3fe3f + tag: 14dc73ee4b547be0361b666a7e51c0fee3463cd9 source-repository-package type: git From 6688d46f96cb5ec6c3d35eaf200c2ed1da93e1c0 Mon Sep 17 00:00:00 2001 From: Emily Pillmore Date: Wed, 17 Aug 2022 13:10:32 -0600 Subject: [PATCH 19/29] bless old contract --- pact/namespaces/v2/ns.pact | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pact/namespaces/v2/ns.pact b/pact/namespaces/v2/ns.pact index e04541d9c4..5ee71a17c3 100644 --- a/pact/namespaces/v2/ns.pact +++ b/pact/namespaces/v2/ns.pact @@ -5,6 +5,9 @@ (module ns GOVERNANCE "Administers definition of new namespaces in Chainweb." + ;; namespace v1 contract + (bless "AF2zCIWu31ATlsHOBrrhSramOa6iEO06kCbQGZmxCww") + (defschema reg-entry admin-guard:guard active:bool) From 7d96a95ce42bbcb73b7face4cfc4b202887cc86e Mon Sep 17 00:00:00 2001 From: Emily Pillmore Date: Wed, 17 Aug 2022 13:22:54 -0600 Subject: [PATCH 20/29] add ns-v2.yaml --- pact/namespaces/v2/ns-v2.yaml | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 pact/namespaces/v2/ns-v2.yaml diff --git a/pact/namespaces/v2/ns-v2.yaml b/pact/namespaces/v2/ns-v2.yaml new file mode 100644 index 0000000000..a4c54b4210 --- /dev/null +++ b/pact/namespaces/v2/ns-v2.yaml @@ -0,0 +1,9 @@ +codeFile: ns.pact +data: + ns-admin-keyset: ["368820f80c324bbc7c2b0610688a7da43e39f91d118732671cd9c7500ff43cca"] + ns-operate-keyset: ["368820f80c324bbc7c2b0610688a7da43e39f91d118732671cd9c7500ff43cca"] + ns-genesis-keyset: + keys: [] + pred: "=" +nonce: load-ns-v2-mainnet +keyPairs: [] From e980f22add016e2183ca398eee82d6b85a0cca9d Mon Sep 17 00:00:00 2001 From: Emily Pillmore Date: Fri, 19 Aug 2022 12:17:47 -0600 Subject: [PATCH 21/29] hook up repl tests to pact tests for ns (v1 and v2) --- pact/namespaces/v2/ns.repl | 14 ++++++++++++-- test/Chainweb/Test/Pact/TransactionTests.hs | 11 ++++++++++- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/pact/namespaces/v2/ns.repl b/pact/namespaces/v2/ns.repl index 72dc6660f7..b2cd6642f7 100644 --- a/pact/namespaces/v2/ns.repl +++ b/pact/namespaces/v2/ns.repl @@ -95,7 +95,6 @@ { "70c787fcfe6c6f4ec23d13c2e94682bc90952f7cec06c7dbac1c012b0b6678b9" : ["70c787fcfe6c6f4ec23d13c2e94682bc90952f7cec06c7dbac1c012b0b6678b9"] , 'multi : ["a", "b"] - , 'ns-operate-keyset: ["operate"] }) (expect @@ -138,9 +137,20 @@ (read-keyset 'multi) (read-keyset 'multi)) +;; only testing control flow here. +(env-exec-config ['DisablePact44]) +(define-keyset 'multi) +(expect-failure + "Non-k or w principals cannot create namespaces" + "Unsupported" + (ns.write-registry + (create-principal (keyset-ref-guard 'multi)) + (read-keyset 'multi) + true)) + (commit-tx) (begin-tx) - +(env-exec-config []) (env-keys [ "70c787fcfe6c6f4ec23d13c2e94682bc90952f7cec06c7dbac1c012b0b6678b9" , "a" diff --git a/test/Chainweb/Test/Pact/TransactionTests.hs b/test/Chainweb/Test/Pact/TransactionTests.hs index c9099998bd..7eb1410eb9 100644 --- a/test/Chainweb/Test/Pact/TransactionTests.hs +++ b/test/Chainweb/Test/Pact/TransactionTests.hs @@ -79,6 +79,12 @@ coinReplV4 = "pact/coin-contract/v4/coin-v4.repl" coinReplV5 :: FilePath coinReplV5 = "pact/coin-contract/v5/coin-v5.repl" +nsReplV1 :: FilePath +nsReplV1 = "pact/namespaces/ns.repl" + +nsReplV2 :: FilePath +nsReplV2 = "pact/namespaces/v2/ns.repl" + logger :: Logger #if DEBUG_TEST logger = newLogger alwaysLog "" @@ -102,7 +108,10 @@ tests = testGroup "Chainweb.Test.Pact.TransactionTests" , testCase "v4" (ccReplTests coinReplV4) , testCase "v5" (ccReplTests coinReplV5) ] - , testCase "Ns Repl Tests" (ccReplTests "pact/namespaces/ns.repl") + , testGroup "Namespace repl unit tests" + [ testCase "Ns v1 repl tests" $ ccReplTests nsReplV1 + , testCase "Ns v2 repl tests" $ ccReplTests nsReplV2 + ] , testCase "Payer Repl Tests" (ccReplTests "pact/gas-payer/gas-payer-v1.repl") ] , testGroup "Precompiled Statements Tests" From eccced7fd56d2228a356d0e3b7f4987683dfa56d Mon Sep 17 00:00:00 2001 From: Emily Pillmore Date: Fri, 19 Aug 2022 12:20:59 -0600 Subject: [PATCH 22/29] undo checkpointer change --- test/Chainweb/Test/Pact/Checkpointer.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Chainweb/Test/Pact/Checkpointer.hs b/test/Chainweb/Test/Pact/Checkpointer.hs index a7f65451e8..016a8dd45a 100644 --- a/test/Chainweb/Test/Pact/Checkpointer.hs +++ b/test/Chainweb/Test/Pact/Checkpointer.hs @@ -614,7 +614,7 @@ runExec cp (PactDbEnv' pactdbenv) eData eCode = do where h' = H.toUntypedHash (H.hash "" :: H.PactHash) cmdenv = TransactionEnv Transactional pactdbenv (_cpeLogger cp) def - noSPVSupport Nothing 0.0 (RequestKey h') 0 (mkExecutionConfig [FlagDisablePact44]) + noSPVSupport Nothing 0.0 (RequestKey h') 0 def cmdst = TransactionState mempty mempty 0 Nothing (_geGasModel freeGasEnv) runCont :: CheckpointEnv -> PactDbEnv' -> PactId -> Int -> IO EvalResult From 6547c576cb919c1d8ea810a2f79287b11fbd5209 Mon Sep 17 00:00:00 2001 From: Emily Pillmore Date: Fri, 19 Aug 2022 15:14:30 -0600 Subject: [PATCH 23/29] move stale logic out of contract defn --- pact/namespaces/v2/ns.pact | 22 +--------------------- pact/namespaces/v2/ns.repl | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 21 deletions(-) diff --git a/pact/namespaces/v2/ns.pact b/pact/namespaces/v2/ns.pact index 5ee71a17c3..61b84c15d6 100644 --- a/pact/namespaces/v2/ns.pact +++ b/pact/namespaces/v2/ns.pact @@ -1,7 +1,3 @@ - -(define-keyset 'ns-admin-keyset (read-keyset 'ns-admin-keyset)) -(define-keyset 'ns-operate-keyset (read-keyset 'ns-genesis-keyset)) - (module ns GOVERNANCE "Administers definition of new namespaces in Chainweb." @@ -120,20 +116,4 @@ ( ns-name:string ) (read registry ns-name)) - ) - -(create-table registry) - -(write-registry "kadena" - (keyset-ref-guard 'ns-operate-keyset) true) -(write-registry "user" GUARD_FAILURE true) -(write-registry "free" GUARD_FAILURE true) - -(define-namespace "kadena" - (keyset-ref-guard 'ns-operate-keyset) - (keyset-ref-guard 'ns-operate-keyset)) - -(define-namespace "user" GUARD_SUCCESS GUARD_FAILURE) -(define-namespace "free" GUARD_SUCCESS GUARD_FAILURE) -;;rotate to real operate keyset -(define-keyset 'ns-operate-keyset (read-keyset 'ns-operate-keyset)) +) diff --git a/pact/namespaces/v2/ns.repl b/pact/namespaces/v2/ns.repl index b2cd6642f7..72fa6c13a4 100644 --- a/pact/namespaces/v2/ns.repl +++ b/pact/namespaces/v2/ns.repl @@ -5,7 +5,26 @@ , 'ns-operate-keyset: ["operate"] , 'ns-genesis-keyset: { "keys": [], "pred": "="} }) + +(define-keyset 'ns-admin-keyset (read-keyset 'ns-admin-keyset)) +(define-keyset 'ns-operate-keyset (read-keyset 'ns-genesis-keyset)) + (load "ns.pact") +(create-table registry) + +(write-registry "kadena" + (keyset-ref-guard 'ns-operate-keyset) true) +(write-registry "user" GUARD_FAILURE true) +(write-registry "free" GUARD_FAILURE true) + +(define-namespace "kadena" + (keyset-ref-guard 'ns-operate-keyset) + (keyset-ref-guard 'ns-operate-keyset)) + +(define-namespace "user" GUARD_SUCCESS GUARD_FAILURE) +(define-namespace "free" GUARD_SUCCESS GUARD_FAILURE) +;;rotate to real operate keyset +(define-keyset 'ns-operate-keyset (read-keyset 'ns-operate-keyset)) (commit-tx) (env-namespace-policy false (ns.validate)) From b8367251673ce13a1393fa1b51ecf8c49c588bb6 Mon Sep 17 00:00:00 2001 From: Stuart Popejoy <8353613+sirlensalot@users.noreply.github.com> Date: Tue, 20 Sep 2022 20:49:47 -0400 Subject: [PATCH 24/29] Principal namespaces: use hashes, rework upgrade methodology (#1534) * slp: move files around for better diff, get gas payer working * don't use registry for principal namespaces * remove dupe validate * fix mainnet genesis yaml * use previous install in repl * move to hashes of principals * prefix namespaces with "n" * move to 160 bit hex namespaces * use "n_" prefix * update comment Co-authored-by: Stuart Popejoy --- pact/gas-payer/gas-payer-v1.repl | 1 + pact/genesis/mainnet/ns.yaml | 2 +- pact/genesis/ns.yaml | 2 +- pact/namespaces/ns.pact | 51 +++-- pact/namespaces/ns.repl | 92 +++++++++ pact/namespaces/v1/ns.pact | 92 +++++++++ pact/namespaces/v1/ns.repl | 87 +++++++++ pact/namespaces/v2/ns-v2.yaml | 9 - pact/namespaces/v2/ns.pact | 119 ------------ pact/namespaces/v2/ns.repl | 201 -------------------- pact/namespaces/yaml/ns-v2.yaml | 5 + test/Chainweb/Test/Pact/TransactionTests.hs | 8 +- 12 files changed, 305 insertions(+), 364 deletions(-) create mode 100644 pact/namespaces/v1/ns.pact create mode 100644 pact/namespaces/v1/ns.repl delete mode 100644 pact/namespaces/v2/ns-v2.yaml delete mode 100644 pact/namespaces/v2/ns.pact delete mode 100644 pact/namespaces/v2/ns.repl create mode 100644 pact/namespaces/yaml/ns-v2.yaml diff --git a/pact/gas-payer/gas-payer-v1.repl b/pact/gas-payer/gas-payer-v1.repl index e243dbd2d6..e29a39da83 100644 --- a/pact/gas-payer/gas-payer-v1.repl +++ b/pact/gas-payer/gas-payer-v1.repl @@ -7,6 +7,7 @@ (env-data {'gas-payer-operate: ["operate"]}) (env-keys ["operate"]) +(env-exec-config ['DisablePact44]) (load "gas-payer-v1-reference.pact") (verify "user.gas-payer-v1-reference") diff --git a/pact/genesis/mainnet/ns.yaml b/pact/genesis/mainnet/ns.yaml index 37f71447ee..c5300c441d 100644 --- a/pact/genesis/mainnet/ns.yaml +++ b/pact/genesis/mainnet/ns.yaml @@ -1,4 +1,4 @@ -codeFile: ../../namespaces/ns.pact +codeFile: ../../namespaces/v1/ns.pact data: ns-admin-keyset: keys: diff --git a/pact/genesis/ns.yaml b/pact/genesis/ns.yaml index 6df5ac0572..ba9e527895 100644 --- a/pact/genesis/ns.yaml +++ b/pact/genesis/ns.yaml @@ -1,4 +1,4 @@ -codeFile: ../namespaces/ns.pact +codeFile: ../namespaces/v1/ns.pact data: ns-admin-keyset: ["368820f80c324bbc7c2b0610688a7da43e39f91d118732671cd9c7500ff43cca"] ns-operate-keyset: ["368820f80c324bbc7c2b0610688a7da43e39f91d118732671cd9c7500ff43cca"] diff --git a/pact/namespaces/ns.pact b/pact/namespaces/ns.pact index ac61e95090..141cd814f1 100644 --- a/pact/namespaces/ns.pact +++ b/pact/namespaces/ns.pact @@ -1,7 +1,3 @@ - -(define-keyset 'ns-admin-keyset (read-keyset 'ns-admin-keyset)) -(define-keyset 'ns-operate-keyset (read-keyset 'ns-genesis-keyset)) - (module ns GOVERNANCE "Administers definition of new namespaces in Chainweb." @@ -31,25 +27,38 @@ (enforce (is-charset CHARSET_LATIN1 name) "Name must be in latin1 charset")) + (defun create-principal-namespace:string + ( g:guard + ) + " Format principal namespace as Pact hash (BLAKE2b256) of principal \ + \ in hex truncated to 160 bits (40 characters), prepended with 'n_'. " + (+ "n_" (take 40 (int-to-str 16 (str-to-int 64 (hash g))))) + ) + (defun validate:bool ( ns-name:string ns-admin:guard ) - " Manages namespace install for Chainweb. Requires active row in registry \ + " Manages namespace install for Chainweb. \ + \ Allows principal namespaces. \ + \ Non-principal namespaces require active row in registry \ \ for NS-NAME with guard matching NS-ADMIN." - (validate-name ns-name) + (if (= (create-principal-namespace ns-admin) ns-name) + + true ;; allow principal namespaces - (with-default-read registry ns-name - { 'admin-guard : ns-admin - , 'active : false } - { 'admin-guard := ag - , 'active := is-active } + (with-default-read registry ns-name ;; otherwise enforce registry + { 'admin-guard : ns-admin + , 'active : false } + { 'admin-guard := ag + , 'active := is-active } (enforce is-active "Inactive or unregistered namespace") (enforce (= ns-admin ag) "Admin guard must match guard in registry") - true)) + true) + )) (defun write-registry:string ( ns-name:string @@ -73,20 +82,4 @@ ( ns-name:string ) (read registry ns-name)) - ) - -(create-table registry) - -(write-registry "kadena" - (keyset-ref-guard 'ns-operate-keyset) true) -(write-registry "user" GUARD_FAILURE true) -(write-registry "free" GUARD_FAILURE true) - -(define-namespace "kadena" - (keyset-ref-guard 'ns-operate-keyset) - (keyset-ref-guard 'ns-operate-keyset)) - -(define-namespace "user" GUARD_SUCCESS GUARD_FAILURE) -(define-namespace "free" GUARD_SUCCESS GUARD_FAILURE) -;;rotate to real operate keyset -(define-keyset 'ns-operate-keyset (read-keyset 'ns-operate-keyset)) +) diff --git a/pact/namespaces/ns.repl b/pact/namespaces/ns.repl index bcf3d9499f..0630583e1d 100644 --- a/pact/namespaces/ns.repl +++ b/pact/namespaces/ns.repl @@ -5,6 +5,7 @@ , 'ns-operate-keyset: ["operate"] , 'ns-genesis-keyset: { "keys": [], "pred": "="} }) +(load "v1/ns.pact") (load "ns.pact") (commit-tx) @@ -67,6 +68,7 @@ (defcap G () (enforce false "disabled")) (defun foo () 4)) (commit-tx) +(begin-tx) (expect "kadena.mod2 works" 4 (kadena.mod2.foo)) @@ -85,3 +87,93 @@ (expect-failure "must be latin1 charset" (write-registry "emilyπ" GUARD_SUCCESS true)) + +(commit-tx) +(begin-tx) + +(env-exec-config []) +(env-data + { 'single : + ["70c787fcfe6c6f4ec23d13c2e94682bc90952f7cec06c7dbac1c012b0b6678b9"] + , 'multi : ["a", "b"] + }) + +(expect + "single principal ns" + "n_c1a583206e24450af26de41110042b019695db8c" + (ns.create-principal-namespace (read-keyset 'single))) + +(expect + "multi principal ns" + "n_64bfdef1c668b167c87f7cf329454c572e284664" + (ns.create-principal-namespace (read-keyset 'multi))) + +(expect-failure + "Principal of other than admin keyset fails" + "Inactive or unregistered namespace" + (define-namespace + "n_c1a583206e24450af26de41110042b019695db8c" + (read-keyset 'single) + (read-keyset 'multi)) +) + +(define-namespace + "n_c1a583206e24450af26de41110042b019695db8c" + (read-keyset 'single) + (read-keyset 'single)) + +(define-namespace + "n_64bfdef1c668b167c87f7cf329454c572e284664" + (read-keyset 'multi) + (read-keyset 'multi)) + +(commit-tx) + +(begin-tx "test rotation") +(env-keys + [ "70c787fcfe6c6f4ec23d13c2e94682bc90952f7cec06c7dbac1c012b0b6678b9" ]) +;; rotate to multi/multi +(define-namespace + "n_c1a583206e24450af26de41110042b019695db8c" + (read-keyset 'multi) + (read-keyset 'multi)) +;; rotate to multi/single +(env-keys ["a","b"]) +(define-namespace + "n_c1a583206e24450af26de41110042b019695db8c" + (read-keyset 'multi) + (read-keyset 'single)) +(rollback-tx) + + +(begin-tx) +(env-exec-config []) +(env-keys + [ "70c787fcfe6c6f4ec23d13c2e94682bc90952f7cec06c7dbac1c012b0b6678b9" + , "a" + , "b" + ] + ) + +(namespace "n_c1a583206e24450af26de41110042b019695db8c") +(module modK G + (defcap G () true) + (defun f () 1)) + +(namespace "n_64bfdef1c668b167c87f7cf329454c572e284664") +(module modW G + (defcap G () true) + (defun f () 2)) + +(commit-tx) +(begin-tx) + +(expect + "k: principal namespaces work" + 1 + (n_c1a583206e24450af26de41110042b019695db8c.modK.f)) + +(expect + "w: principal namespaces work" + 2 + (n_64bfdef1c668b167c87f7cf329454c572e284664.modW.f)) diff --git a/pact/namespaces/v1/ns.pact b/pact/namespaces/v1/ns.pact new file mode 100644 index 0000000000..ac61e95090 --- /dev/null +++ b/pact/namespaces/v1/ns.pact @@ -0,0 +1,92 @@ + +(define-keyset 'ns-admin-keyset (read-keyset 'ns-admin-keyset)) +(define-keyset 'ns-operate-keyset (read-keyset 'ns-genesis-keyset)) + +(module ns GOVERNANCE + "Administers definition of new namespaces in Chainweb." + + (defschema reg-entry + admin-guard:guard + active:bool) + + (deftable registry:{reg-entry}) + + (defcap GOVERNANCE () + (enforce-keyset 'ns-admin-keyset)) + + (defcap OPERATE () + (enforce-keyset 'ns-operate-keyset)) + + (defconst GUARD_SUCCESS (create-user-guard (success))) + (defconst GUARD_FAILURE (create-user-guard (failure))) + + (defun success () + true) + (defun failure () + (enforce false "Disabled")) + + (defun validate-name (name) + (enforce (!= "" name) "Empty name not allowed") + (enforce (< (length name) 64) "Name must be less than 64 characters long") + (enforce (is-charset CHARSET_LATIN1 name) + "Name must be in latin1 charset")) + + (defun validate:bool + ( ns-name:string + ns-admin:guard + ) + " Manages namespace install for Chainweb. Requires active row in registry \ + \ for NS-NAME with guard matching NS-ADMIN." + + (validate-name ns-name) + + (with-default-read registry ns-name + { 'admin-guard : ns-admin + , 'active : false } + { 'admin-guard := ag + , 'active := is-active } + + (enforce is-active "Inactive or unregistered namespace") + (enforce (= ns-admin ag) "Admin guard must match guard in registry") + + true)) + + (defun write-registry:string + ( ns-name:string + guard:guard + active:bool + ) + " Write entry with GUARD and ACTIVE into registry for NAME. \ + \ Guarded by operate keyset. " + + (with-capability (OPERATE) + + (validate-name ns-name) + + (write registry ns-name + { 'admin-guard: guard + , 'active: active }) + + "Register entry written")) + + (defun query:object{reg-entry} + ( ns-name:string ) + (read registry ns-name)) + + ) + +(create-table registry) + +(write-registry "kadena" + (keyset-ref-guard 'ns-operate-keyset) true) +(write-registry "user" GUARD_FAILURE true) +(write-registry "free" GUARD_FAILURE true) + +(define-namespace "kadena" + (keyset-ref-guard 'ns-operate-keyset) + (keyset-ref-guard 'ns-operate-keyset)) + +(define-namespace "user" GUARD_SUCCESS GUARD_FAILURE) +(define-namespace "free" GUARD_SUCCESS GUARD_FAILURE) +;;rotate to real operate keyset +(define-keyset 'ns-operate-keyset (read-keyset 'ns-operate-keyset)) diff --git a/pact/namespaces/v1/ns.repl b/pact/namespaces/v1/ns.repl new file mode 100644 index 0000000000..bcf3d9499f --- /dev/null +++ b/pact/namespaces/v1/ns.repl @@ -0,0 +1,87 @@ +(env-exec-config ["DisablePact44"]) +(begin-tx) +(env-data + { 'ns-admin-keyset: ["admin"] + , 'ns-operate-keyset: ["operate"] + , 'ns-genesis-keyset: { "keys": [], "pred": "="} }) + +(load "ns.pact") +(commit-tx) + +(env-namespace-policy false (ns.validate)) + +(begin-tx) +(namespace 'user) +(env-keys []) + +(module mod G + (defcap G () (enforce false "disabled")) + (defun foo () 1)) + +(namespace 'free) + +(module mod G + (defcap G () (enforce false "disabled")) + (defun foo () 2)) + +(expect-failure + "Cannot bring kadena ns into scope w/o operate admin" + (namespace 'kadena)) + +(env-keys ["operate"]) + +(namespace 'kadena) + +(module mod G + (defcap G () (enforce false "disabled")) + (defun foo () 3)) + +(commit-tx) + +(expect "user.mod works" 1 (user.mod.foo)) +(expect "free.mod works" 2 (free.mod.foo)) +(expect "kadena.mod works" 3 (kadena.mod.foo)) + +(begin-tx) +(env-keys ["operate"]) +(env-data + { 'ns-admin-keyset: ["admin"] + , 'ns-operate-keyset: ["operate"] }) + +(expect-failure "cannot redefine user" + (define-namespace 'user ns.GUARD_FAILURE ns.GUARD_FAILURE)) +(expect-failure "cannot redefine free" + (define-namespace 'free ns.GUARD_FAILURE ns.GUARD_FAILURE)) +(expect "can redefine kadena" + "Namespace defined: kadena" + (define-namespace 'kadena ns.GUARD_SUCCESS ns.GUARD_FAILURE)) + +(commit-tx) + +(begin-tx) +(env-keys []) + +(namespace 'kadena) + +(module mod2 G + (defcap G () (enforce false "disabled")) + (defun foo () 4)) +(commit-tx) + +(expect "kadena.mod2 works" 4 (kadena.mod2.foo)) + +(use ns) +(env-keys ["operate"]) +(expect-failure + "cannot register empty name" + (write-registry "" GUARD_SUCCESS true)) + +(expect-failure + "cannot register >64 length name" + (write-registry + "1234567890123456789012345678901234567890123456789012345678901234567890" + GUARD_SUCCESS true)) + +(expect-failure + "must be latin1 charset" + (write-registry "emilyπ" GUARD_SUCCESS true)) diff --git a/pact/namespaces/v2/ns-v2.yaml b/pact/namespaces/v2/ns-v2.yaml deleted file mode 100644 index a4c54b4210..0000000000 --- a/pact/namespaces/v2/ns-v2.yaml +++ /dev/null @@ -1,9 +0,0 @@ -codeFile: ns.pact -data: - ns-admin-keyset: ["368820f80c324bbc7c2b0610688a7da43e39f91d118732671cd9c7500ff43cca"] - ns-operate-keyset: ["368820f80c324bbc7c2b0610688a7da43e39f91d118732671cd9c7500ff43cca"] - ns-genesis-keyset: - keys: [] - pred: "=" -nonce: load-ns-v2-mainnet -keyPairs: [] diff --git a/pact/namespaces/v2/ns.pact b/pact/namespaces/v2/ns.pact deleted file mode 100644 index 61b84c15d6..0000000000 --- a/pact/namespaces/v2/ns.pact +++ /dev/null @@ -1,119 +0,0 @@ -(module ns GOVERNANCE - "Administers definition of new namespaces in Chainweb." - - ;; namespace v1 contract - (bless "AF2zCIWu31ATlsHOBrrhSramOa6iEO06kCbQGZmxCww") - - (defschema reg-entry - admin-guard:guard - active:bool) - - (deftable registry:{reg-entry}) - - (defcap GOVERNANCE () - (enforce-keyset 'ns-admin-keyset)) - - (defcap OPERATE () - (enforce-keyset 'ns-operate-keyset)) - - (defconst GUARD_SUCCESS (create-user-guard (success))) - (defconst GUARD_FAILURE (create-user-guard (failure))) - - (defun success () - true) - (defun failure () - (enforce false "Disabled")) - - (defun validate-name (name) - (enforce (!= "" name) "Empty name not allowed") - (enforce (< (length name) 64) "Name must be less than 64 characters long") - (enforce (is-charset CHARSET_LATIN1 name) - "Name must be in latin1 charset")) - - (defun validate:bool - ( ns-name:string - ns-admin:guard - ) - " Manages namespace install for Chainweb. Requires active row in registry \ - \ for NS-NAME with guard matching NS-ADMIN." - - (let* - ((parse-name - (lambda (n) - (let - ((take-two (take 2 n)) - (drop-two (drop 2 n))) - - (cond - ((= "k#" take-two) - (+ "k:" drop-two)) - ((= "w#" take-two) - (+ "w:" (+ (take 43 drop-two) (+ ":" (drop 46 n))))) - n)))) - - (name-validation - (lambda (n) - (if (is-principal n) - (validate-principal ns-admin n) - (validate-name n)))) - - (parsed-name (parse-name ns-name))) - - (with-default-read registry ns-name - { 'admin-guard : ns-admin - , 'active : false } - { 'admin-guard := ag - , 'active := is-active } - - (name-validation parsed-name) - (enforce is-active "Inactive or unregistered namespace") - (enforce (= ns-admin ag) "Admin guard must match guard in registry") - - true) - )) - - (defun write-registry:string - ( ns-name:string - guard:guard - active:bool - ) - " Write entry with GUARD and ACTIVE into registry for NAME. \ - \ Guarded by operate keyset. " - - (if (is-principal ns-name) - (let* - ((drop-two (drop 2 ns-name)) - (take-two (take 2 ns-name)) - - (parsed-name - (cond - ((= "k:" take-two) - (+ "k#" drop-two)) - ((= "w:" take-two) - (+ "w#" (+ (take 43 drop-two) (+ "#" (drop 44 drop-two))))) - "unsupported"))) - - (enforce (not (= "unsupported" parsed-name)) - "Unsupported principal guard protocol") - - (enforce (validate-principal guard ns-name) - "Invalid principal namespace protocol") - - (write registry parsed-name - { 'admin-guard: guard - , 'active: active })) - - (with-capability (OPERATE) - (validate-name ns-name) - - (write registry ns-name - { 'admin-guard : guard - , 'active: active }))) - - "Register entry written") - - (defun query:object{reg-entry} - ( ns-name:string ) - (read registry ns-name)) - -) diff --git a/pact/namespaces/v2/ns.repl b/pact/namespaces/v2/ns.repl deleted file mode 100644 index 72fa6c13a4..0000000000 --- a/pact/namespaces/v2/ns.repl +++ /dev/null @@ -1,201 +0,0 @@ -(env-exec-config ["DisablePact44"]) -(begin-tx) -(env-data - { 'ns-admin-keyset: ["admin"] - , 'ns-operate-keyset: ["operate"] - , 'ns-genesis-keyset: { "keys": [], "pred": "="} }) - - -(define-keyset 'ns-admin-keyset (read-keyset 'ns-admin-keyset)) -(define-keyset 'ns-operate-keyset (read-keyset 'ns-genesis-keyset)) - -(load "ns.pact") -(create-table registry) - -(write-registry "kadena" - (keyset-ref-guard 'ns-operate-keyset) true) -(write-registry "user" GUARD_FAILURE true) -(write-registry "free" GUARD_FAILURE true) - -(define-namespace "kadena" - (keyset-ref-guard 'ns-operate-keyset) - (keyset-ref-guard 'ns-operate-keyset)) - -(define-namespace "user" GUARD_SUCCESS GUARD_FAILURE) -(define-namespace "free" GUARD_SUCCESS GUARD_FAILURE) -;;rotate to real operate keyset -(define-keyset 'ns-operate-keyset (read-keyset 'ns-operate-keyset)) -(commit-tx) - -(env-namespace-policy false (ns.validate)) - -(begin-tx) -(namespace 'user) -(env-keys []) - -(module mod G - (defcap G () (enforce false "disabled")) - (defun foo () 1)) - -(namespace 'free) - -(module mod G - (defcap G () (enforce false "disabled")) - (defun foo () 2)) - -(expect-failure - "Cannot bring kadena ns into scope w/o operate admin" - (namespace 'kadena)) - -(env-keys ["operate"]) - -(namespace 'kadena) - -(module mod G - (defcap G () (enforce false "disabled")) - (defun foo () 3)) - -(commit-tx) - -(expect "user.mod works" 1 (user.mod.foo)) -(expect "free.mod works" 2 (free.mod.foo)) -(expect "kadena.mod works" 3 (kadena.mod.foo)) - -(begin-tx) -(env-keys ["operate"]) -(env-data - { 'ns-admin-keyset: ["admin"] - , 'ns-operate-keyset: ["operate"] }) - -(expect-failure "cannot redefine user" - (define-namespace 'user ns.GUARD_FAILURE ns.GUARD_FAILURE)) -(expect-failure "cannot redefine free" - (define-namespace 'free ns.GUARD_FAILURE ns.GUARD_FAILURE)) -(expect "can redefine kadena" - "Namespace defined: kadena" - (define-namespace 'kadena ns.GUARD_SUCCESS ns.GUARD_FAILURE)) - -(commit-tx) - -(begin-tx) -(env-keys []) - -(namespace 'kadena) - -(module mod2 G - (defcap G () (enforce false "disabled")) - (defun foo () 4)) -(commit-tx) -(begin-tx) - -(expect "kadena.mod2 works" 4 (kadena.mod2.foo)) - -(use ns) -(env-keys ["operate"]) -(expect-failure - "cannot register empty name" - (write-registry "" GUARD_SUCCESS true)) - -(expect-failure - "cannot register >64 length name" - (write-registry - "1234567890123456789012345678901234567890123456789012345678901234567890" - GUARD_SUCCESS true)) - -(expect-failure - "must be latin1 charset" - (write-registry "emilyπ" GUARD_SUCCESS true)) - -(commit-tx) -(begin-tx) - -(env-exec-config []) -(env-data - { "70c787fcfe6c6f4ec23d13c2e94682bc90952f7cec06c7dbac1c012b0b6678b9" : - ["70c787fcfe6c6f4ec23d13c2e94682bc90952f7cec06c7dbac1c012b0b6678b9"] - , 'multi : ["a", "b"] - }) - -(expect - "Principal namespace creation for k: accounts succeeds" - "Register entry written" - (ns.write-registry - (create-principal - (read-keyset "70c787fcfe6c6f4ec23d13c2e94682bc90952f7cec06c7dbac1c012b0b6678b9")) - (read-keyset "70c787fcfe6c6f4ec23d13c2e94682bc90952f7cec06c7dbac1c012b0b6678b9") - true)) - -(expect - "Principal namespace creation for w: accounts succeeds" - "Register entry written" - (ns.write-registry - (create-principal (read-keyset 'multi)) - (read-keyset 'multi) - true)) - -; write k: principal to registry -(ns.write-registry - (create-principal - (read-keyset "70c787fcfe6c6f4ec23d13c2e94682bc90952f7cec06c7dbac1c012b0b6678b9")) - (read-keyset "70c787fcfe6c6f4ec23d13c2e94682bc90952f7cec06c7dbac1c012b0b6678b9") - true) - -; write w: principal to registry -(ns.write-registry - (create-principal (read-keyset 'multi)) - (read-keyset 'multi) - true) - -(define-namespace - "k#70c787fcfe6c6f4ec23d13c2e94682bc90952f7cec06c7dbac1c012b0b6678b9" - (read-keyset "70c787fcfe6c6f4ec23d13c2e94682bc90952f7cec06c7dbac1c012b0b6678b9") - (read-keyset "70c787fcfe6c6f4ec23d13c2e94682bc90952f7cec06c7dbac1c012b0b6678b9")) - -(define-namespace - "w#9lped_9eJpCtMWt7n8KN2QzFyaN-YXrD7uFAPePPmlU#keys-all" - (read-keyset 'multi) - (read-keyset 'multi)) - -;; only testing control flow here. -(env-exec-config ['DisablePact44]) -(define-keyset 'multi) -(expect-failure - "Non-k or w principals cannot create namespaces" - "Unsupported" - (ns.write-registry - (create-principal (keyset-ref-guard 'multi)) - (read-keyset 'multi) - true)) - -(commit-tx) -(begin-tx) -(env-exec-config []) -(env-keys - [ "70c787fcfe6c6f4ec23d13c2e94682bc90952f7cec06c7dbac1c012b0b6678b9" - , "a" - , "b" - ] - ) - -(namespace "k#70c787fcfe6c6f4ec23d13c2e94682bc90952f7cec06c7dbac1c012b0b6678b9") -(module modK G - (defcap G () true) - (defun f () 1)) - -(namespace "w#9lped_9eJpCtMWt7n8KN2QzFyaN-YXrD7uFAPePPmlU#keys-all") -(module modW G - (defcap G () true) - (defun f () 2)) - -(commit-tx) -(begin-tx) - -(expect - "k: principal namespaces work" - 1 - (k#70c787fcfe6c6f4ec23d13c2e94682bc90952f7cec06c7dbac1c012b0b6678b9.modK.f)) - -(expect - "w: principal namespaces work" - 2 - (w#9lped_9eJpCtMWt7n8KN2QzFyaN-YXrD7uFAPePPmlU#keys-all.modW.f)) diff --git a/pact/namespaces/yaml/ns-v2.yaml b/pact/namespaces/yaml/ns-v2.yaml new file mode 100644 index 0000000000..14406f97fa --- /dev/null +++ b/pact/namespaces/yaml/ns-v2.yaml @@ -0,0 +1,5 @@ +codeFile: ../ns.pact +nonce: load-ns-v2-mainnet +signers: + - public: 56ff9e5c1b5ec3e98172a76aa3cdc03d3ec664f147267fd99eee4dd09763c853 + - public: a241430816f0112add2179e3e3939ebab5336ab024be990960e684e38eb87d80 diff --git a/test/Chainweb/Test/Pact/TransactionTests.hs b/test/Chainweb/Test/Pact/TransactionTests.hs index 01741c1f68..f386bc5cd0 100644 --- a/test/Chainweb/Test/Pact/TransactionTests.hs +++ b/test/Chainweb/Test/Pact/TransactionTests.hs @@ -80,10 +80,10 @@ coinReplV5 :: FilePath coinReplV5 = "pact/coin-contract/v5/coin-v5.repl" nsReplV1 :: FilePath -nsReplV1 = "pact/namespaces/ns.repl" +nsReplV1 = "pact/namespaces/v1/ns.repl" nsReplV2 :: FilePath -nsReplV2 = "pact/namespaces/v2/ns.repl" +nsReplV2 = "pact/namespaces/ns.repl" logger :: Logger #if DEBUG_TEST @@ -109,8 +109,8 @@ tests = testGroup "Chainweb.Test.Pact.TransactionTests" , testCase "v5" (ccReplTests coinReplV5) ] , testGroup "Namespace repl unit tests" - [ testCase "Ns v1 repl tests" $ ccReplTests nsReplV1 - , testCase "Ns v2 repl tests" $ ccReplTests nsReplV2 + [ testCase "Ns-v1 repl tests" $ ccReplTests nsReplV1 + , testCase "Ns-v2 repl tests" $ ccReplTests nsReplV2 ] , testCase "Payer Repl Tests" (ccReplTests "pact/gas-payer/gas-payer-v1.repl") ] From 3378b5271714822b93c06a149e8aacde2422723b Mon Sep 17 00:00:00 2001 From: Emily Pillmore Date: Thu, 29 Sep 2022 14:17:05 -0600 Subject: [PATCH 25/29] add typecheck for principal type + test --- pact/namespaces/ns.pact | 14 ++++++++++++-- pact/namespaces/ns.repl | 16 ++++++++++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/pact/namespaces/ns.pact b/pact/namespaces/ns.pact index 141cd814f1..908e8c101c 100644 --- a/pact/namespaces/ns.pact +++ b/pact/namespaces/ns.pact @@ -31,8 +31,18 @@ ( g:guard ) " Format principal namespace as Pact hash (BLAKE2b256) of principal \ - \ in hex truncated to 160 bits (40 characters), prepended with 'n_'. " - (+ "n_" (take 40 (int-to-str 16 (str-to-int 64 (hash g))))) + \ in hex truncated to 160 bits (40 characters), prepended with 'n_'.\ + \ Only w: and k: account protocols are supported. " + + (let + ((ty (typeof-principal (create-principal g)))) + + ;; only w: and k: currently supported + (if (or (= ty "k:") (= ty "w:")) + (+ "n_" (take 40 (int-to-str 16 (str-to-int 64 (hash g))))) + (enforce false + (format "Unsupported guard protocol: {}" [ty])) + )) ) (defun validate:bool diff --git a/pact/namespaces/ns.repl b/pact/namespaces/ns.repl index 0630583e1d..8fb67c67b9 100644 --- a/pact/namespaces/ns.repl +++ b/pact/namespaces/ns.repl @@ -177,3 +177,19 @@ "w: principal namespaces work" 2 (n_64bfdef1c668b167c87f7cf329454c572e284664.modW.f)) + +(commit-tx) +(begin-tx) + +(env-data + { "n_c1a583206e24450af26de41110042b019695db8c.failure": ['k] + }) + +(namespace "n_c1a583206e24450af26de41110042b019695db8c") +(define-keyset "n_c1a583206e24450af26de41110042b019695db8c.failure") + +(expect-failure + "r: principal namespaces do not work" + "Unsupported guard protocol: r:" + (ns.create-principal-namespace + (keyset-ref-guard "n_c1a583206e24450af26de41110042b019695db8c.failure"))) From 05162309add8ee41e3b4d42eabafe18f13d8cc7d Mon Sep 17 00:00:00 2001 From: Emily Pillmore Date: Thu, 17 Nov 2022 17:11:48 -0700 Subject: [PATCH 26/29] add (wip) test for failed upgrade + comments --- pact/namespaces/.pact-history | 43 +++++++++++++++++++++++++++++++++++ pact/namespaces/ns.repl | 18 ++++++++++++++- 2 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 pact/namespaces/.pact-history diff --git a/pact/namespaces/.pact-history b/pact/namespaces/.pact-history new file mode 100644 index 0000000000..f3d4a8ff94 --- /dev/null +++ b/pact/namespaces/.pact-history @@ -0,0 +1,43 @@ +(load "ns.repl" true) +(load "ns.repl" true) +(load "ns.pact") +(env-keys ['admin]) +(env-data { 'ns-admin-keyset:['admin]}) +(load "ns.pact") +(env-data {}) +(begin-tx) +(commit-tx) +(load "v1/ns.pact") +(env-data { "ns-admin-keyset": ['admin], 'ns-operate-keyset: ['operate], 'ns-genesis-keyset: { "keys": [], "pred": "=" }}) +(env-exec-config ["DisablePact45", 'DisablePact44]) +(begin-tx) +(env-data { "ns-admin-keyset": ['admin], 'ns-operate-keyset: ['operate], 'ns-genesis-keyset: { "keys": [], "pred": "=" }}) +(env-exec-config ["DisablePact45", 'DisablePact44]) +(load "v1/ns.pact") +(load "v1/ns.pact") +(load "v1/ns.pact") +(env-data { "ns-admin-keyset": ['admin], 'ns-operate-keyset: ['operate], 'ns-genesis-keyset: { "keys": [], "pred": "=" }}) +(load "v1/ns.pact") +(env-data { "ns-admin-keyset": ['admin], 'ns-operate-keyset: ['operate], 'ns-genesis-keyset: { "keys": [], "pred": "=" }}) +(load "v1/ns.pact") +) +(load "ns.pact" +(env-data {}) +(load "v1/ns.pact") +(env-data { "ns-admin-keyset": ['admin], 'ns-operate-keyset: ['operate], 'ns-genesis-keyset: { "keys": [], "pred": "=" }}) +(env-exec-config ["DisablePact45", 'DisablePact44]) +(load "v1/ns.pact") +(load "ns.pact") +(env-data {}) +env-data +(load "ns.pact") +(load "v1/ns.pact") +(env-exec-config ["DisablePact45", 'DisablePact44]) +(load "v1/ns.pact") +(env-data { "ns-admin-keyset": ['admin], 'ns-operate-keyset: ['operate], 'ns-genesis-keyset: { "keys": [], "pred": "=" }}) +(env-exec-config ["DisablePact45"]) +(load "v1/ns.pact") +(env-data { "ns-admin-keyset": ['admin], 'ns-operate-keyset: ['operate], 'ns-genesis-keyset: { "keys": [], "pred": "=" }}) +(env-data { "ns-admin-keyset": ['admin], 'ns-operate-keyset: ['operate], 'ns-genesis-keyset: { "keys": [], "pred": "=" }) +(env-data { "ns-admin-keyset": ['admin], 'ns-operate-keyset: ['operate], 'ns-genesis-keyset { "keys": [], "pred": "=" }) +(load "v1/ns.pact") diff --git a/pact/namespaces/ns.repl b/pact/namespaces/ns.repl index 436d4ea155..20f38c08d0 100644 --- a/pact/namespaces/ns.repl +++ b/pact/namespaces/ns.repl @@ -1,17 +1,33 @@ (env-exec-config ["DisablePact44", "DisablePact45"]) (begin-tx) + (env-data { 'ns-admin-keyset: ["admin"] , 'ns-operate-keyset: ["operate"] , 'ns-genesis-keyset: { "keys": [], "pred": "="} }) (load "v1/ns.pact") + +(commit-tx) +(begin-tx) + +;; Test that we can upgrade ns.pact only when appropriate keys +;; are in scope. +(env-data {}) +(expect-failure + "Cannot upgrade the namespace contract due to governance failure" + (load "ns.pact")) + +(env-data + { 'ns-admin-keyset: ['admin] }) +(env-keys ['admin]) (load "ns.pact") + (commit-tx) +(begin-tx) (env-namespace-policy false (ns.validate)) -(begin-tx) (namespace 'user) (env-keys []) From a7b8f9f4344796adf3cb10279198dd334f070b31 Mon Sep 17 00:00:00 2001 From: Emily Pillmore Date: Thu, 17 Nov 2022 17:12:06 -0700 Subject: [PATCH 27/29] purge pact history --- pact/namespaces/.pact-history | 43 ----------------------------------- 1 file changed, 43 deletions(-) delete mode 100644 pact/namespaces/.pact-history diff --git a/pact/namespaces/.pact-history b/pact/namespaces/.pact-history deleted file mode 100644 index f3d4a8ff94..0000000000 --- a/pact/namespaces/.pact-history +++ /dev/null @@ -1,43 +0,0 @@ -(load "ns.repl" true) -(load "ns.repl" true) -(load "ns.pact") -(env-keys ['admin]) -(env-data { 'ns-admin-keyset:['admin]}) -(load "ns.pact") -(env-data {}) -(begin-tx) -(commit-tx) -(load "v1/ns.pact") -(env-data { "ns-admin-keyset": ['admin], 'ns-operate-keyset: ['operate], 'ns-genesis-keyset: { "keys": [], "pred": "=" }}) -(env-exec-config ["DisablePact45", 'DisablePact44]) -(begin-tx) -(env-data { "ns-admin-keyset": ['admin], 'ns-operate-keyset: ['operate], 'ns-genesis-keyset: { "keys": [], "pred": "=" }}) -(env-exec-config ["DisablePact45", 'DisablePact44]) -(load "v1/ns.pact") -(load "v1/ns.pact") -(load "v1/ns.pact") -(env-data { "ns-admin-keyset": ['admin], 'ns-operate-keyset: ['operate], 'ns-genesis-keyset: { "keys": [], "pred": "=" }}) -(load "v1/ns.pact") -(env-data { "ns-admin-keyset": ['admin], 'ns-operate-keyset: ['operate], 'ns-genesis-keyset: { "keys": [], "pred": "=" }}) -(load "v1/ns.pact") -) -(load "ns.pact" -(env-data {}) -(load "v1/ns.pact") -(env-data { "ns-admin-keyset": ['admin], 'ns-operate-keyset: ['operate], 'ns-genesis-keyset: { "keys": [], "pred": "=" }}) -(env-exec-config ["DisablePact45", 'DisablePact44]) -(load "v1/ns.pact") -(load "ns.pact") -(env-data {}) -env-data -(load "ns.pact") -(load "v1/ns.pact") -(env-exec-config ["DisablePact45", 'DisablePact44]) -(load "v1/ns.pact") -(env-data { "ns-admin-keyset": ['admin], 'ns-operate-keyset: ['operate], 'ns-genesis-keyset: { "keys": [], "pred": "=" }}) -(env-exec-config ["DisablePact45"]) -(load "v1/ns.pact") -(env-data { "ns-admin-keyset": ['admin], 'ns-operate-keyset: ['operate], 'ns-genesis-keyset: { "keys": [], "pred": "=" }}) -(env-data { "ns-admin-keyset": ['admin], 'ns-operate-keyset: ['operate], 'ns-genesis-keyset: { "keys": [], "pred": "=" }) -(env-data { "ns-admin-keyset": ['admin], 'ns-operate-keyset: ['operate], 'ns-genesis-keyset { "keys": [], "pred": "=" }) -(load "v1/ns.pact") From 272cdb43c29999ebc95b0d45b29b1d9c4ff2465a Mon Sep 17 00:00:00 2001 From: Emily Pillmore Date: Fri, 18 Nov 2022 11:22:04 -0700 Subject: [PATCH 28/29] add weird test for upgrades --- pact/namespaces/ns.repl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pact/namespaces/ns.repl b/pact/namespaces/ns.repl index 20f38c08d0..a8f728e6aa 100644 --- a/pact/namespaces/ns.repl +++ b/pact/namespaces/ns.repl @@ -16,7 +16,8 @@ (env-data {}) (expect-failure "Cannot upgrade the namespace contract due to governance failure" - (load "ns.pact")) + "tx failure on upgrade" + (try (enforce false "tx failure on upgrade") (load "ns.pact"))) (env-data { 'ns-admin-keyset: ['admin] }) From 9b1eb0946eedf7f7f9381f4978d395e3c74266b3 Mon Sep 17 00:00:00 2001 From: Emily Pillmore Date: Fri, 18 Nov 2022 11:37:44 -0700 Subject: [PATCH 29/29] stuarts comments --- pact/namespaces/ns.repl | 3 --- 1 file changed, 3 deletions(-) diff --git a/pact/namespaces/ns.repl b/pact/namespaces/ns.repl index a8f728e6aa..c8093d0edb 100644 --- a/pact/namespaces/ns.repl +++ b/pact/namespaces/ns.repl @@ -13,14 +13,11 @@ ;; Test that we can upgrade ns.pact only when appropriate keys ;; are in scope. -(env-data {}) (expect-failure "Cannot upgrade the namespace contract due to governance failure" "tx failure on upgrade" (try (enforce false "tx failure on upgrade") (load "ns.pact"))) -(env-data - { 'ns-admin-keyset: ['admin] }) (env-keys ['admin]) (load "ns.pact")