Repository navigation
fix(provider): read the compiler version in the Sierra program in getContractVersion() - #1766
Merged
PhilippeR26 merged 1 commit intoNov 25, 2026
Conversation
Contributor
|
🎉 This PR is included in version 11.9.2 🎉 The release is available on: Your semantic-release bot 📦🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation and Resolution
provider.getContractVersion()(andContract.getVersion(), which calls it) guessed the compiler version of a Cairo 1 class from the shape of its abi:'2'when the abi has aninterfaceentry,'1'otherwise. A contract compiled by Cairo 2 has nointerfaceentry when it has no external function, or when it declares its functions one by one with#[external(v0)]. For such a contract, the answer was'1': wrong. Example:__mocks__/cairo/onlyConstructor(compiled by Cairo 2.8.2).The real version is in the class: the Cairo compiler writes it at the start of the Sierra program, and nodes return this program unchanged (the class hash is computed on it).
0x1, 0x6, 0x0, 0x2, 0x8, 0x2is Sierra 1.6.0, compiled by Cairo 2.8.2.'0.1.0', and holds no compiler version: it means compiler 1.getContractVersionnow reads the compiler major version there. A header it does not know (for example a future compiler 3.x) or cannot read givescompiler: undefined. It never throws, and never guesses.RPC version (if applicable)
N/A
Usage related changes
getContractVersion()/Contract.getVersion()returncompiler: '2'instead of'1'for a Cairo 2 contract with nointerfaceentry in its abi.compilerisundefinedfor a compiler unknown to this version of starknet.js, or for a Sierra program that cannot be read.undefinedwas already a possible value ofCompilerVersion.cairofield does not change, soAccount.getCairoVersion()behaves the same.cairo.getAbiContractVersion()is unchanged; its JSDoc now explains that its compiler version is a guess, and when it is wrong.Development related changes
__tests__/utils/contractVersion.test.ts(no node needed): Sierra headers of the fixtures, Sierra 0.1.0, unknown and unreadable headers, optioncompiler: false, Cairo 0 class.__tests__/defaultProvider.test.ts:getContractVersionononlyConstructor(declared withdeclareIfNot, on all targets), and on a Cairo 0 contract already deployed on Testnet and Mainnet, the legacy UDC (describeIfNotDevnet: devnet cannot run Cairo 0, and no network accepts a Cairo 0 declaration any more).Checklist: