Skip to content

Commit

Permalink
Merge pull request #33 from Chia-Mine/v2.0.0
Browse files Browse the repository at this point in the history
V2.0.0
  • Loading branch information
ChiaMineJP authored Jul 20, 2022
2 parents 8a27f56 + 8c59141 commit bdf6d28
Show file tree
Hide file tree
Showing 13 changed files with 53 additions and 32 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# Changelog

## [2.0.0]
This version is compatible with [`fc73cd9dc2fc30a1fd461d0f05af9f9679e042c8`](https://github.com/Chia-Network/clvm/tree/fc73cd9dc2fc30a1fd461d0f05af9f9679e042c8) of [clvm](https://github.com/Chia-Network/clvm)

### Breaking Change
The behaviour of `op_div` has changed. See detailed explanation [here](https://www.chia.net/2022/03/04/divided-we-fork.en.html)

### Changed
- Made `op_div` bug-compatible with `clvm_rs`
- Replaced npm package `@chiamine/bls-signatures` with `bls-signatures`

## [1.0.9]
This version is compatible with [`389efa3fbe65c77600da63c78d29c0866d292754`](https://github.com/Chia-Network/clvm/tree/389efa3fbe65c77600da63c78d29c0866d292754) of [clvm](https://github.com/Chia-Network/clvm)

Expand Down Expand Up @@ -245,6 +255,7 @@ At this version, I've managed to improve test complete time to `79s` -> `2s` by
Initial (beta) release.

<!--[Unreleased]: https://github.com/Chia-Mine/clvm-js/compare/v0.0.1...v0.0.2-->
[2.0.0]: https://github.com/Chia-Mine/clvm-js/compare/v1.0.9...v2.0.0
[1.0.9]: https://github.com/Chia-Mine/clvm-js/compare/v1.0.8...v1.0.9
[1.0.8]: https://github.com/Chia-Mine/clvm-js/compare/v1.0.7...v1.0.8
[1.0.7]: https://github.com/Chia-Mine/clvm-js/compare/v1.0.6...v1.0.7
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ If you find something not compatible with Python's clvm, please report it to Git

## Compatibility
This code is compatible with:
- [`389efa3fbe65c77600da63c78d29c0866d292754`](https://github.com/Chia-Network/clvm/tree/389efa3fbe65c77600da63c78d29c0866d292754) of [clvm](https://github.com/Chia-Network/clvm)
- [Diff to the latest clvm](https://github.com/Chia-Network/clvm/compare/389efa3fbe65c77600da63c78d29c0866d292754...main)
- [`f9db7faa370c4743e48be8a9823232e4d906c4d0`](https://github.com/Chia-Network/bls-signatures/tree/f9db7faa370c4743e48be8a9823232e4d906c4d0) of [bls-signatures](https://github.com/Chia-Network/bls-signatures)
- [Diff to the latest bls-signatures](https://github.com/Chia-Network/bls-signatures/compare/f9db7faa370c4743e48be8a9823232e4d906c4d0...main)
- [`fc73cd9dc2fc30a1fd461d0f05af9f9679e042c8`](https://github.com/Chia-Network/clvm/tree/fc73cd9dc2fc30a1fd461d0f05af9f9679e042c8) of [clvm](https://github.com/Chia-Network/clvm)
- [Diff to the latest clvm](https://github.com/Chia-Network/clvm/compare/fc73cd9dc2fc30a1fd461d0f05af9f9679e042c8...main)
- [`34f504bd0ef2cd3a219fea8ce6b15ff7684687fd`](https://github.com/Chia-Network/bls-signatures/tree/34f504bd0ef2cd3a219fea8ce6b15ff7684687fd) of [bls-signatures](https://github.com/Chia-Network/bls-signatures)
- [Diff to the latest bls-signatures](https://github.com/Chia-Network/bls-signatures/compare/34f504bd0ef2cd3a219fea8ce6b15ff7684687fd...main)

## Example
```javascript
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "clvm",
"version": "1.0.9",
"version": "2.0.0",
"author": "ChiaMineJP <[email protected]>",
"description": "Javascript implementation of chia lisp",
"license": "MIT",
Expand All @@ -25,7 +25,7 @@
"node": ">=12.13.0"
},
"dependencies": {
"@chiamine/bls-signatures": "^0.2.1-beta.2",
"bls-signatures": "^1.0.14",
"jscrypto": "^1.0.2"
},
"devDependencies": {
Expand Down
6 changes: 3 additions & 3 deletions pre_build.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const fs = require("fs");
// clean and create output dir
const distDir = path.join(__dirname, ".dist");
if(fs.existsSync(distDir)){
fs.rmdirSync(distDir, {recursive: true});
fs.rmSync(distDir, {recursive: true});
}
fs.mkdirSync(distDir);
const distNpmDir = path.join(distDir, "npm");
Expand All @@ -13,10 +13,10 @@ fs.mkdirSync(distNpmDir);
// Copy wasm file
const browserDir = path.join(distNpmDir, "browser");
if(fs.existsSync(browserDir)){
fs.rmdirSync(browserDir, {recursive: true});
fs.rmSync(browserDir, {recursive: true});
}
fs.mkdirSync(browserDir);
const blsWasmSrcPath = path.join(__dirname, "node_modules", "@chiamine", "bls-signatures", "blsjs.wasm");
const blsWasmSrcPath = path.join(__dirname, "node_modules", "bls-signatures", "blsjs.wasm");
const blsWasmDestPath = path.join(browserDir, "blsjs.wasm");
if(!fs.existsSync(blsWasmSrcPath)){
console.error("blsjs.wasm not found at:");
Expand Down
2 changes: 1 addition & 1 deletion src/SExp.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {G1Element} from "@chiamine/bls-signatures";
import {G1Element} from "bls-signatures";
import {None, Optional} from "./__python_types__";
import {CLVMObject, CLVMType} from "./CLVMObject";
import {Bytes, isIterable, Tuple, t, Stream, isBytes, isTuple} from "./__type_compatibility__";
Expand Down
2 changes: 1 addition & 1 deletion src/__bls_signatures__/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type {G1Element as G1ElementType, ModuleInstance} from "@chiamine/bls-signatures";
import type {G1Element as G1ElementType, ModuleInstance} from "bls-signatures";
import * as blsLoader from "./loader";

type TCreateModule = () => Promise<ModuleInstance>;
Expand Down
2 changes: 1 addition & 1 deletion src/__bls_signatures__/loader.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import type {ModuleInstance} from "@chiamine/bls-signatures";
import type {ModuleInstance} from "bls-signatures";
type TCreateModule = () => Promise<ModuleInstance>;
export default TCreateModule;
2 changes: 1 addition & 1 deletion src/__bls_signatures__/loader.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
const createModuleInstance = require("@chiamine/bls-signatures");
const createModuleInstance = require("bls-signatures");
module.exports = createModuleInstance;
3 changes: 1 addition & 2 deletions src/__type_compatibility__.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ import {Utf8} from "jscrypto/Utf8";
import {Word32Array} from "jscrypto/Word32Array";
import {SHA256} from "jscrypto/SHA256";
import {None} from "./__python_types__";
import {G1Element} from "@chiamine/bls-signatures";
import {bigint_from_bytes} from "./casts";
import {G1Element} from "bls-signatures";

export function to_hexstr(r: Uint8Array) {
return (new Word32Array(r)).toString();
Expand Down
11 changes: 10 additions & 1 deletion src/more_ops.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,16 @@ export function op_div(args: SExp){
throw new EvalError("div with 0", SExp.to(i0));
}
cost += (l0+l1)*DIV_COST_PER_BYTE;
const q = division(i0, i1); // i0 / i1
const divmod_result = divmod(i0, i1) as Tuple<bigint, bigint>;
let q = divmod_result[0];
const r = divmod_result[1];

// this is to preserve a buggy behavior from the initial implementation
// of this operator.
if (q === BigInt(-1) && r !== BigInt(0)) {
q += BigInt(1);
}

return malloc_cost(cost, SExp.to(q));
}

Expand Down
18 changes: 10 additions & 8 deletions src/serialize.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
/*
decoding:
read a byte
if it's 0xfe, it's nil (which might be same as 0)
if it's 0x80, it's nil (which might be same as 0)
if it's 0xff, it's a cons box. Read two items, build cons
otherwise, number of leading set bits is length in bytes to read size
0-0x7f are literal one byte values
leading bits is the count of bytes to read of size
0x80-0xbf is a size of one byte (perform logical and of first byte with 0x3f to get size)
0xc0-0xdf is a size of two bytes (perform logical and of first byte with 0x1f)
0xe0-0xef is 3 bytes ((perform logical and of first byte with 0xf))
0xf0-0xf7 is 4 bytes ((perform logical and of first byte with 0x7))
0xf7-0xfb is 5 bytes ((perform logical and of first byte with 0x3))
For example, if the bit fields of the first byte read are:
10xx xxxx -> 1 byte is allocated for size_byte, and the value of the size is 00xx xxxx
110x xxxx -> 2 bytes are allocated for size_byte, and the value of the size 000x xxxx xxxx xxxx
1110 xxxx -> 3 bytes allocated. The size is 0000 xxxx xxxx xxxx xxxx xxxx
1111 0xxx -> 4 bytes allocated.
1111 10xx -> 5 bytes allocated.
If the first byte read is one of the following:
1000 0000 -> 0 bytes : nil
0000 0000 -> 1 byte : zero (b'\x00')
*/
import {SExp} from "./SExp";
import {Bytes, Stream, t} from "./__type_compatibility__";
Expand Down
2 changes: 1 addition & 1 deletion tests/as_javascript_test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {SExp, t, h, b, Bytes, getBLSModule, initialize, None, Tuple, list, str, repr} from "../src";
import {CLVMObject} from "../src/CLVMObject";
import {EvalError} from "../src/EvalError";
import type {ModuleInstance} from "@chiamine/bls-signatures";
import type {ModuleInstance} from "bls-signatures";

let BLS: ModuleInstance;

Expand Down
14 changes: 7 additions & 7 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -323,13 +323,6 @@
resolved "https://registry.yarnpkg.com/@bcoe/v8-coverage/-/v8-coverage-0.2.3.tgz#75a2e8b51cb758a7553d6804a5932d7aace75c39"
integrity sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw==

"@chiamine/bls-signatures@^0.2.1-beta.2":
version "0.2.1-beta.2"
resolved "https://registry.yarnpkg.com/@chiamine/bls-signatures/-/bls-signatures-0.2.1-beta.2.tgz#6ce2ef0b2ed76bf1e650bc93ba2640e69c3240b1"
integrity sha512-Pd7ZHvn4ao5UX1DwxWofat/xLwo2TGeAY7HdhJ3YHtXQxsfHJS1OirCTGjO6cx/miW57pAXW7pwlXYQXo67paw==
dependencies:
binascii "0.0.2"

"@discoveryjs/json-ext@^0.5.0":
version "0.5.3"
resolved "https://registry.yarnpkg.com/@discoveryjs/json-ext/-/json-ext-0.5.3.tgz#90420f9f9c6d3987f176a19a7d8e764271a2f55d"
Expand Down Expand Up @@ -1188,6 +1181,13 @@ [email protected]:
resolved "https://registry.yarnpkg.com/binascii/-/binascii-0.0.2.tgz#a7f8a8801dbccf8b1756b743daa0fee9e2d9e0ee"
integrity sha1-p/iogB28z4sXVrdD2qD+6eLZ4O4=

bls-signatures@^1.0.14:
version "1.0.14"
resolved "https://registry.yarnpkg.com/bls-signatures/-/bls-signatures-1.0.14.tgz#cfd735d2241e244b187cf28c37b19181894c8732"
integrity sha512-QDPMfwetbfjwijtgmfrQ+VZc0hItMDopmhSfkDVDdlk10nHm1v0sQMc+CULKYbmaOT/8HZBOAHWlbWe89cqNYA==
dependencies:
binascii "0.0.2"

brace-expansion@^1.1.7:
version "1.1.11"
resolved "https://registry.yarnpkg.com/brace-expansion/-/brace-expansion-1.1.11.tgz#3c7fcbf529d87226f3d2f52b966ff5271eb441dd"
Expand Down

0 comments on commit bdf6d28

Please sign in to comment.