Skip to content

Commit

Permalink
handling hash zero length case and adding fixme
Browse files Browse the repository at this point in the history
adding ledger test
  • Loading branch information
ibhatt-jumptrading committed May 3, 2024
1 parent be6f39e commit 71332f5
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/flamenco/runtime/tests/Local.mk
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ run-runtime-test-1: $(OBJDIR)/bin/fd_ledger
OBJDIR=$(OBJDIR) src/flamenco/runtime/tests/run_ledger_tests.sh -l mainnet-257066844 -s snapshot-257066844-B5JpRYzvMa4iyQeR8w9co4y7oEayphgbXVeQHXLDoWvV.tar.zst -p 32 -m 5000000 -e 257066849 --zst
OBJDIR=$(OBJDIR) src/flamenco/runtime/tests/run_ledger_tests.sh -l mainnet-257067457 -s snapshot-257067457-DxbpHefwdjLkPecZG2jLuqyQp8me9dFZQMQ8hZMyfhsw.tar.zst -p 32 -m 5000000 -e 257067461 --zst
OBJDIR=$(OBJDIR) src/flamenco/runtime/tests/run_ledger_tests.sh -l mainnet-257068890 -s snapshot-257068890-uRVtagPzKhYorycp4CRtKdWrYPij6iBxCYYXmqRvdSp.tar.zst -p 32 -m 5000000 -e 257068895 --zst
OBJDIR=$(OBJDIR) src/flamenco/runtime/tests/run_ledger_tests.sh -l mainnet-257181622 -s snapshot-257181622-Fy996aeLW7kZ6AbBcPd3Vst77pkHDSAXpaexGiVHbB4S.tar.zst -p 32 -m 5000000 -e 257181624 --zst

# src/flamenco/runtime/run_bpf_tests.sh

Expand Down
3 changes: 3 additions & 0 deletions src/flamenco/vm/fd_vm_context.c
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,9 @@ fd_vm_translate_vm_to_host_private( fd_vm_exec_context_t * ctx,
ulong vm_addr,
ulong sz,
int write ) {
/* FIXME: if the size if zero, then we should not error out here
https://github.com/firedancer-io/solana/blob/d8292b427adf8367d87068a3a88f6fd3ed8916a5/programs/bpf_loader/src/syscalls/mod.rs#L512-L514 */

ulong mem_region = vm_addr & FD_VM_MEM_MAP_REGION_MASK;
ulong start_addr = vm_addr & FD_VM_MEM_MAP_REGION_SZ;
ulong end_addr = start_addr + sz;
Expand Down
10 changes: 7 additions & 3 deletions src/flamenco/vm/syscall/fd_vm_hashes.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ fd_vm_syscall_sol_sha256(

for( ulong i = 0; i < slices_cnt; i++ ) {
uchar const * slice = fd_vm_translate_vm_to_host_const( ctx, slices[i].addr, slices[i].len, alignof(uchar) );
if( FD_UNLIKELY( !slice ) ) return FD_VM_MEM_MAP_ERR_ACC_VIO;
if( FD_UNLIKELY( !slice && slices[i].len ) ) {
return FD_VM_MEM_MAP_ERR_ACC_VIO;
}

ulong cost = fd_ulong_max(vm_compute_budget.mem_op_base_cost, fd_ulong_sat_mul(vm_compute_budget.sha256_byte_cost, slices[i].len) / 2);
ulong err = fd_vm_consume_compute_meter(ctx, cost);
Expand Down Expand Up @@ -92,7 +94,7 @@ fd_vm_syscall_sol_keccak256(

for (ulong i = 0; i < slices_cnt; i++) {
void const * slice = fd_vm_translate_vm_to_host_const( ctx, slices[i].addr, slices[i].len, alignof(uchar) );
if( FD_UNLIKELY( !slice ) ) {
if( FD_UNLIKELY( !slice && slices[i].len ) ) {
FD_LOG_DEBUG(("Translate slice failed %lu %lu %lu", i, slices[i].addr, slices[i].len));
return FD_VM_MEM_MAP_ERR_ACC_VIO;
}
Expand Down Expand Up @@ -142,7 +144,9 @@ fd_vm_syscall_sol_blake3(

for (ulong i = 0; i < slices_cnt; i++) {
void const * slice = fd_vm_translate_vm_to_host( ctx, slices[i].addr, slices[i].len, alignof(uchar) );
if( FD_UNLIKELY( !slice ) ) return FD_VM_MEM_MAP_ERR_ACC_VIO;
if( FD_UNLIKELY( !slice && slices[i].len ) ) {
return FD_VM_MEM_MAP_ERR_ACC_VIO;
}

ulong cost = fd_ulong_max(vm_compute_budget.mem_op_base_cost, fd_ulong_sat_mul(vm_compute_budget.sha256_byte_cost, slices[i].len) / 2);
ulong err = fd_vm_consume_compute_meter(ctx, cost);
Expand Down

0 comments on commit 71332f5

Please sign in to comment.