Skip to content

Commit

Permalink
proof verification working
Browse files Browse the repository at this point in the history
  • Loading branch information
manojkgorle committed Jul 7, 2024
1 parent c3f33b0 commit bbfa5d5
Show file tree
Hide file tree
Showing 19 changed files with 1,099 additions and 146 deletions.
16 changes: 8 additions & 8 deletions blobstream-contracts-rust/src/input_type/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ sol!(
struct InitializerInput {
uint64 height;
bytes32 header;
bytes32 blobstreamProgramVKeyHash;
bytes blobstreamProgramVKeyHash;
bytes blobstreamProgramVKey;
}
struct UpdateFreezeInput{
Expand All @@ -24,18 +24,18 @@ sol!(
bytes32 header;
}
struct UpdateProgramVkeyInput{
bytes32 blobstreamProgramVKeyHash;
bytes blobstreamProgramVKeyHash;
bytes blobstreamProgramVKey;
}
struct CommitHeaderRangeInput {
bytes proof;
bytes publicValues;
}
struct VAInput {
uint256 tuple_root_nonce;
DataRootTuple tuple;
BinaryMerkleProof proof;
}
struct CommitHeaderRangeInput {
bytes proof;
bytes publicValues;
}
struct ProofOutputs {
bytes32 trustedHeaderHash;
bytes32 targetHeaderHash;
Expand All @@ -60,7 +60,7 @@ impl InitializerInput {
let init_input = unsafe { slice::from_raw_parts(ptr, (len as u16).into()) };
Self::abi_decode(init_input, true).unwrap()
}
pub fn unpack(&self) -> (u64, FixedBytes<32>, FixedBytes<32>, Vec<u8>) {
pub fn unpack(&self) -> (u64, FixedBytes<32>, Vec<u8>, Vec<u8>) {
(
self.height,
self.header.clone(),
Expand Down Expand Up @@ -95,7 +95,7 @@ impl UpdateProgramVkeyInput {
let init_input = unsafe { slice::from_raw_parts(ptr, (len as u16).into()) };
Self::abi_decode(init_input, true).unwrap()
}
pub fn unpack(&self) -> (FixedBytes<32>, Vec<u8>) {
pub fn unpack(&self) -> (Vec<u8>, Vec<u8>) {
(
self.blobstreamProgramVKeyHash.clone(),
self.blobstreamProgramVKey.clone(),
Expand Down
15 changes: 7 additions & 8 deletions blobstream-contracts-rust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const MAPPING_BLOCK_HEIGHT_TO_HEADER_HASH_ID: u32 = 1;
const MAPPING_STATE_DATA_COMMITMENTS_ID: u32 = 2;

// CONSTANT VARIABLES
const DATA_COMMITMENT_MAX: u64 = 10_000;
const DATA_COMMITMENT_MAX: u64 = 1_000;

#[cfg_attr(all(target_arch = "wasm32"), export_name = "initializer")]
#[no_mangle]
Expand All @@ -48,9 +48,9 @@ pub extern "C" fn initializer(tx_context: *const TxContext, ptr: *const u8, len:
state::store_mapping_u64_bytes32(MAPPING_BLOCK_HEIGHT_TO_HEADER_HASH_ID, height, header);
state::store_u256(STATIC_STATE_PROOFNONCE, U256::from(1));
state::store_address(STATIC_GUARDIAN, &msg_sender);
state::store_bytes32(
state::store_vec(
STATIC_BLOBSTREAM_PROGRAM_VKEY_HASH,
blobstream_program_vkey_hash,
&blobstream_program_vkey_hash,
);
state::store_vec(STATIC_BLOBSTREAM_PROGRAM_VKEY, &blobstream_program_vkey);
state::store_bool(STATIC_ISINITIALIZED, 1);
Expand Down Expand Up @@ -125,7 +125,7 @@ pub extern "C" fn update_program_vkey(
}

// msg_sender is the guardian, update program vkey.
state::store_bytes32(STATIC_BLOBSTREAM_PROGRAM_VKEY_HASH, program_vkey_hash);
state::store_vec(STATIC_BLOBSTREAM_PROGRAM_VKEY_HASH, &program_vkey_hash);
state::store_vec(STATIC_BLOBSTREAM_PROGRAM_VKEY, &program_vkey);

// Call executed without any errors, return true.
Expand All @@ -136,13 +136,12 @@ pub extern "C" fn update_program_vkey(
#[cfg_attr(all(target_arch = "wasm32"), export_name = "commit_header_range")]
#[no_mangle]
pub extern "C" fn commit_header_range(_: *const TxContext, ptr: *const u8, len: u32) -> bool {
// unpack proof and public values from CommitHeaderRangeInput.
let (proof, public_values) = CommitHeaderRangeInput::new(ptr, len).unpack();
// if contract is frozen or not initialized, return false.
if is_frozen() || !is_initialized() {
return false;
}

// unpack proof and public values from CommitHeaderRangeInput.
let (proof, public_values) = CommitHeaderRangeInput::new(ptr, len).unpack();
let (
po_trusted_header_hash,
target_header_hash,
Expand Down Expand Up @@ -172,7 +171,7 @@ pub extern "C" fn commit_header_range(_: *const TxContext, ptr: *const u8, len:
}

// fetch blobstream program vkey and program vkey hash from the state.
let blobstream_program_vkey_hash = state::get_bytes32(STATIC_BLOBSTREAM_PROGRAM_VKEY_HASH);
let blobstream_program_vkey_hash = state::get_vec(STATIC_BLOBSTREAM_PROGRAM_VKEY_HASH);
let blobstream_program_vkey = state::get_vec(STATIC_BLOBSTREAM_PROGRAM_VKEY);
// verify sp1 plonk proof.
if precompiles::gnark_verify(
Expand Down
99 changes: 93 additions & 6 deletions go.work.sum

Large diffs are not rendered by default.

Binary file removed input-types-test/blobstream_contracts_rust.wasm
Binary file not shown.
30 changes: 19 additions & 11 deletions input-types-test/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ go 1.22
toolchain go1.22.2

require (
github.com/AnomalyFi/hypersdk v0.0.0-00010101000000-000000000000
github.com/consensys/gnark v0.10.1-0.20240504023521-d9bfacd7cb60
github.com/consensys/gnark-crypto v0.12.2-0.20240504013751-564b6f724c3b
github.com/ethereum/go-ethereum v1.13.14
Expand All @@ -25,32 +26,39 @@ require (

require (
github.com/Microsoft/go-winio v0.6.1 // indirect
github.com/StackExchange/wmi v1.2.1 // indirect
github.com/ava-labs/avalanchego v1.11.6 // indirect
github.com/bits-and-blooms/bitset v1.10.0 // indirect
github.com/btcsuite/btcd/btcec/v2 v2.2.0 // indirect
github.com/btcsuite/btcd/btcec/v2 v2.3.2 // indirect
github.com/btcsuite/btcd/btcutil v1.1.3 // indirect
github.com/consensys/bavard v0.1.13 // indirect
github.com/crate-crypto/go-kzg-4844 v0.7.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/deckarep/golang-set/v2 v2.1.0 // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.1 // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.1.0 // indirect
github.com/ethereum/c-kzg-4844 v0.4.0 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/go-ole/go-ole v1.3.0 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/gorilla/websocket v1.4.2 // indirect
github.com/google/renameio/v2 v2.0.0 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/gorilla/websocket v1.5.0 // indirect
github.com/holiman/uint256 v1.2.4 // indirect
github.com/mmcloughlin/addchain v0.4.0 // indirect
github.com/mr-tron/base58 v1.2.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible // indirect
github.com/shirou/gopsutil v3.21.11+incompatible // indirect
github.com/supranational/blst v0.3.11 // indirect
github.com/tklauser/go-sysconf v0.3.12 // indirect
github.com/tklauser/numcpus v0.6.1 // indirect
golang.org/x/crypto v0.17.0 // indirect
golang.org/x/exp v0.0.0-20231110203233-9a3e6036ecaa // indirect
github.com/yusufpapurcu/wmi v1.2.2 // indirect
go.uber.org/mock v0.4.0 // indirect
golang.org/x/crypto v0.21.0 // indirect
golang.org/x/exp v0.0.0-20231127185646-65229373498e // indirect
golang.org/x/mod v0.14.0 // indirect
golang.org/x/sync v0.5.0 // indirect
golang.org/x/sys v0.16.0 // indirect
golang.org/x/tools v0.15.0 // indirect
golang.org/x/sync v0.6.0 // indirect
golang.org/x/sys v0.18.0 // indirect
golang.org/x/tools v0.17.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
rsc.io/tmplfunc v0.0.3 // indirect
)

replace github.com/AnomalyFi/hypersdk => ../../hypersdk
Loading

0 comments on commit bbfa5d5

Please sign in to comment.