Removed old TEAL / updated README with VAA info

This commit is contained in:
Hernán Di Pietro 2021-11-04 15:33:06 -03:00
parent 2d711d1917
commit 37e0e17585
2 changed files with 28 additions and 225 deletions

View File

@ -64,6 +64,34 @@ For the stateful app-calls we consider,
* Passed guardian size set must match the current global state.
* Last TX in group triggers VAA processing according to fields (e.g: do governance chores, unpack Pyth price ticker, etc)
**VAA Structure**
VAA structure is defined in:
https://github.com/certusone/wormhole/blob/dev.v2/design/0001_generic_message_passing.md
Governance VAAs:
https://github.com/certusone/wormhole/blob/dev.v2/design/0002_governance_messaging.md
Sample Ethereum Struct Reference:
https://github.com/certusone/wormhole/blob/dev.v2/ethereum/contracts/Structs.sol
```
VAA
i Bytes Field
0 1 Version
1 4 GuardianSetIndex
5 1 LenSignatures (LN)
6 66*LN Signatures where each S = { guardianIndex (1),r(32),s(32),v(1) }
-------------------------------------< hashed/signed body starts here.
4 timestamp
4 Nonce
2 emitterChainId
32 emitterAddress
8 sequence
1 consistencyLevel
N payload
--------------------------------------< hashed/signed body ends here.
```
**VAA Commitment**
Each VAA is uniquely identified by tuple (emitter_chain_id, emitter_address, sequence). We are currently interested in VAAs for:

View File

@ -1,225 +0,0 @@
#pragma version 5
// ------------------------------------------------------------------------------------------------
//
// Core Wormhole TEAL Program
//
// (c) 2021 Randlabs, Inc.
//
// ------------------------------------------------------------------------------------------------
//
// This program allows us to:
// - Verify Wormhole' signed VAAs
// - Acknowledge change in validator sets
//
// (!) We dont support submitting VAAs.
//
// VAA structure is defined in:
// https://github.com/certusone/wormhole/blob/dev.v2/design/0001_generic_message_passing.md
//
// Governance VAAs:
// https://github.com/certusone/wormhole/blob/dev.v2/design/0002_governance_messaging.md
//
// Ethereum Struct Reference:
// https://github.com/certusone/wormhole/blob/dev.v2/ethereum/contracts/Structs.sol
//
// For the acceptVAA application call, we accept the following packed structure:
//
// VAA
// i Bytes Field
// 0 1 Version
// 1 4 GuardianSetIndex
// 5 1 LenSignatures (LN)
// 6 66*LN Signatures where each S = { guardianIndex (1),r(32),s(32),v(1) }
// -------------------------------------< hashed/signed body starts here.
// 4 timestamp
// 4 Nonce
// 2 emitterChainId
// 32 emitterAddress
// 8 sequence
// 1 consistencyLevel
// N payload
// --------------------------------------< hashed/signed body ends here.
//
// SLOTS:
// 0 Entire signed VAA
// 1 Parsed number of signatures.
// 2 Signature block
// 3 Size of all signatures (66 * N)
// 4 VAA Body hash
//
// -----------------------------------------------------------------------------------------
// Global state:
//
// "gsexptime": Guardian set expiration time
// "gssize" : Guardian set size (number of items)
// key N: address of guardian N
// -----------------------------------------------------------------------------------------
// Application creation.
int 0
txn ApplicationID
==
bnz handle_create
// Handle app call: validate signed VAAs
txn OnCompletion
int NoOp
==
bnz handle_call
// Handle deletion.
txn OnCompletion
int DeleteApplication
==
bnz success
// Fail otherwise
err
handle_create:
// -----------------------------------------------------
// Handle creation
// -----------------------------------------------------
b success
// -----------------------------------------------------
// Handle app call
// -----------------------------------------------------
handle_call:
// (!) Group size must be Maxed out to raise computational allowance
global GroupSize
int 16
==
assert
// if this is one of dummy transactions(0..14), exit with success
txn GroupIndex
int 15
!=
bnz success
// Retrieve signed VAA, store in slot 0
txn ApplicationArgs 0
store 0
// ------------------------------------------------------
// Verify VAA
// ------------------------------------------------------
// Check version
load 0
extract 0 1
btoi
int 1
==
assert
// Store num of signatures in slot 1
load 0
extract 5 1
btoi
dup
store 1
// Store signatures in slot 2, size of signatures in 3.
int 66
*
dup
store 3 // size of signatures (66*N)
load 0
swap
int 6
extract3 // extract msg from 66 * sig_count from byte 6
store 2
// Hash body
// Body starts at index 6 + (66*#Sig)
load 1
int 66
*
int 6
+
load 0
swap
int 0 // Stack has ...msgbyte, begin_of_body, 0 (extract all)
extract3
keccak256
store 4
// ----------------------------------------------------------------------------
// verify signature loop
// ----------------------------------------------------------------------------
load 2 // sig
// start
int 0 // sig index
store 128 // SLOT128: index
loop:
load 4 // hash
int 66 // hash sig index 66
* // hash sig (66*index)
int 66 // hash sig (66*i) 66
extract3 // hash S(i)
load 128
app_global_get // hash S(i) key(i)
edcsa_verify 0 // is_verified( h,S(i),k(i) )
int 1
==
assert
byte "gssize"
app_global_get // gssize
load 128 // gssize index
int 1 // gssize index 1
+ // gssize (index + 1)
dup // gssize (index + 1)(index + 1)
store 128 // SLOT 128: index+1
== // gssize == index + 1
bz loop
// All verified.
// ----------------------------------------------------------------------------
fail:
int 0
return
success:
int 1
return