Skip to content

Commit

Permalink
vm: add syscall sol_get_epoch_rewards_sysvar
Browse files Browse the repository at this point in the history
  • Loading branch information
0x0ece committed Jan 8, 2025
1 parent 8c202e8 commit 8f77acd
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ dump/test-vectors/vm_interp/fixtures/latest/35cf22f9eec59e8e27368e14e657e5659eb4
dump/test-vectors/vm_interp/fixtures/latest/crash-e83a21538a4cb23f371b138b9b16573cf6c9427e.fix
dump/test-vectors/vm_interp/fixtures/latest/74286304a3bc106079f15b2d03f40418f8657a7a_3948568.fix
dump/test-vectors/vm_interp/fixtures/latest/d6633e73f5c6a36107118ad018d34a18d7e42dea_3948711.fix
dump/test-vectors/vm_interp/fixtures/latest/4d58264dac713a0ec42c255f11d3b0fb74d32181_2321898.fix
2 changes: 1 addition & 1 deletion src/flamenco/runtime/sysvar/fd_sysvar_epoch_rewards.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ write_epoch_rewards( fd_exec_slot_ctx_t * slot_ctx, fd_sysvar_epoch_rewards_t *
fd_sysvar_epoch_rewards_t *
fd_sysvar_epoch_rewards_read(
fd_sysvar_epoch_rewards_t * result,
fd_exec_slot_ctx_t * slot_ctx
fd_exec_slot_ctx_t const * slot_ctx
) {
fd_sysvar_epoch_rewards_t const * ret = fd_sysvar_cache_epoch_rewards( slot_ctx->sysvar_cache );
if( FD_UNLIKELY( NULL != ret ) ) {
Expand Down
2 changes: 1 addition & 1 deletion src/flamenco/runtime/sysvar/fd_sysvar_epoch_rewards.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ FD_PROTOTYPES_BEGIN
fd_sysvar_epoch_rewards_t *
fd_sysvar_epoch_rewards_read(
fd_sysvar_epoch_rewards_t * result,
fd_exec_slot_ctx_t * slot_ctx
fd_exec_slot_ctx_t const * slot_ctx
);

/* Update EpochRewards sysvar with distributed rewards
Expand Down
9 changes: 8 additions & 1 deletion src/flamenco/vm/syscall/fd_vm_syscall.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ fd_vm_syscall_register_slot( fd_sbpf_syscalls_t * syscalls,
int enable_last_restart_slot_syscall = 0;
int enable_get_sysvar_syscall = 0;
int enable_get_epoch_stake_syscall = 0;
int enable_epoch_rewards_syscall = 0;

int disable_fees_sysvar = 0;

Expand All @@ -42,6 +43,9 @@ fd_vm_syscall_register_slot( fd_sbpf_syscalls_t * syscalls,
enable_last_restart_slot_syscall = FD_FEATURE_ACTIVE( slot_ctx, last_restart_slot_sysvar );
enable_get_sysvar_syscall = FD_FEATURE_ACTIVE( slot_ctx, get_sysvar_syscall_enabled );
enable_get_epoch_stake_syscall = FD_FEATURE_ACTIVE( slot_ctx, enable_get_epoch_stake_syscall );
// https://github.com/anza-xyz/agave/blob/v2.1.7/programs/bpf_loader/src/syscalls/mod.rs#L275-L277
enable_epoch_rewards_syscall = FD_FEATURE_ACTIVE( slot_ctx, enable_partitioned_epoch_reward ) ||
FD_FEATURE_ACTIVE( slot_ctx, partitioned_epoch_rewards_superfeature );

disable_fees_sysvar = FD_FEATURE_ACTIVE( slot_ctx, disable_fees_sysvar );

Expand All @@ -55,6 +59,7 @@ fd_vm_syscall_register_slot( fd_sbpf_syscalls_t * syscalls,
enable_last_restart_slot_syscall = 1;
enable_get_sysvar_syscall = 1;
enable_get_epoch_stake_syscall = 1;
enable_epoch_rewards_syscall = 1;

}

Expand Down Expand Up @@ -143,7 +148,9 @@ fd_vm_syscall_register_slot( fd_sbpf_syscalls_t * syscalls,
REGISTER( "sol_alt_bn128_group_op", fd_vm_syscall_sol_alt_bn128_group_op );

//REGISTER( "sol_big_mod_exp", fd_vm_syscall_sol_big_mod_exp );
//REGISTER( "sol_get_epoch_rewards_sysvar", fd_vm_syscall_sol_get_epoch_rewards_sysvar );

if( enable_epoch_rewards_syscall )
REGISTER( "sol_get_epoch_rewards_sysvar", fd_vm_syscall_sol_get_epoch_rewards_sysvar );

if( enable_poseidon_syscall )
REGISTER( "sol_poseidon", fd_vm_syscall_sol_poseidon );
Expand Down
1 change: 1 addition & 0 deletions src/flamenco/vm/syscall/fd_vm_syscall.h
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,7 @@ FD_VM_SYSCALL_DECL( sol_get_epoch_schedule_sysvar );
FD_VM_SYSCALL_DECL( sol_get_fees_sysvar );
FD_VM_SYSCALL_DECL( sol_get_rent_sysvar );
FD_VM_SYSCALL_DECL( sol_get_last_restart_slot_sysvar );
FD_VM_SYSCALL_DECL( sol_get_epoch_rewards_sysvar );

/* syscall(13c1b505) "sol_get_sysvar"
Expand Down
29 changes: 29 additions & 0 deletions src/flamenco/vm/syscall/fd_vm_syscall_runtime.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "../../runtime/program/fd_vote_program.h"
#include "../../runtime/sysvar/fd_sysvar.h"
#include "../../runtime/sysvar/fd_sysvar_clock.h"
#include "../../runtime/sysvar/fd_sysvar_epoch_rewards.h"
#include "../../runtime/sysvar/fd_sysvar_epoch_schedule.h"
#include "../../runtime/sysvar/fd_sysvar_fees.h"
#include "../../runtime/sysvar/fd_sysvar_rent.h"
Expand Down Expand Up @@ -585,3 +586,31 @@ fd_vm_syscall_sol_get_processed_sibling_instruction(
*ret = 0UL;
return FD_VM_SUCCESS;
}

// https://github.com/anza-xyz/agave/blob/master/programs/bpf_loader/src/syscalls/sysvar.rs#L75
int
fd_vm_syscall_sol_get_epoch_rewards_sysvar( /**/ void * _vm,
/**/ ulong out_vaddr,
FD_PARAM_UNUSED ulong r2,
FD_PARAM_UNUSED ulong r3,
FD_PARAM_UNUSED ulong r4,
FD_PARAM_UNUSED ulong r5,
/**/ ulong * _ret ) {
fd_vm_t * vm = (fd_vm_t *)_vm;

fd_exec_instr_ctx_t const * instr_ctx = vm->instr_ctx;
if( FD_UNLIKELY( !instr_ctx ) ) return FD_VM_SYSCALL_ERR_OUTSIDE_RUNTIME;

FD_VM_CU_UPDATE( vm, fd_ulong_sat_add( FD_VM_SYSVAR_BASE_COST, FD_SYSVAR_EPOCH_REWARDS_FOOTPRINT ) );

void * out = FD_VM_MEM_HADDR_ST( vm, out_vaddr, FD_SYSVAR_EPOCH_REWARDS_ALIGN, FD_SYSVAR_EPOCH_REWARDS_FOOTPRINT );

fd_sysvar_epoch_rewards_t var[1];
fd_sysvar_epoch_rewards_new ( var );
fd_sysvar_epoch_rewards_read( var, instr_ctx->slot_ctx );

memcpy( out, var, FD_SYSVAR_EPOCH_REWARDS_FOOTPRINT );

*_ret = 0UL;
return FD_VM_SUCCESS;
}

0 comments on commit 8f77acd

Please sign in to comment.