Skip to content

Sigma protocols and v1 scripts#135

Open
vks4git wants to merge 52 commits intomainfrom
134-v1-scripts
Open

Sigma protocols and v1 scripts#135
vks4git wants to merge 52 commits intomainfrom
134-v1-scripts

Conversation

@vks4git
Copy link
Contributor

@vks4git vks4git commented Jan 2, 2026

No description provided.

@vks4git vks4git force-pushed the 134-v1-scripts branch 2 times, most recently from d322be2 to 77ba99a Compare January 28, 2026 06:47
@vks4git vks4git force-pushed the 134-v1-scripts branch 11 times, most recently from ec1f128 to bc1fcd1 Compare February 4, 2026 04:45
@vks4git vks4git marked this pull request as ready for review February 4, 2026 13:28
@vks4git vks4git changed the title WIP sigma protocols Sigma protocols and v1 scripts Feb 4, 2026
@vks4git vks4git requested a review from sourabhxyz February 4, 2026 13:32
deriving stock (Show, Generic)
deriving anyclass HasBlueprintDefinition

PlutusTx.Blueprint.TH.makeIsDataSchemaIndexed ''UserId [('UserId, 0)]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fine, but slightly less efficient. For newtype wrappers, we can essentially utilize newtype derivation for IsData and HasBlueprintDefinition as otherwise we are adding extra layer of Constr (from BuiltinData) on the value.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ToData, FromData and UnsafeFromData worked fine with newtype deriving.

For some reason deriving newtype HasBlueprintDefinition did not work. The compiler issued an error: UserId type was not found in the list of types having schema definitions: [<a list of types>]. Only deriving anyclass HasBlueprintDefinition works.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made a fix for it in #141.

instance ZkFold.Scale Natural G1 where
scale n = ZkFold.scale (naturalToInteger n)

instance ZkFold.Scale F G1 where
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this instance being used?


correctLengths = length v == 16 && length aut == 16

verified = and $ flip map (zip v aut) $ \(vi, auti) ->
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was discussing with AI about it and it suggested a vulnerability. Could you please take a look if it makes sense? Thank you.

Image

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does make sense, and it will probably make the script more efficient. Thanks!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree

newtype UserId = UserId { userId :: BuiltinByteString }
deriving stock (Show, Generic)
deriving newtype (ToData, FromData, UnsafeFromData)
deriving anyclass HasBlueprintDefinition
Copy link
Member

@sourabhxyz sourabhxyz Mar 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please see #141. You may want to manually bring in those changes as that PR is apparently having many duplicate commits.


slices = enumFromThenTo 0 2 30

is = fmap (\s -> byteStringToInteger BigEndian $ sliceByteString s (s + 2) digest) slices
Copy link
Member

@sourabhxyz sourabhxyz Mar 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sliceByteString s 2 digest instead as I think second argument is length (not the end index).


import ZkFold.Cardano.UPLC.Wallet.V0.Types (JWTParts (..), KeyId (..), OnChainWalletConfig (..))

data PubKey = PubKey { pubE :: Integer, pubN :: Integer }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I notice that we are never using pubE -- if a different public exponent is ever registered in a beacon, we would be silently ignoring it. Perhaps we need to assert pubE == 65537 or use myExpMod vi pubE pubN.


c = integerToByteString BigEndian 256 paddedHash

transcript = mconcat $ c : (integerToByteString BigEndian 256 <$> aut)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since transcript contains no transaction-specific data, it seems that the same RewardingRedeemer can be copied from a previous valid transaction and submitted again to spend funds from the same wallet (replay attack).
If so, I think we can add TxOutRef to RewardingRedeemer, then transcript could be transcript = mconcat $ c : (serialiseData (toBuiltinData txOutRef)) : (integerToByteString BigEndian 256 <$> aut).
We would need to see how efficient it is, but first let's agree on the vulnerability.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree. Previously, we tied a JWT to a temporary public key via ZK proof. Now, we need to add tx-specific data to the transcript.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants