Comments (3)
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.
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:
- Add the contract constant-expr.clar with this content:
(define-constant FOO (+ 1 1))
(define-public (get-constant)
(ok FOO)
)
- 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.
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)
- issue with uint subtraction HOT 3
- var-get should throw a runtime error if variable does not exist
- principal-of? should throw a runtime error
- secp256k1-recover? should throw a runtime error
- secp256k1-verify runtime error handling
- add value to ShortReturnType runtime error
- Compilation errors handling
- Stdlib `$is-valid-string-ascii" does not account for all characters
- Validate `define-x` names
- Wrong evaluation order for tuples
- Crosscheck for `replace-at` fails too often due to `ValueTooLarge`
- Testing: `evaluate` and `interpret` should give access to the events
- Improve unit tests coverage for stx-transfer-memo? function HOT 4
- Improve unit tests for token functions HOT 1
- New bottom-up typechecker directly integrated inside the compiler
- OOM issues with `print`
- Separate clar2wasm into the compiler and the runtime
- Function `map` can provoke OOM
- The type workaround provokes errors in `append`
- Incorrect error code returned from `secp256k1-recover?`
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from clarity-wasm.