Skip to content

[Soroban] Linked support for block.number on soroban#1939

Merged
Islam-Imad merged 3 commits into
hyperledger-solang:mainfrom
slash-aech:harsh
Jul 17, 2026
Merged

[Soroban] Linked support for block.number on soroban#1939
Islam-Imad merged 3 commits into
hyperledger-solang:mainfrom
slash-aech:harsh

Conversation

@slash-aech

@slash-aech slash-aech commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Closes #1937

Contents

Added following features from pull 1921
modified: src/codegen/mod.rs
modified: src/codegen/targets/soroban/mod.rs

added arm to lower_builtin (mirror of GetAddress with optimizations removed)
modified: src/emit/soroban/mod.rs

Added tests from pull 1921 + 2 extra boundary variables
modified: tests/soroban_testcases/mod.rs
new file: tests/soroban_testcases/block_number.rs

Compliant with

cargo build
cargo test
cargo clippy (only related to this pr)
cargo fmt

Pleas do let me know if anything seems out of place #

@slash-aech
slash-aech marked this pull request as ready for review July 16, 2026 15:09
Comment thread src/codegen/targets/soroban/mod.rs Outdated
Some(address_var)
}
ast::Builtin::BlockNumber => {
let block_var_no = vartab.temp_anonymous(&Type::Uint(64));

@Islam-Imad Islam-Imad Jul 17, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I prefer to use vartab.temp_name("block_number", ...)
it help us when we debug the CFG.

Comment thread src/codegen/targets/soroban/mod.rs Outdated
Comment on lines +347 to +350
//decoding to uint64 since get_ledger_sequence returns
let decoded_block_number =
soroban_decode_arg(block_var, cfg, vartab, ns, Some(Type::Uint(64)));
Some(decoded_block_number)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

also here since we can directly pack the function call inside Some instead of using a variable it will be better.

@Islam-Imad

Copy link
Copy Markdown
Contributor

We just need some minor changes.
overall LGTM
nice work @slash-aech

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Adds Soroban support for block.number by wiring the Soroban host function for ledger sequence into the codegen lowering path, and validates behavior with a dedicated Soroban testcase. This aligns Soroban’s block.number semantics with Stellar’s ledger sequence number per issue #1937.

Changes:

  • Add HostFunctions::GetLedgerSequence ("x.3") and declare it as an external Soroban host function.
  • Lower ast::Builtin::BlockNumber in SorobanTarget::lower_builtin via GetLedgerSequence + Soroban value decoding to uint64.
  • Add Soroban tests to exercise block.number across multiple ledger sequence samples.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
tests/soroban_testcases/mod.rs Registers the new Soroban block number testcase module.
tests/soroban_testcases/block_number.rs New test validating block.number maps to ledger sequence on Soroban.
src/emit/soroban/mod.rs Declares the new Soroban host function signature and adds it to extern declarations.
src/codegen/targets/soroban/mod.rs Lowers block.number via GetLedgerSequence and decodes to uint64.
src/codegen/mod.rs Adds GetLedgerSequence to HostFunctions and maps it to "x.3".

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/codegen/targets/soroban/mod.rs Outdated
args: vec![],
},
);
//decoding to uint64 since get_ledger_sequence returns

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

i don't think we need to add comment here, code is short and clear.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thank you for the review
Lemme apply those changes and commit again. Gimme a min

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ping me when u update the pr

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@Islam-Imad I've made the changes accordingly

@Islam-Imad Islam-Imad left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@Islam-Imad Islam-Imad self-assigned this Jul 17, 2026
@slash-aech

Copy link
Copy Markdown
Contributor Author

Let me check the changes and see where the code fails. I'll mitigate and update

@Islam-Imad

Copy link
Copy Markdown
Contributor

Let me check the changes and see where the code fails. I'll mitigate and update

i think its github issue , i triggered the rerun for the failed job

@Islam-Imad
Islam-Imad enabled auto-merge July 17, 2026 15:08
@Islam-Imad
Islam-Imad disabled auto-merge July 17, 2026 15:17
Signed-off-by: slash-aech <harshitbenke@proton.me>
removed comments, changed variable type and removed redudant variable returning
Signed-off-by: slash-aech <harshitbenke@proton.me>
Signed-off-by: slash-aech <harshitbenke@proton.me>
@Islam-Imad
Islam-Imad merged commit 6c94109 into hyperledger-solang:main Jul 17, 2026
11 of 15 checks passed
@Islam-Imad

Copy link
Copy Markdown
Contributor

thanks @slash-aech

@slash-aech
slash-aech deleted the harsh branch July 18, 2026 07:16
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.

Support block.number on Soroban (ledger sequence)

3 participants