Skip to content
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

support dynamic params #41

Open
wants to merge 20 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
support dynamic params and passed signature check
  • Loading branch information
xgaozoyoe committed Dec 19, 2024

Verified

This commit was signed with the committer’s verified signature.
AmorfEvo Imre Hajagos
commit 539b99a23564fed1d4f65dc1d28222b047edbb30
13 changes: 9 additions & 4 deletions abi/src/lib.rs
Original file line number Diff line number Diff line change
@@ -275,11 +275,17 @@ macro_rules! create_zkwasm_apis {
let trace = unsafe {wasm_trace_size()};
zkwasm_rust_sdk::dbg!("trace after initialize: {}\n", trace);

let cmdlen = $T::command_length();

for _ in 0..tx_length {
let mut params = Vec::with_capacity(20 + cmdlen);
for _ in 0..(20 + cmdlen) {
let mut params = Vec::with_capacity(20 + 16);
for _ in 0..20 {
params.push(unsafe {wasm_input(0)});
}
let command = unsafe {wasm_input(0)};
let command_length = ((command & 0xff00) >> 8) as usize;
unsafe { zkwasm_rust_sdk::require(command_length < 16) };
params.push(command);
for _ in 0..command_length - 1 {
params.push(unsafe {wasm_input(0)});
}
verify_tx_signature(params.clone());
@@ -288,7 +294,6 @@ macro_rules! create_zkwasm_apis {
zkwasm_rust_sdk::dbg!("trace track: {}\n", trace);
}


unsafe { zkwasm_rust_sdk::require(preempt()) };

let bytes = finalize();
2 changes: 1 addition & 1 deletion example/Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
build:
wasm-pack build --release --out-name application --out-dir pkg
wasm-opt -Oz -o ../ts/src/application/application_bg.wasm pkg/application_bg.wasm
#cp pkg/application_bg.wasm ../ts/src/application/application_bg.wasm
cp pkg/application_bg.wasm ../ts/src/application/application_bg.wasm
cp pkg/application.d.ts ../ts/src/application/application.d.ts
cp pkg/application_bg.js ../ts/src/application/application_bg.js
cp pkg/application_bg.wasm.d.ts ../ts/src/application/application_bg.wasm.d.ts
3 changes: 0 additions & 3 deletions example/src/state.rs
Original file line number Diff line number Diff line change
@@ -86,9 +86,6 @@ const ERROR_PLAYER_ALREADY_EXIST: u32 = 1;
const ERROR_PLAYER_NOT_EXIST: u32 = 2;

impl Transaction {
pub fn command_length() -> usize {
4
}
pub fn decode_error(e: u32) -> &'static str {
match e {
ERROR_PLAYER_NOT_EXIST => "PlayerNotExist",
9 changes: 5 additions & 4 deletions ts/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion ts/package.json
Original file line number Diff line number Diff line change
@@ -11,7 +11,7 @@
"@types/sync-fetch": "^0.4.3",
"bullmq": "^5.7.9",
"cors": "^2.8.5",
"delphinus-curves": "git+https://github.com/DelphinusLab/delphinus-curves.git#yyu/hybridPackage",
"delphinus-curves": "github:DelphinusLab/delphinus-curves#xgao",
"dotenv": "^16.4.5",
"ethers": "^6.13.1",
"express": "^4.19.2",
Binary file modified ts/src/application/application_bg.wasm
Binary file not shown.
30 changes: 0 additions & 30 deletions ts/src/query.ts

This file was deleted.

6 changes: 6 additions & 0 deletions ts/src/run.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { Service } from "./service.js";

const service = new Service(()=>{return;});
service.initialize();
service.serve();

19 changes: 11 additions & 8 deletions ts/src/service.ts
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@
import initBootstrap, * as bootstrap from "./bootstrap/bootstrap.js";
import initApplication, * as application from "./application/application.js";
import { test_merkle_db_service } from "./test.js";
import { verifySign, LeHexBN, sign } from "zkwasm-minirollup-rpc";
import { verifySign, LeHexBN, sign, PlayerConvention, ZKWasmAppRpc } from "zkwasm-minirollup-rpc";
import { Queue, Worker, Job } from 'bullmq';
import IORedis from 'ioredis';
import express from 'express';
@@ -251,6 +251,7 @@ export class Service {
}, 5000); // Change the interval as needed (e.g., 5000ms for every 5 seconds)
}

let admin = new PlayerConvention(get_server_admin_key(), new ZKWasmAppRpc(""), 0n, 0n);

this.worker = new Worker('sequencer', async job => {
if (job.name == 'autoJob') {
@@ -265,8 +266,10 @@ export class Service {
});
seed = randRecord[0].seed!.readBigInt64LE();
};
let signature = sign(new BigUint64Array([0n, seed, rand, 0n]), get_server_admin_key());
let signature = sign(admin.createCommand(0n, 0n, [seed, rand, 0n, 0n]), get_server_admin_key());
console.log("signautre is", signature);
let u64array = signature_to_u64array(signature);
application.verify_tx_signature(u64array);
application.handle_tx(u64array);
await this.install_transactions(signature, job.id);
} catch (error) {
@@ -425,11 +428,11 @@ function signature_to_u64array(value: any) {
const sigr = new LeHexBN(value.sigr).toU64Array();

let u64array = new BigUint64Array(24);
u64array.set(msg);
u64array.set(pkx, 4);
u64array.set(pky, 8);
u64array.set(sigx, 12);
u64array.set(sigy, 16);
u64array.set(sigr, 20);
u64array.set(pkx, 0);
u64array.set(pky, 4);
u64array.set(sigx, 8);
u64array.set(sigy, 12);
u64array.set(sigr, 16);
u64array.set(msg, 20);
return u64array;
}