Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
73 commits
Select commit Hold shift + click to select a range
5c1f9bf
feat(#689): update ledger types
sourabhxyz Sep 3, 2025
5a4aef6
fourmolu auto-commit
sourabhxyz Sep 3, 2025
1fbbaa9
feat(#689): `sPreviousBatch` -> `sPreviousStateHash`
sourabhxyz Sep 3, 2025
825373d
Merge branch '689-pivot-simplified-account' of github.com:zkFold/symb…
sourabhxyz Sep 3, 2025
71cbce8
feat(#689): make `Nonce` a `FieldElement` instead
sourabhxyz Sep 4, 2025
b498951
fourmolu auto-commit
sourabhxyz Sep 4, 2025
edd0f3a
feat(#689): improve type for bridge out assets, bridge in assets, tra…
sourabhxyz Sep 5, 2025
db49032
feat(#689): handle merge conflicts
sourabhxyz Sep 5, 2025
4af85e4
feat(#689): `AssetValues` -> `AssetValue` in `sAccountInfo`
sourabhxyz Sep 5, 2025
51669d0
feat(#689): add state validation
sourabhxyz Sep 5, 2025
201ee05
Merge remote-tracking branch 'origin/main' into upon-689
sourabhxyz Sep 16, 2025
42cec29
fourmolu auto-commit
sourabhxyz Sep 16, 2025
0c82c52
feat(#689): update wrt latest breaking changes in main
sourabhxyz Sep 17, 2025
0828082
feat(#689): update wrt latest breaking changes in main
sourabhxyz Sep 17, 2025
52039d2
fourmolu auto-commit
sourabhxyz Sep 17, 2025
934ec89
feat(#689): remove redundant import
sourabhxyz Sep 17, 2025
398ccf4
fourmolu auto-commit
sourabhxyz Sep 17, 2025
328966f
feat(#689): parameterize maximum number of users
sourabhxyz Sep 17, 2025
f90a4f9
Merge branch 'upon-689' of github.com:zkFold/symbolic into upon-689
sourabhxyz Sep 17, 2025
b6aec34
fourmolu auto-commit
sourabhxyz Sep 17, 2025
aca9784
feat(#689): put just root hash of asset tree in account info
sourabhxyz Sep 17, 2025
64a245b
Merge branch 'upon-689' of github.com:zkFold/symbolic into upon-689
sourabhxyz Sep 17, 2025
a6d60fc
feat(#689): add state witness type
sourabhxyz Sep 17, 2025
077825a
fourmolu auto-commit
sourabhxyz Sep 17, 2025
960d0d3
Merge remote-tracking branch 'origin/main' into upon-689
sourabhxyz Sep 17, 2025
e0547e9
Merge branch 'upon-689' of github.com:zkFold/symbolic into upon-689
sourabhxyz Sep 17, 2025
813a703
feat(#689): saving progress related to vector of nonce, before trying…
sourabhxyz Sep 19, 2025
1a2c4f5
feat(#689): modify types to have UTxO based ledger
sourabhxyz Sep 19, 2025
a0f2768
fourmolu auto-commit
sourabhxyz Sep 19, 2025
92a5050
feat(#689): work out validation design
sourabhxyz Sep 19, 2025
e492c8d
fourmolu auto-commit
sourabhxyz Sep 19, 2025
4935c39
feat(#689): state validation updates
sourabhxyz Sep 19, 2025
4ec90fc
Merge branch '689-utxo' of github.com:zkFold/symbolic into 689-utxo
sourabhxyz Sep 19, 2025
1435108
feat(#689): compute utxo set by incorporating bridged in assets
sourabhxyz Sep 19, 2025
15c0e4f
fourmolu auto-commit
sourabhxyz Sep 19, 2025
e818899
feat(#689): compute state and batch validation
sourabhxyz Sep 19, 2025
5dc9a94
fourmolu auto-commit
sourabhxyz Sep 19, 2025
58589e9
feat(#689): remove comments
sourabhxyz Sep 19, 2025
6b6d38b
Merge branch '689-utxo' of github.com:zkFold/symbolic into 689-utxo
sourabhxyz Sep 19, 2025
057ef17
fourmolu auto-commit
sourabhxyz Sep 19, 2025
b355c5d
feat(#689): add some of tx validation checks
sourabhxyz Sep 19, 2025
5eeab7d
Merge branch '689-utxo' of github.com:zkFold/symbolic into 689-utxo
sourabhxyz Sep 19, 2025
5784b2f
fourmolu auto-commit
sourabhxyz Sep 19, 2025
16efd6e
feat(#689): input tx validation check
sourabhxyz Sep 19, 2025
4b65373
fourmolu auto-commit
sourabhxyz Sep 19, 2025
3174263
feat(#689): complete tx validation checks
sourabhxyz Sep 19, 2025
cfa2dee
fourmolu auto-commit
sourabhxyz Sep 19, 2025
8cfc7fb
style(#689): hlint suggestions
sourabhxyz Sep 19, 2025
7aaf67b
fourmolu auto-commit
sourabhxyz Sep 19, 2025
50845d0
feat(#689): also check that input utxo is not the null utxo
sourabhxyz Sep 19, 2025
d5148ec
fourmolu auto-commit
sourabhxyz Sep 19, 2025
07fd7e5
feat(#689): check that output has atleast 1 ada
sourabhxyz Sep 19, 2025
104b4f8
fourmolu auto-commit
sourabhxyz Sep 19, 2025
0ee6ded
feat(#689): check that transaction is balanced
sourabhxyz Sep 22, 2025
695a38e
fourmolu auto-commit
sourabhxyz Sep 22, 2025
22842a5
feat(#689): check that bridged in outputs have at least one ada
sourabhxyz Sep 22, 2025
fe882ae
fourmolu auto-commit
sourabhxyz Sep 22, 2025
b9a9d66
feat(#689): remove redundant imports
sourabhxyz Sep 22, 2025
c981c81
fourmolu auto-commit
sourabhxyz Sep 22, 2025
e5968fa
fix(#689): bug in ifThenElse branch
sourabhxyz Sep 22, 2025
8636aba
fourmolu auto-commit
sourabhxyz Sep 22, 2025
d836b77
docs(#689): add comments
sourabhxyz Sep 22, 2025
89bb9fe
fourmolu auto-commit
sourabhxyz Sep 22, 2025
e7a590c
docs(#689): add comments
sourabhxyz Sep 22, 2025
09257c7
fourmolu auto-commit
sourabhxyz Sep 22, 2025
86af47c
docs(#689): add comments
sourabhxyz Sep 22, 2025
53b1548
docs(#689): add comments
sourabhxyz Sep 22, 2025
a492cf8
feat(#689): bug fix to see output is null instead of utxo for bridged…
sourabhxyz Sep 23, 2025
8a5e2b7
fourmolu auto-commit
sourabhxyz Sep 23, 2025
b527737
Merge branch 'main' into 689-utxo
sourabhxyz Sep 23, 2025
b2be619
feat(#689): rename from boutsValidAcc to outsValidAcc
sourabhxyz Sep 23, 2025
082d9e8
Merge branch '689-utxo' of github.com:zkFold/symbolic into 689-utxo
sourabhxyz Sep 23, 2025
0864a81
fourmolu auto-commit
sourabhxyz Sep 23, 2025
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
11 changes: 9 additions & 2 deletions symbolic-base/src/ZkFold/Data/Eq.hs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import qualified Data.Ord as Haskell
import Data.Ratio (Rational)
import Data.String (String)
import Data.Type.Equality (type (~))
import GHC.Generics ((:.:))
import qualified GHC.Generics as G
import Numeric.Natural (Natural)
import Prelude (Integer)
Expand All @@ -28,14 +29,18 @@ class BoolType (BooleanOf a) => Eq a where
(==) :: a -> a -> BooleanOf a
default (==)
:: (G.Generic a, GEq (G.Rep a), BooleanOf a ~ GBooleanOf (G.Rep a))
=> a -> a -> BooleanOf a
=> a
-> a
-> BooleanOf a
x == y = geq (G.from x) (G.from y)

infix 4 /=
(/=) :: a -> a -> BooleanOf a
default (/=)
:: (G.Generic a, GEq (G.Rep a), BooleanOf a ~ GBooleanOf (G.Rep a))
=> a -> a -> BooleanOf a
=> a
-> a
-> BooleanOf a
x /= y = gneq (G.from x) (G.from y)

elem :: (Eq a, Foldable t) => a -> t a -> BooleanOf a
Expand Down Expand Up @@ -74,6 +79,8 @@ instance Eq (f a) => Eq (G.Rec1 f a)

instance Eq (f a) => Eq (G.M1 i c f a)

instance Eq (f (g a)) => Eq ((:.:) f g a)

instance {-# OVERLAPPING #-} Eq (f a) => Eq ((f G.:*: G.U1) a) where
(x G.:*: _) == (y G.:*: _) = x == y
(x G.:*: _) /= (y G.:*: _) = x /= y
Expand Down
35 changes: 27 additions & 8 deletions symbolic-base/src/ZkFold/Symbolic/Data/MerkleTree.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ module ZkFold.Symbolic.Data.MerkleTree (
emptyTree,
fromLeaves,
toLeaves,
MerklePath,
merklePath,
rootOnReplace,
MerkleEntry (..),
Expand Down Expand Up @@ -111,7 +112,9 @@ type Index d = Vector (d - 1) :.: Bool

merklePath
:: (Symbolic c, KnownNat (d - 1))
=> MerkleTree d c -> Index d c -> MerklePath d c
=> MerkleTree d c
-> Index d c
-> MerklePath d c
merklePath MerkleTree {..} position =
let baseTree = Base.MerkleTree (toBaseHash mHash) (toBaseLeaves mLeaves)
path = fromBaseHash <$> Base.merkleProve' baseTree (toBasePosition position)
Expand All @@ -130,7 +133,9 @@ data MerkleEntry d c = MerkleEntry
contains
:: forall d c
. (Symbolic c, KnownNat (d - 1))
=> MerkleTree d c -> MerkleEntry d c -> Bool c
=> MerkleTree d c
-> MerkleEntry d c
-> Bool c
tree `contains` MerkleEntry {..} =
rootOnReplace (merklePath tree position) value == mHash tree

Expand All @@ -139,7 +144,9 @@ type Bool' c = BooleanOf (IntegralOf (WitnessField c))
(!!)
:: forall d c
. (Symbolic c, KnownNat (d - 1))
=> MerkleTree d c -> Index d c -> FieldElement c
=> MerkleTree d c
-> Index d c
-> FieldElement c
tree !! position =
assert (\value -> tree `contains` MerkleEntry {..}) $
fromBaseHash $
Expand Down Expand Up @@ -172,7 +179,9 @@ search pred tree =
recSearch
:: forall n b a
. (BoolType b, Conditional b a)
=> (a -> b) -> Vector (2 ^ n) a -> (b, Vector n b, a)
=> (a -> b)
-> Vector (2 ^ n) a
-> (b, Vector n b, a)
recSearch p d =
let (b, i, x) = doSearch (toV d)
in (b, unsafeToVector i, x)
Expand Down Expand Up @@ -228,7 +237,9 @@ elemIndex elem = findIndex (== elem)

lookup
:: (Symbolic c, KnownNat (d - 1))
=> MerkleTree d c -> Index d c -> FieldElement c
=> MerkleTree d c
-> Index d c
-> FieldElement c
lookup = (!!)

search'
Expand All @@ -242,7 +253,9 @@ type KnownMerkleTree d = (KnownNat (d - 1), KnownNat (Base.MerkleTreeSize d))

replace
:: (Symbolic c, KnownMerkleTree d)
=> MerkleEntry d c -> MerkleTree d c -> MerkleTree d c
=> MerkleEntry d c
-> MerkleTree d c
-> MerkleTree d c
replace entry@MerkleEntry {..} =
assert (`contains` entry)
. unconstrainedFromLeaves
Expand All @@ -252,12 +265,18 @@ replace entry@MerkleEntry {..} =
where
replacer
:: (FromConstant n i, Eq i, Conditional (BooleanOf i) a)
=> (i, a) -> n -> a -> a
=> (i, a)
-> n
-> a
-> a
replacer (i, a') n = ifThenElse (i == fromConstant n) a'

replaceAt
:: (Symbolic c, KnownMerkleTree d)
=> Index d c -> FieldElement c -> MerkleTree d c -> MerkleTree d c
=> Index d c
-> FieldElement c
-> MerkleTree d c
-> MerkleTree d c
replaceAt position value = replace MerkleEntry {..}

---------------------------- conversion functions ------------------------------
Expand Down
87 changes: 36 additions & 51 deletions symbolic-ledger/src/ZkFold/Symbolic/Ledger/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,69 +3,54 @@
module ZkFold.Symbolic.Ledger.Types (
module ZkFold.Symbolic.Ledger.Types.Address,
module ZkFold.Symbolic.Ledger.Types.Hash,
module ZkFold.Symbolic.Ledger.Types.Interval,
module ZkFold.Symbolic.Ledger.Types.Output,
module ZkFold.Symbolic.Ledger.Types.State,
module ZkFold.Symbolic.Ledger.Types.Transaction,
module ZkFold.Symbolic.Ledger.Types.Root,
module ZkFold.Symbolic.Ledger.Types.Datum,
module ZkFold.Symbolic.Ledger.Types.Value,
module ZkFold.Symbolic.Ledger.Types.DataAvailability,
module ZkFold.Symbolic.Ledger.Types.Circuit,
Signature,
SignatureTransaction,
SignatureTransactionBatch,
SignatureState,
) where

-- Re-exports

import GHC.Generics ((:*:))
import GHC.TypeLits (KnownNat)
import GHC.Generics ((:.:))
import GHC.TypeNats (KnownNat, type (-))
import ZkFold.Data.MerkleTree (MerkleTreeSize)
import ZkFold.Data.Vector (Vector)
import ZkFold.Symbolic.Class (Symbolic (..))
import ZkFold.Symbolic.Data.Combinators (
Ceil,
GetRegisterSize,
KnownRegisters,
RegisterSize (Auto),
)
import ZkFold.Symbolic.Data.FieldElement (FieldElement)
import ZkFold.Symbolic.Data.Hash (Hashable)
import ZkFold.Symbolic.Data.UInt (OrdWord)
import ZkFold.Symbolic.Fold (SymbolicFold)

import ZkFold.Symbolic.Ledger.Types.Address
import ZkFold.Symbolic.Ledger.Types.Circuit
import ZkFold.Symbolic.Ledger.Types.DataAvailability
import ZkFold.Symbolic.Ledger.Types.Datum
import ZkFold.Symbolic.Ledger.Types.Hash
import ZkFold.Symbolic.Ledger.Types.Interval
import ZkFold.Symbolic.Ledger.Types.Output
import ZkFold.Symbolic.Ledger.Types.Root
import ZkFold.Symbolic.Ledger.Types.State
import ZkFold.Symbolic.Ledger.Types.Transaction
import ZkFold.Symbolic.Ledger.Types.Value

{-
zkFold's ledger is a UTXO-based ledger. The architecture of the ledger is mostly similar to the Cardano ledger with some key differences:

- Some transaction data is private and is kept off-chain by the concerned parties.

- All UTXOs are locked by contracts.
type SignatureTransaction ud i o a context =
( Symbolic context
, KnownRegistersAssetQuantity context
, KnownNat i
, KnownNat a
, KnownNat (ud - 1)
, KnownNat (MerkleTreeSize ud)
, Hashable (HashSimple context) (Transaction i o a context)
, forall s. Hashable (HashSimple s) (Transaction i o a s)
, Hashable (HashSimple context) (UTxO a context)
, forall s. Hashable (HashSimple s) (UTxO a s)
)

- Stake delegation and governance is implemented through contracts.
-}
type SignatureTransactionBatch ud i o a t context =
( SignatureTransaction ud i o a context
, Hashable (HashSimple context) (TransactionBatch i o a t context)
, forall s. Hashable (HashSimple s) (TransactionBatch i o a t s)
)

type Signature context =
( KnownRegistersAssetQuantity context
, KnownRegistersOutputIndex context
, KnownRegisters context 11 Auto
, SymbolicFold context
, KnownNat (Ceil (GetRegisterSize (BaseField context) 11 Auto) OrdWord)
, -- TODO: Can we derive 'Hashable h' based on constituents (using generic)?
-- TODO: Remove @ImpredicativeTypes@ extension from symbolic-ledger once above 'Hashable' issue is sorted.
Hashable (HashSimple context) (AssetValues context)
, Hashable (HashSimple context) (Transaction context)
, Hashable (HashSimple context) (TransactionBatch context)
, Hashable (HashSimple context) (TransactionBatchData context)
, Hashable (HashSimple context) ((Circuit :*: DAIndex :*: DAType) context)
, forall s. Hashable (HashSimple s) (AssetValues s)
, forall s. Hashable (HashSimple s) (Transaction s)
, forall s. Hashable (HashSimple s) (TransactionBatch s)
, forall s. Hashable (HashSimple s) (TransactionBatchData s)
, forall s. Hashable (HashSimple s) ((Circuit :*: DAIndex :*: DAType) s)
type SignatureState bi bo ud a context =
( Symbolic context
, KnownRegistersAssetQuantity context
, Hashable (HashSimple context) (State bi bo ud a context)
, forall s. Hashable (HashSimple s) (State bi bo ud a s)
, Hashable (HashSimple context) ((Vector bi :.: Output a) context)
, Hashable (HashSimple context) ((Vector bo :.: Output a) context)
, Hashable (HashSimple context) (FieldElement context)
, forall s. Hashable (HashSimple s) (FieldElement s)
)
20 changes: 10 additions & 10 deletions symbolic-ledger/src/ZkFold/Symbolic/Ledger/Types/Address.hs
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
module ZkFold.Symbolic.Ledger.Types.Address (
Address,
nullAddress,
) where

import GHC.Generics ((:*:))

import ZkFold.Symbolic.Ledger.Types.Circuit (Circuit)
import ZkFold.Symbolic.Ledger.Types.DataAvailability
import ZkFold.Symbolic.Ledger.Types.Hash (Hash)
import ZkFold.Algebra.Class (Zero (..))
import ZkFold.Symbolic.Class (Symbolic)
import ZkFold.Symbolic.Data.FieldElement (FieldElement)
import Prelude hiding (Bool, Eq, length, splitAt, (*), (+))

-- | Address on the zkFold ledger.
--
-- Circuit describes the smart contract that locks funds at this address.
--
-- Data availability index points to a data availability source that posts data about the address's transactions. The data availability type indicates whether the address is associated with online or offline transactions.
type Address = Hash (Circuit :*: DAIndex :*: DAType)
type Address = FieldElement

-- | Null address.
nullAddress :: Symbolic context => Address context
nullAddress = zero
13 changes: 0 additions & 13 deletions symbolic-ledger/src/ZkFold/Symbolic/Ledger/Types/Circuit.hs

This file was deleted.

This file was deleted.

9 changes: 0 additions & 9 deletions symbolic-ledger/src/ZkFold/Symbolic/Ledger/Types/Datum.hs

This file was deleted.

2 changes: 1 addition & 1 deletion symbolic-ledger/src/ZkFold/Symbolic/Ledger/Types/Hash.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import ZkFold.Symbolic.Data.FieldElement (FieldElement)
import qualified ZkFold.Symbolic.Data.Hash as Symbolic.Hash

-- | Hash type used in the zkFold ledger.
type Hash = Symbolic.Hash.Hash FieldElement
type Hash = Symbolic.Hash.Hash HashSimple

-- TODO: Introduce a phantom type to track hash relation? Also should likely add strong typing than synonyms.

Expand Down
32 changes: 0 additions & 32 deletions symbolic-ledger/src/ZkFold/Symbolic/Ledger/Types/Interval.hs

This file was deleted.

28 changes: 0 additions & 28 deletions symbolic-ledger/src/ZkFold/Symbolic/Ledger/Types/Output.hs

This file was deleted.

Loading