Skip to content

Commit

Permalink
txn: add FD_TXN_MIN_SERIALIZED_SZ
Browse files Browse the repository at this point in the history
Adds constant for minimum serialized txn size.

Adds CBMC proof for lower bound, i.e.:
"There is no byte array with sz <= FD_TXN_MIN_SERIALIZED_SZ that
is successfully parsed by fd_txn_parse()."
  • Loading branch information
riptl authored and ripatel-fd committed Nov 6, 2023
1 parent 5c71339 commit d43e011
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/ballet/txn/fd_txn.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@
transaction. */
#define FD_TXN_MTU (1232UL)

/* FD_TXN_MIN_SERIALIZED_SZ: The minimum size (in bytes) of a serialized
transaction, using fd_txn_parse() verification rules. */
#define FD_TXN_MIN_SERIALIZED_SZ (134UL)


/* A Solana transaction instruction, i.e. one command or step to execute in a
transaction.
Expand Down
15 changes: 15 additions & 0 deletions verification/proofs/txn/minsz/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
HARNESS_ENTRY = harness
HARNESS_FILE = fd_txn_minsz_harness

PROOF_UID = fd_txn_minsz

DEFINES +=
INCLUDES += -I$(SRCDIR)

REMOVE_FUNCTION_BODY +=

PROOF_SOURCES += $(PROOFDIR)/$(HARNESS_FILE).c
PROOF_SOURCES += $(PROOF_STUB)/fd_log.c
PROJECT_SOURCES = $(SRCDIR)/ballet/txn/fd_txn_parse.c

include ../../Makefile.common
7 changes: 7 additions & 0 deletions verification/proofs/txn/minsz/cbmc-viewer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{ "expected-missing-functions":
[

],
"proof-name": "fd_txn_minsz",
"proof-root": "verification/proofs"
}
26 changes: 26 additions & 0 deletions verification/proofs/txn/minsz/fd_txn_minsz_harness.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include <ballet/txn/fd_txn.h>

#include <assert.h>
#include <stdlib.h>

/* Prove that there is no valid serialized txn with size less than
FD_TXN_MIN_SERIALIZED_SZ. */

void
harness( void ) {
/* Input */
ulong input_sz;
__CPROVER_assume( input_sz<FD_TXN_MIN_SERIALIZED_SZ );
uchar * input = malloc( input_sz );
if( !input ) return;

/* Parsing target buffers */
fd_txn_parse_counters_t counters = {0};
uchar __attribute__((aligned((alignof(fd_txn_t))))) txn_buf[ FD_TXN_MAX_SZ ];

/* Parse */
ulong res = fd_txn_parse( input, input_sz, txn_buf, &counters );

/* Parsing must have failed */
assert( res==0UL );
}

0 comments on commit d43e011

Please sign in to comment.