Skip to content

Instantly share code, notes, and snippets.

View alonmuroch's full-sized avatar

Alon Muroch alonmuroch

View GitHub Profile
pragma solidity ^0.4.8;
// import "./StandardToken.sol";
import 'zeppelin-solidity/contracts/token/VestedToken.sol';
import 'zeppelin-solidity/contracts/SafeMath.sol';
contract CDTToken is VestedToken {
using SafeMath for uint;
//FIELDS
//CONSTANTS
0x0092781f6397a37ed76038503741aa6CaCEFf90D
0x87252ea7D298b1c822e791931AFeFb2a6DDD00f7
# evaluate the equation y=x^3+x+5 for x
def qeval(x):
return x^3+x+5
// example grpc for fetching minimal slashing data from Prsym's slasher
address := "<slasher_address>:<slasher_port>"
conn, err := grpc.Dial(address, grpc.WithInsecure())
if err != nil {
fmt.Printf("%s", err.Error())
return
}
defer conn.Close()
client := slashpb.NewSlasherClient(conn)
@alonmuroch
alonmuroch / python
Created January 11, 2021 08:05
get_attestation_deltas
def get_attestation_deltas(state: BeaconState) -> Tuple[Sequence[Gwei], Sequence[Gwei]]:
"""
Return attestation reward/penalty deltas for each validator.
"""
source_rewards, source_penalties = get_source_deltas(state)
target_rewards, target_penalties = get_target_deltas(state)
head_rewards, head_penalties = get_head_deltas(state)
inclusion_delay_rewards, _ = get_inclusion_delay_deltas(state)
_, inactivity_penalties = get_inactivity_penalty_deltas(state)
@alonmuroch
alonmuroch / get_attestation_component_deltas.py
Created January 11, 2021 08:10
get_attestation_component_deltas
def get_attestation_component_deltas(state: BeaconState,
attestations: Sequence[PendingAttestation]
) -> Tuple[Sequence[Gwei], Sequence[Gwei]]:
"""
Helper with shared logic for use by get source, target, and head deltas functions
"""
rewards = [Gwei(0)] * len(state.validators)
penalties = [Gwei(0)] * len(state.validators)
total_balance = get_total_active_balance(state)
unslashed_attesting_indices = get_unslashed_attesting_indices(state, attestations)
@alonmuroch
alonmuroch / get_attestation_deltas.py
Created January 11, 2021 08:11
get_attestation_deltas
def get_attestation_deltas(state: BeaconState) -> Tuple[Sequence[Gwei], Sequence[Gwei]]:
"""
Return attestation reward/penalty deltas for each validator.
"""
source_rewards, source_penalties = get_source_deltas(state)
target_rewards, target_penalties = get_target_deltas(state)
head_rewards, head_penalties = get_head_deltas(state)
inclusion_delay_rewards, _ = get_inclusion_delay_deltas(state)
_, inactivity_penalties = get_inactivity_penalty_deltas(state)
@alonmuroch
alonmuroch / get_base_reward.py
Created January 11, 2021 08:18
get_base_reward
def get_base_reward(state: BeaconState, index: ValidatorIndex) -> Gwei:
total_balance = get_total_active_balance(state)
effective_balance = state.validators[index].effective_balance
return Gwei(effective_balance * BASE_REWARD_FACTOR // integer_squareroot(total_balance) // BASE_REWARDS_PER_EPOCH)
@alonmuroch
alonmuroch / is_in_inactivity_leak.py
Created January 11, 2021 08:36
is_in_inactivity_leak
def is_in_inactivity_leak(state: BeaconState) -> bool:
return get_finality_delay(state) > MIN_EPOCHS_TO_INACTIVITY_PENALTY