Skip to content

Conversation

@colll78
Copy link
Collaborator

@colll78 colll78 commented Mar 14, 2025

Add new field to the DirectorySetNode,

data DirectorySetNode = DirectorySetNode
  { key :: CurrencySymbol
  , next :: CurrencySymbol
  , transferLogicScript  :: Credential
  , issuerLogicScript :: Credential
  , globalStateCS :: CurrencySymbol -- new field
  }
  deriving stock (Show, Eq, Generic)
  deriving anyclass (SOP.Generic)

Global State Currency Symbol: The currency symbol of an NFT that uniquely identifies a UTxO that contains the global state associated with the programmable token. This is optionally and can be set to the empty currency symbol if not needed.

@colll78 colll78 requested a review from j-mueller March 14, 2025 21:12
pvalidateConditions [pelem # mintingLogicCred # invokedScripts]
)

-- TODO:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Will this be part of this PR?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, but before implementing it I wanted to discuss with you and the others to see if this is reasonable. Basically, the issue is because the idea is that all programmable tokens will be minted with this same issuance script with only the parameter being different, and the parameter is the credential associated with a withdraw-zero script that contains the logic for minting that specific programmable token, the withdraw-zero script needs to know which minted token it is responsible for validating, but because the issuance script is parameterized by the withdraw-zero script, the withdraw-zero script cannot be parameterized by the issuance script, so it needs another way to figure out which minting policy it is responsible for. This approach uses the redeemer of the issuance script to provide that information to the minting logic script, another approach would be to provide the minting logic withdraw-zero script in the directory node so that the withdraw-zero script just needs the directory node as a reference input to know what policy id it is validating against.

prefixScriptBytes :: Term s PByteString
prefixScriptBytes = phexByteStr "deadbeef"

_pisProgrammableTokenRegistration :: Term s PCurrencySymbol -> Term s PByteString -> Term s (PValue 'Sorted 'NonZero) -> Term s PBool
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this going to be used for anything?

Copy link
Collaborator Author

@colll78 colll78 Mar 15, 2025

Choose a reason for hiding this comment

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

Yes, this will be used to ensure that only programmable tokens can be inserted into the directory. It enforces this via parameter validation, it validates that the inserted policy id is indeed an instance of the issuance script (and thus guarantees that the token can never be minted anywhere outside the programmableLogicBase script). I just need to add some tests to make sure parameter validation works correctly for all cases (because this trick relies on manipulation of the underlying script cbor hex, which is very finnicky with byte alignment etc.

pdeserializeCurrencySymbol :: Term s (PAsData PCurrencySymbol) -> Term s (PAsData PCurrencySymbol)
pdeserializeCurrencySymbol term =
plet (pasByteStr # pforgetData term) $ \bstr ->
pif (plengthBS # bstr #<= 28)
Copy link
Collaborator

@choener choener Mar 19, 2025

Choose a reason for hiding this comment

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

I thought this would have to be #== 28 for a currency symbol?
(Twice in this file)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The empty string is also a valid currency symbol.

Copy link
Collaborator

Choose a reason for hiding this comment

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

For Ada, right?
Ok, is there any scenario where it would be possible to craft a string of size 13, say? And does this break anything?

@j-mueller
Copy link
Collaborator

I'm happy with the changes. The conflicts are due to the compiled scripts being moved by the previous PR (#77 ). I'll try to sort it out.

@j-mueller j-mueller force-pushed the global-state-field branch from 8ea6851 to 48c4071 Compare March 20, 2025 11:40
@j-mueller j-mueller self-assigned this Mar 20, 2025
Copy link
Collaborator

@choener choener left a comment

Choose a reason for hiding this comment

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

Especially after yesterdays discussion, I agree with these changes.

@j-mueller j-mueller merged commit 3e02f83 into main Mar 20, 2025
5 checks passed
@j-mueller j-mueller deleted the global-state-field branch March 20, 2025 15:55
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.

4 participants