-
Notifications
You must be signed in to change notification settings - Fork 1
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
Conversation
<instrs> hostCall ( "env" , "kasmer_set_ledger_timestamp" , [ i64 .ValTypes ] -> [ .ValTypes ] ) | ||
=> loadObject(HostVal(TIMESTAMP)) | ||
~> setLedgerTimestamp | ||
~> toSmall(Void) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 ScVal
s to HostVal
s. 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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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:
- projection cast on the list lookup result because
_ [_]
returnsKItem
:{VEC[I]}:>HostVal
- side condition to check the list item sort:
isHostVal(VEC[I])
preserves-definedness
attribute to avoid booster backend fallbacks (and manually check if it actually does)
This PR implements 5/11 of the remaining host functions needed for the FxDAO vaults contract:
get_ledger_timestamp
("x" "4"
)kasmer_set_ledger_timestamp
del_contract_data
("l" "2"
)vec_get
("v" "1"
)vec_len
("v" "3"
)vec_push_back
("v" "6"
)