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

Extending the ttl of a temporal storage to exisiting maximum live until ledger would always fail #1329

Closed
yanliu18 opened this issue Jan 17, 2024 · 2 comments · Fixed by #1413
Labels
bug Something isn't working

Comments

@yanliu18
Copy link

What version are you using?

20.1.0

What did you do?

Formal Auditting for Client Code

pub(crate) fn extend_ttl(

When call to the extend_ttl() function in host/storage, when the function parameter extend_to = li.max_entry_ttl (li.max_entry_ttl = host.with_ledger_info(|li| li.max_entry_ttl)) and parameter key matches ContractData(LedgerKeyContractData {_, _, StorageType::Temporal, }), the call to extend_ttl will always return an error.

This is because of the following condition checking where,
new_live_until = li_sequece_number + extend_to
host.max_live_until_ledger() = li_sequece_number + li.max_entry_ttl - 1
will always go to the else branch.

if new_live_until > host.max_live_until_ledger()? {
if let Some(durability) = get_key_durability(&key) {
if matches!(durability, ContractDataDurability::Persistent) {
new_live_until = host.max_live_until_ledger()?;
} else {
return Err(host.err(
ScErrorType::Storage,
ScErrorCode::InvalidAction,
"trying to extend past max live_until ledger",
&[new_live_until.into()],
));

What did you expect to see?

Though it is rare for a contract instance to set its temporal stroage to the exisiting max livable ledger sequence, it is still possible.
Maybe it is reasonable to calculate the new_live_until in the same way as the max_live_live_until_ledger.

@jayz22
Copy link
Contributor

jayz22 commented May 3, 2024

Thanks @yanliu18 for reporting this issue. Indeed some of the terminologies defined can be a little confusing.
You've brought up a couple good points worth clarifying:

  • The internal logic for calculating new_live_until is treating the input as "extend by" (not including the current ledger) where as the li.max_entry_ttl is being treated as number of ledgers to live including the current ledger.
  • The Temporary entry cannot be attempted to be extended past the ledger max, it throws error instead of being clamped to the max. This was an intentional design (@dmkozh gave a good explanation here) but it's worth clarifying in the documentation.

Although not a protocol bug, I think both of these points worth being clarified via better documentation, I will open a PR to do so.
The SDK has already been updated to make sure the max_entry_ttl getter takes care of the boundary offset: stellar/rs-soroban-sdk#1269, so that user can't trigger the error using it.

github-merge-queue bot pushed a commit that referenced this issue May 3, 2024
### What

Resolves #1329

### Why

[TODO: Why this change is being made. Include any context required to
understand the why.]

### Known limitations

[TODO or N/A]
@yanliu18
Copy link
Author

yanliu18 commented May 6, 2024

Thanks @yanliu18 for reporting this issue. Indeed some of the terminologies defined can be a little confusing. You've brought up a couple good points worth clarifying:

  • The internal logic for calculating new_live_until is treating the input as "extend by" (not including the current ledger) where as the li.max_entry_ttl is being treated as number of ledgers to live including the current ledger.
  • The Temporary entry cannot be attempted to be extended past the ledger max, it throws error instead of being clamped to the max. This was an intentional design (@dmkozh gave a good explanation here) but it's worth clarifying in the documentation.

Although not a protocol bug, I think both of these points worth being clarified via better documentation, I will open a PR to do so. The SDK has already been updated to make sure the max_entry_ttl getter takes care of the boundary offset: stellar/rs-soroban-sdk#1269, so that user can't trigger the error using it.

Thank you @jayz22 for addressing this issue and reply to us. The changes look good.
I shall let our team and clients know about this update.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants
@jayz22 @yanliu18 and others