Skip to content

Commit

Permalink
poseidon: fix syscall edge cases based on diff testing
Browse files Browse the repository at this point in the history
  • Loading branch information
0x0ece committed May 16, 2024
1 parent ec9d52e commit 59c0a3d
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 20 deletions.
3 changes: 2 additions & 1 deletion src/ballet/bn254/fd_poseidon.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ fd_poseidon_append( fd_poseidon_t * pos,
if( FD_UNLIKELY( pos->cnt >= FD_POSEIDON_MAX_WIDTH ) ) {
return NULL;
}
if( FD_UNLIKELY( sz>32UL ) ) {
/* Empty input and non-field are errors. Short element is extended with 0s. */
if( FD_UNLIKELY( sz==0 || sz>32UL ) ) {
return NULL;
}

Expand Down
13 changes: 0 additions & 13 deletions src/ballet/bn254/test_poseidon.c
Original file line number Diff line number Diff line change
Expand Up @@ -231,19 +231,6 @@ int main( int argc,
fd_poseidon_fini( pos, res );
FD_TEST(memcmp(res, FLIST[12], FD_POSEIDON_HASH_SZ) == 0);

/*
fd_poseidon_hash(1) 9.530K/s/core 104927.617 ns/call
fd_poseidon_hash(2) 5.372K/s/core 186157.594 ns/call
fd_poseidon_hash(4) 2.213K/s/core 451814.312 ns/call
fd_poseidon_hash(6) 1.159K/s/core 862762.500 ns/call
fd_poseidon_hash(12) 0.349K/s/core 2869402.500 ns/call
fd_poseidon_hash(1) 25.282K/s/core 39553.863 ns/call
fd_poseidon_hash(2) 15.764K/s/core 63437.676 ns/call
fd_poseidon_hash(4) 7.002K/s/core 142807.094 ns/call
fd_poseidon_hash(6) 3.658K/s/core 273403.594 ns/call
fd_poseidon_hash(12) 1.116K/s/core 896352.188 ns/call
*/
/* benchmark */
char cstr[128];
ulong iter = 1000UL;
Expand Down
12 changes: 10 additions & 2 deletions src/flamenco/features/fd_features_generated.c
Original file line number Diff line number Diff line change
Expand Up @@ -1087,6 +1087,12 @@ fd_feature_id_t const ids[] = {
/* 3opE3EzAKnUftUDURkzMgwpNgimBAypW1mNDYH4x4Zg7 */
.name = "reward_full_priority_fee" },

{ .index = offsetof(fd_features_t, simplify_alt_bn128_syscall_error_codes)>>3,
.id = {"\xff\xdc\x9f\x8d\x03\xe9\xa9\x8b\x11\x73\xd7\xf4\x57\x73\x30\xb9\x37\xc4\x25\xcd\xa9\xd8\xc1\x3e\xcc\xb7\x16\x4a\x1a\xfd\xf9\xec"},
/* JDn5q3GBeqzvUa7z67BbmVHVdE3EbUAjvFep3weR3jxX */
.name = "simplify_alt_bn128_syscall_error_codes",
.hardcoded = 1 },

{ .index = offsetof(fd_features_t, abort_on_invalid_curve)>>3,
.id = {"\xdd\x72\x21\x65\xad\x48\xe1\xaf\xda\x46\x3f\x70\xf5\xe7\x27\xdf\x99\x16\x8f\xf9\xbb\xcb\x52\x76\xdb\x98\x53\x4e\x33\xf1\xf5\x86"},
/* FuS3FPfJDKSNot99ECLXtp3rueq36hMNStJkPJwWodLh */
Expand Down Expand Up @@ -1294,7 +1300,8 @@ fd_feature_id_query( ulong prefix ) {
case 0xf711255aedfe2d0d: return &ids[ 190 ];
case 0x81f658d2653a6051: return &ids[ 191 ];
case 0xf1f206f6027db529: return &ids[ 192 ];
case 0xafe148ad652172dd: return &ids[ 193 ];
case 0x8ba9e9038d9fdcff: return &ids[ 193 ];
case 0xafe148ad652172dd: return &ids[ 194 ];
default: break;
}

Expand Down Expand Up @@ -1496,6 +1503,7 @@ FD_STATIC_ASSERT( offsetof( fd_features_t, remove_rounding_in_fee_calculation
FD_STATIC_ASSERT( offsetof( fd_features_t, enable_tower_sync_ix )>>3==190UL, layout );
FD_STATIC_ASSERT( offsetof( fd_features_t, deprecate_unused_legacy_vote_plumbing )>>3==191UL, layout );
FD_STATIC_ASSERT( offsetof( fd_features_t, reward_full_priority_fee )>>3==192UL, layout );
FD_STATIC_ASSERT( offsetof( fd_features_t, abort_on_invalid_curve )>>3==193UL, layout );
FD_STATIC_ASSERT( offsetof( fd_features_t, simplify_alt_bn128_syscall_error_codes )>>3==193UL, layout );
FD_STATIC_ASSERT( offsetof( fd_features_t, abort_on_invalid_curve )>>3==194UL, layout );

FD_STATIC_ASSERT( sizeof( fd_features_t )>>3==FD_FEATURE_ID_CNT, layout );
3 changes: 2 additions & 1 deletion src/flamenco/features/fd_features_generated.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

/* FEATURE_ID_CNT is the number of features in ids */

#define FD_FEATURE_ID_CNT (194UL)
#define FD_FEATURE_ID_CNT (195UL)

union fd_features {

Expand Down Expand Up @@ -206,6 +206,7 @@ union fd_features {
/* 0xf711255aedfe2d0d */ ulong enable_tower_sync_ix;
/* 0x81f658d2653a6051 */ ulong deprecate_unused_legacy_vote_plumbing;
/* 0xf1f206f6027db529 */ ulong reward_full_priority_fee;
/* 0x8ba9e9038d9fdcff */ ulong simplify_alt_bn128_syscall_error_codes;
/* 0xafe148ad652172dd */ ulong abort_on_invalid_curve;
};

Expand Down
1 change: 1 addition & 0 deletions src/flamenco/features/feature_map.json
Original file line number Diff line number Diff line change
Expand Up @@ -192,5 +192,6 @@
{"name":"enable_tower_sync_ix","pubkey":"tSynMCspg4xFiCj1v3TDb4c7crMR5tSBhLz4sF7rrNA"},
{"name":"deprecate_unused_legacy_vote_plumbing","pubkey":"6Uf8S75PVh91MYgPQSHnjRAPQq6an5BDv9vomrCwDqLe"},
{"name":"reward_full_priority_fee","pubkey":"3opE3EzAKnUftUDURkzMgwpNgimBAypW1mNDYH4x4Zg7"},
{"name":"simplify_alt_bn128_syscall_error_codes","pubkey": "JDn5q3GBeqzvUa7z67BbmVHVdE3EbUAjvFep3weR3jxX","hardcoded":1,"comment":"only impl the activated path"},
{"name":"abort_on_invalid_curve","pubkey":"FuS3FPfJDKSNot99ECLXtp3rueq36hMNStJkPJwWodLh"}
]
2 changes: 1 addition & 1 deletion src/flamenco/runtime/tests/fd_exec_instr_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -903,7 +903,7 @@ fd_exec_vm_syscall_test_run( fd_exec_instr_test_runner_t * runner,
syscalls,
fd_murmur3_32( syscall_name, strlen( syscall_name ), 0U ),
NULL );
FD_TEST( syscall );
if( !syscall ) return 0;

/* Actually invoke the syscall */
int syscall_err = syscall->func( vm, vm->reg[1], vm->reg[2], vm->reg[3], vm->reg[4], vm->reg[5], &vm->reg[0] );
Expand Down
5 changes: 3 additions & 2 deletions src/flamenco/vm/syscall/fd_vm_syscall_crypto.c
Original file line number Diff line number Diff line change
Expand Up @@ -252,11 +252,12 @@ fd_vm_syscall_sol_poseidon( void * _vm,
We must be careful in returning the correct fatal vs soft error.
The special case of vals_len==0 returns a soft_error, so for simplicity
The special case of vals_len==0 returns success, so for simplicity
we capture it explicitly. */

if( FD_UNLIKELY( !vals_len ) ) {
goto soft_error;
ret = 0;
return FD_VM_SUCCESS;
}

/* First loop to memory map. This can return a fatal error. */
Expand Down

0 comments on commit 59c0a3d

Please sign in to comment.