use isomorphicCast between beacon block types (#2698)

This commit is contained in:
tersec 2021-07-06 12:32:49 +00:00 committed by GitHub
parent 38a5bc8de3
commit ac7f719382
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -43,39 +43,25 @@ template asSigVerified(x: phase0.SignedBeaconBlock):
phase0.SigVerifiedSignedBeaconBlock = phase0.SigVerifiedSignedBeaconBlock =
## This converts a signed beacon block to a sig verified beacon clock. ## This converts a signed beacon block to a sig verified beacon clock.
## This assumes that their bytes representation is the same. ## This assumes that their bytes representation is the same.
static: # TODO See isomorphicCast isomorphicCast[phase0.SigVerifiedSignedBeaconBlock](signedBlock)
doAssert sizeof(phase0.SignedBeaconBlock) ==
sizeof(phase0.SigVerifiedSignedBeaconBlock)
cast[ptr phase0.SigVerifiedSignedBeaconBlock](signedBlock.unsafeAddr)[]
template asSigVerified(x: altair.SignedBeaconBlock): template asSigVerified(x: altair.SignedBeaconBlock):
altair.SigVerifiedSignedBeaconBlock = altair.SigVerifiedSignedBeaconBlock =
## This converts a signed beacon block to a sig verified beacon clock. ## This converts a signed beacon block to a sig verified beacon clock.
## This assumes that their bytes representation is the same. ## This assumes that their bytes representation is the same.
static: # TODO See isomorphicCast isomorphicCast[altair.SigVerifiedSignedBeaconBlock](signedBlock)
doAssert sizeof(altair.SignedBeaconBlock) ==
sizeof(altair.SigVerifiedSignedBeaconBlock)
cast[ptr altair.SigVerifiedSignedBeaconBlock](signedBlock.unsafeAddr)[]
template asTrusted(x: phase0.SignedBeaconBlock or phase0.SigVerifiedBeaconBlock): template asTrusted(x: phase0.SignedBeaconBlock or phase0.SigVerifiedBeaconBlock):
phase0.TrustedSignedBeaconBlock = phase0.TrustedSignedBeaconBlock =
## This converts a sigverified beacon block to a trusted beacon clock. ## This converts a sigverified beacon block to a trusted beacon clock.
## This assumes that their bytes representation is the same. ## This assumes that their bytes representation is the same.
static: # TODO See isomorphicCast isomorphicCast[phase0.TrustedSignedBeaconBlock](signedBlock)
doAssert sizeof(x) == sizeof(phase0.TrustedSignedBeaconBlock)
cast[ptr phase0.TrustedSignedBeaconBlock](signedBlock.unsafeAddr)[]
template asTrusted(x: altair.SignedBeaconBlock or altair.SigVerifiedBeaconBlock): template asTrusted(x: altair.SignedBeaconBlock or altair.SigVerifiedBeaconBlock):
altair.TrustedSignedBeaconBlock = altair.TrustedSignedBeaconBlock =
## This converts a sigverified beacon block to a trusted beacon clock. ## This converts a sigverified beacon block to a trusted beacon clock.
## This assumes that their bytes representation is the same. ## This assumes that their bytes representation is the same.
static: # TODO See isomorphicCast isomorphicCast[altair.TrustedSignedBeaconBlock](signedBlock)
doAssert sizeof(x) == sizeof(altair.TrustedSignedBeaconBlock)
cast[ptr altair.TrustedSignedBeaconBlock](signedBlock.unsafeAddr)[]
func batchVerify(quarantine: QuarantineRef, sigs: openArray[SignatureSet]): bool = func batchVerify(quarantine: QuarantineRef, sigs: openArray[SignatureSet]): bool =
var secureRandomBytes: array[32, byte] var secureRandomBytes: array[32, byte]