GithubHelp home page GithubHelp logo

Comments (3)

hugocaillard avatar hugocaillard commented on May 27, 2024

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 get-stacking-minimum or get-pox-info (which the new boot contract signers-voting.clar does, so it can't be deployed in clar2wasm)

from clarity-wasm.

Acaccia avatar Acaccia commented on May 27, 2024

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, .top-level is not evaluated.

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:

  1. Add the contract constant-expr.clar with this content:
(define-constant FOO (+ 1 1))

(define-public (get-constant)
	(ok FOO)
)
  1. Add in lib_tests.rs this test:
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());
    }
);

from clarity-wasm.

Acaccia avatar Acaccia commented on May 27, 2024

Our traverse function for define-constant should also handle other cases than literal values at compile time, like atoms for reserved variables (e.g. tx-sender).

from clarity-wasm.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.