Skip to content
This repository was archived by the owner on Nov 24, 2025. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
9ca72b6
update pact for pact-4.4
emilypi Aug 9, 2022
7fb035d
update warp tls
jmcardon Aug 9, 2022
878cf4b
Merge branch 'master' into feat/integrate-pact44
edmundnoble Aug 10, 2022
34ad004
set up initial gas environment
jmcardon Aug 10, 2022
3f485e6
fix merge conflicts
jmcardon Aug 10, 2022
76d5ae6
wip fix tests
jmcardon Aug 10, 2022
9f51bc1
fix rosetta gas bound
jmcardon Aug 10, 2022
6a052aa
update pin to latest master
jmcardon Aug 10, 2022
ea2c899
Fix spcae mistake in ns.pact
jmcardon Aug 10, 2022
01b5778
merge master
emilypi Aug 10, 2022
fab4b49
merge master
emilypi Aug 10, 2022
3ac3196
get started on pactinprocapi test
emilypi Aug 10, 2022
7ea8f31
wip tests to pre/post fork conditions in define-keyset
jmcardon Aug 12, 2022
12914a2
all tests pre-post fork
jmcardon Aug 12, 2022
f3c7ec2
update pin with latest master
jmcardon Aug 12, 2022
ab14aa9
Remove now nonexistent flag
edmundnoble Aug 15, 2022
98d29e9
initial rewrite
emilypi Aug 15, 2022
5736a63
remove unnecessary flag
emilypi Aug 15, 2022
1e502f0
parser fixes
jmcardon Aug 16, 2022
463c780
kludgy first implementation
emilypi Aug 16, 2022
a0e104f
WIP repl tests
emilypi Aug 17, 2022
0deff95
Add initial coverage, get code working
emilypi Aug 17, 2022
405d35a
latest pact master
jmcardon Aug 17, 2022
6688d46
bless old contract
emilypi Aug 17, 2022
dab259b
Merge branch 'feat/integrate-pact44' into feat/principal-namespaces
emilypi Aug 17, 2022
7d96a95
add ns-v2.yaml
emilypi Aug 17, 2022
e980f22
hook up repl tests to pact tests for ns (v1 and v2)
emilypi Aug 19, 2022
58c8789
Merge branch 'master' into feat/principal-namespaces
emilypi Aug 19, 2022
eccced7
undo checkpointer change
emilypi Aug 19, 2022
6547c57
move stale logic out of contract defn
emilypi Aug 19, 2022
e21f1d3
Merge branch 'master' into feat/principal-namespaces
emilypi Aug 26, 2022
1b9a00f
Merge branch 'master' into feat/principal-namespaces
sirlensalot Sep 8, 2022
06994dc
slp: move files around for better diff, get gas payer working
sirlensalot Sep 8, 2022
2f62913
don't use registry for principal namespaces
sirlensalot Sep 8, 2022
7a77e90
remove dupe validate
sirlensalot Sep 8, 2022
47cdec7
fix mainnet genesis yaml
sirlensalot Sep 8, 2022
cf6e2b1
use previous install in repl
sirlensalot Sep 8, 2022
d9755b5
move to hashes of principals
sirlensalot Sep 8, 2022
5dbf535
prefix namespaces with "n"
sirlensalot Sep 8, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pact/gas-payer/gas-payer-v1.repl
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion pact/genesis/mainnet/ns.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
codeFile: ../../namespaces/ns.pact
codeFile: ../../namespaces/v1/ns.pact
data:
ns-admin-keyset:
keys:
Expand Down
2 changes: 1 addition & 1 deletion pact/genesis/ns.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
codeFile: ../namespaces/ns.pact
codeFile: ../namespaces/v1/ns.pact
data:
ns-admin-keyset: ["368820f80c324bbc7c2b0610688a7da43e39f91d118732671cd9c7500ff43cca"]
ns-operate-keyset: ["368820f80c324bbc7c2b0610688a7da43e39f91d118732671cd9c7500ff43cca"]
Expand Down
43 changes: 14 additions & 29 deletions pact/namespaces/ns.pact
Original file line number Diff line number Diff line change
@@ -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."

Expand Down Expand Up @@ -35,21 +31,26 @@
( ns-name:string
ns-admin:guard
)
" Manages namespace install for Chainweb. Requires active row in registry \
" Manages namespace install for Chainweb. \
\ Supports principal namespaces ('n' + hashed principal of admin guard). \
\ Non-principal namespaces require active row in registry \
\ for NS-NAME with guard matching NS-ADMIN."

(validate-name ns-name)
(if (= (+ "n" (hash (create-principal ns-admin))) ns-name)

(with-default-read registry ns-name
{ 'admin-guard : ns-admin
, 'active : false }
{ 'admin-guard := ag
, 'active := is-active }
true ;; allow principal namespaces

(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
Expand All @@ -73,20 +74,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))
)
82 changes: 82 additions & 0 deletions pact/namespaces/ns.repl
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
, 'ns-operate-keyset: ["operate"]
, 'ns-genesis-keyset: { "keys": [], "pred": "="} })

(load "v1/ns.pact")
(load "ns.pact")
(commit-tx)

Expand Down Expand Up @@ -67,6 +68,7 @@
(defcap G () (enforce false "disabled"))
(defun foo () 4))
(commit-tx)
(begin-tx)

(expect "kadena.mod2 works" 4 (kadena.mod2.foo))

Expand All @@ -85,3 +87,83 @@
(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-failure
"Principal of other than admin keyset fails"
"Inactive or unregistered namespace"
(define-namespace
"nD8cqMpEfqKF_tj8I0be5VDdoYfBvb5ax_tFZMoHvXU4"
(read-keyset 'single)
(read-keyset 'multi))
)

(define-namespace
"nD8cqMpEfqKF_tj8I0be5VDdoYfBvb5ax_tFZMoHvXU4"
(read-keyset 'single)
(read-keyset 'single))

(define-namespace
"ndDxw31bRij5gA0Xvl_uDUOZMvrnkMscu-Ax-H0ocJFM"
(read-keyset 'multi)
(read-keyset 'multi))

(commit-tx)

(begin-tx "test rotation")
(env-keys
[ "70c787fcfe6c6f4ec23d13c2e94682bc90952f7cec06c7dbac1c012b0b6678b9" ])
;; rotate to multi/multi
(define-namespace
"nD8cqMpEfqKF_tj8I0be5VDdoYfBvb5ax_tFZMoHvXU4"
(read-keyset 'multi)
(read-keyset 'multi))
;; rotate to multi/single
(env-keys ["a","b"])
(define-namespace
"nD8cqMpEfqKF_tj8I0be5VDdoYfBvb5ax_tFZMoHvXU4"
(read-keyset 'multi)
(read-keyset 'single))
(rollback-tx)


(begin-tx)
(env-exec-config [])
(env-keys
[ "70c787fcfe6c6f4ec23d13c2e94682bc90952f7cec06c7dbac1c012b0b6678b9"
, "a"
, "b"
]
)

(namespace "nD8cqMpEfqKF_tj8I0be5VDdoYfBvb5ax_tFZMoHvXU4")
(module modK G
(defcap G () true)
(defun f () 1))

(namespace "ndDxw31bRij5gA0Xvl_uDUOZMvrnkMscu-Ax-H0ocJFM")
(module modW G
(defcap G () true)
(defun f () 2))

(commit-tx)
(begin-tx)

(expect
"k: principal namespaces work"
1
(nD8cqMpEfqKF_tj8I0be5VDdoYfBvb5ax_tFZMoHvXU4.modK.f))

(expect
"w: principal namespaces work"
2
(ndDxw31bRij5gA0Xvl_uDUOZMvrnkMscu-Ax-H0ocJFM.modW.f))
92 changes: 92 additions & 0 deletions pact/namespaces/v1/ns.pact
Original file line number Diff line number Diff line change
@@ -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))
87 changes: 87 additions & 0 deletions pact/namespaces/v1/ns.repl
Original file line number Diff line number Diff line change
@@ -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))
5 changes: 5 additions & 0 deletions pact/namespaces/yaml/ns-v2.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
codeFile: ../ns.pact
nonce: load-ns-v2-mainnet
signers:
- public: 56ff9e5c1b5ec3e98172a76aa3cdc03d3ec664f147267fd99eee4dd09763c853
- public: a241430816f0112add2179e3e3939ebab5336ab024be990960e684e38eb87d80
11 changes: 10 additions & 1 deletion test/Chainweb/Test/Pact/TransactionTests.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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/v1/ns.repl"

nsReplV2 :: FilePath
nsReplV2 = "pact/namespaces/ns.repl"

logger :: Logger
#if DEBUG_TEST
logger = newLogger alwaysLog ""
Expand All @@ -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"
Expand Down