-
Notifications
You must be signed in to change notification settings - Fork 9
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
Wrong constant value in the signers.clar boot contract #370
Comments
I think that it's same issue but with another use case, in the pox-4 contract we use an expression to define the STACKING_THRESHOLD constant, it evaluates to 0 in WASM (define-constant STACKING_THRESHOLD_25 (if is-in-mainnet u20000 u8000))
(define-read-only (get-st25)
STACKING_THRESHOLD_25
) In because the contract also does (define-read-only (get-stacking-minimum)
(/ stx-liquid-supply STACKING_THRESHOLD_25)) it leads to a division by zero when we call |
So, after a little bit of investigation, the bug is caused by the fact that a constant which is not a literal value is not evaluated if it's called from inside a function. This is because in this case, We have to make sure that an accessed constant has been evaluated first. Here is a simple way to reproduce the bug in the clar2wasm-tests package:
(define-constant FOO (+ 1 1))
(define-public (get-constant)
(ok FOO)
)
test_contract_call_response!(
test_contract_constant_expr,
"constant-expr",
"get-constant",
|response: ResponseData| {
assert!(response.committed);
assert_eq!(*response.data, Value::some(Value::Int(2)).unwrap());
}
); |
Our |
Since it's urgent for the task stated above, I will unassign myself so that anyone can take it. |
@Acaccia I've started checking this issue and wrote the following test case: #[test]
fn test_not_literal_constant_inside_function() {
crosscheck("
(define-constant not-literal-foo (* u6 u7))
(define-public (get-not-literal-foo)
(ok not-literal-foo))
(get-not-literal-foo)
",
evaluate("(ok u42)"),
);
} It is running ok. Is this issue really a constant evaluation problem? |
You cannot use crosscheck for this: the top-level function will always be computed before calling your constant, so it will always be defined, and a call will always succeed. This defines the purpose of this issue, where a call from another contract to a function using a constant has the constant not defined. |
The signers.clar boot contracts has this function
When calling this method with clarinet console with --enable-clarity-wasm, it returns a chunk-size of 0.
I tried it with my local build of clarinet that has the latest clar2wasm version (from the
main
branch).The text was updated successfully, but these errors were encountered: