Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remaining host functions for FxDAO: 5/11 #43

Merged
merged 8 commits into from
Nov 5, 2024
Merged

Conversation

bbyalcinkaya
Copy link
Member

This PR implements 5/11 of the remaining host functions needed for the FxDAO vaults contract:

  • get_ledger_timestamp ("x" "4")
    • also implemented a cheat function for setting the timestamp: kasmer_set_ledger_timestamp
  • del_contract_data ("l" "2")
  • vec_get ("v" "1")
  • vec_len ("v" "3")
  • vec_push_back ("v" "6")

@bbyalcinkaya bbyalcinkaya changed the title Fxdao hostcalls Remaining host functions for FxDAO: 5/11 Oct 29, 2024
@bbyalcinkaya bbyalcinkaya marked this pull request as ready for review October 29, 2024 19:54
<instrs> hostCall ( "env" , "kasmer_set_ledger_timestamp" , [ i64 .ValTypes ] -> [ .ValTypes ] )
=> loadObject(HostVal(TIMESTAMP))
~> setLedgerTimestamp
~> toSmall(Void)

Choose a reason for hiding this comment

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

@bbyalcinkaya, could you please elaborate a bit on the presence of toSmall at the end of the rewriting operation? After going through its implementation, it is not immediately clear to me why we should leave it at the K cell at the end of certain operations.

Choose a reason for hiding this comment

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

My current understanding is that it is working as some sort of a return value for this host function (as in it is returning nothing, in this case), but I'd like to double check.

Copy link
Member Author

Choose a reason for hiding this comment

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

@ACassimiro That's correct, it is used as a return value here. toSmall converts ScVals to HostVals. When a HostVal is on top of the <instrs> cell, it is executed as i64.const _ instruction: rule.

syntax InternalInstr ::= "vecGet" [symbol(vecGet)]
// ----------------------------------------------------
rule [vecGet]:
<instrs> vecGet => VEC {{ I }} orDefault HostVal(0) ... </instrs> // use 'orDefault' to avoid non-total list lookup

Choose a reason for hiding this comment

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

@bbyalcinkaya could you please elaborate on how orDefault operates here? And how it is used to avoid a scenario of non-total list lookup? I'm not entirely familiar with this production, so if you have a reference for me to take a deeper look into it, it would be more than enough.

Copy link
Member Author

Choose a reason for hiding this comment

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

It is a typed and total list lookup defined here. It returns the default value if the index is out of bounds or the list item at that index is not a HostVal.

I could've used the normal list lookup but that would require:

  1. projection cast on the list lookup result because _ [_] returns KItem: {VEC[I]}:>HostVal
  2. side condition to check the list item sort: isHostVal(VEC[I])
  3. preserves-definedness attribute to avoid booster backend fallbacks (and manually check if it actually does)

@rv-jenkins rv-jenkins merged commit c94a4be into master Nov 5, 2024
3 checks passed
@rv-jenkins rv-jenkins deleted the fxdao-hostcalls branch November 5, 2024 15:42
@bbyalcinkaya bbyalcinkaya mentioned this pull request Nov 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants