-
Notifications
You must be signed in to change notification settings - Fork 172
feat: update acp-103 complexities #919
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
b713965
test: update complexity tests with compute
erictaylor fae9f61
feat: acp-103 complexity updates
erictaylor 8027ae7
fix: update export name
erictaylor 2bab717
feat: add updated acp-103 complexities
erictaylor 52b0ba4
feat: add warp message serialization/deserialization
erictaylor 7b50aa6
test: fix warp message bytes fixture
erictaylor c42d82c
docs: update jsdoc comment
erictaylor df7686a
docs: update jsdoc comment
erictaylor File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { | ||
WarpMessage, | ||
WarpSignature, | ||
WarpUnsignedMessage, | ||
} from '../serializable/pvm/warp'; | ||
import { concatBytes } from '../utils'; | ||
import { id, idBytes } from './common'; | ||
import { | ||
blsSignature, | ||
blsSignatureBytes, | ||
bytes, | ||
bytesBytes, | ||
int, | ||
intBytes, | ||
} from './primitives'; | ||
import { bytesForInt } from './utils/bytesFor'; | ||
|
||
export const warpUnsignedMessage = () => | ||
new WarpUnsignedMessage(int(), id(), bytes()); | ||
|
||
export const warpUnsignedMessageBytes = () => | ||
concatBytes(intBytes(), idBytes(), bytesBytes()); | ||
|
||
export const warpSignature = () => new WarpSignature(bytes(), blsSignature()); | ||
|
||
export const warpSignatureBytes = () => | ||
concatBytes(bytesBytes(), blsSignatureBytes()); | ||
|
||
export const warpMessage = () => | ||
new WarpMessage(warpUnsignedMessage(), warpSignature()); | ||
|
||
export const warpMessageBytes = () => | ||
concatBytes(warpUnsignedMessageBytes(), bytesForInt(0), warpSignatureBytes()); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { Codec, Manager } from '../../codec'; | ||
import { WarpSignature } from './signature'; | ||
|
||
/** | ||
* @see https://github.com/ava-labs/avalanchego/blob/master/vms/platformvm/warp/codec.go | ||
*/ | ||
export const codec = new Codec([WarpSignature]); | ||
|
||
let manager: Manager; | ||
export const getWarpManager = () => { | ||
if (manager) return manager; | ||
manager = new Manager(); | ||
manager.RegisterCodec(0, codec); | ||
return manager; | ||
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export { codec, getWarpManager } from './codec'; | ||
export { WarpMessage } from './message'; | ||
export { WarpSignature } from './signature'; | ||
export { WarpUnsignedMessage } from './unsignedMessage'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { testWarpCodec } from '../../../fixtures/codec'; | ||
import { testSerialization } from '../../../fixtures/utils/serializable'; | ||
import { warpMessage, warpMessageBytes } from '../../../fixtures/warp'; | ||
import { WarpMessage } from './message'; | ||
|
||
testSerialization( | ||
'WarpMessage', | ||
WarpMessage, | ||
warpMessage, | ||
warpMessageBytes, | ||
testWarpCodec, | ||
); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { concatBytes } from '../../../utils/buffer'; | ||
import { unpack } from '../../../utils/struct'; | ||
import type { Codec } from '../../codec'; | ||
import { serializable } from '../../common/types'; | ||
import { TypeSymbols } from '../../constants'; | ||
import type { WarpSignature } from './signature'; | ||
import { WarpUnsignedMessage } from './unsignedMessage'; | ||
|
||
@serializable() | ||
export class WarpMessage { | ||
_type = TypeSymbols.WarpMessage; | ||
|
||
constructor( | ||
public readonly unsignedMessage: WarpUnsignedMessage, | ||
public readonly signature: WarpSignature, | ||
) {} | ||
|
||
static fromBytes(bytes: Uint8Array, codec: Codec): [WarpMessage, Uint8Array] { | ||
const [unsignedMessage, signatureBytes] = unpack( | ||
bytes, | ||
[WarpUnsignedMessage], | ||
codec, | ||
); | ||
|
||
const [signature, rest] = codec.UnpackPrefix<WarpSignature>(signatureBytes); | ||
|
||
return [new WarpMessage(unsignedMessage, signature), rest]; | ||
} | ||
|
||
toBytes(codec: Codec) { | ||
return concatBytes( | ||
this.unsignedMessage.toBytes(codec), | ||
codec.PackPrefix(this.signature), | ||
); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { testWarpCodec } from '../../../fixtures/codec'; | ||
import { testSerialization } from '../../../fixtures/utils/serializable'; | ||
import { warpSignature, warpSignatureBytes } from '../../../fixtures/warp'; | ||
import { WarpSignature } from './signature'; | ||
|
||
testSerialization( | ||
'WarpSignature', | ||
WarpSignature, | ||
warpSignature, | ||
warpSignatureBytes, | ||
testWarpCodec, | ||
); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { hammingWeight } from '../../../utils/buffer'; | ||
import { pack, unpack } from '../../../utils/struct'; | ||
import type { Codec } from '../../codec'; | ||
import { serializable } from '../../common/types'; | ||
import { TypeSymbols } from '../../constants'; | ||
import { BlsSignature } from '../../fxs/common'; | ||
import { Bytes } from '../../primitives'; | ||
|
||
@serializable() | ||
export class WarpSignature { | ||
_type = TypeSymbols.WarpSignature; | ||
|
||
constructor( | ||
public readonly signers: Bytes, | ||
public readonly signature: BlsSignature, | ||
) {} | ||
|
||
static fromBytes( | ||
bytes: Uint8Array, | ||
codec: Codec, | ||
): [WarpSignature, Uint8Array] { | ||
const [signers, signature, rest] = unpack( | ||
bytes, | ||
[Bytes, BlsSignature], | ||
codec, | ||
); | ||
|
||
return [new WarpSignature(signers, signature), rest]; | ||
} | ||
|
||
toBytes(codec: Codec) { | ||
return pack([this.signers, this.signature], codec); | ||
} | ||
|
||
/** | ||
* Number of BLS public keys that participated in the | ||
* {@linkcode BlsSignature}. This is exposed because users of the signatures | ||
* typically impose a verification fee that is a function of the number of signers. | ||
* | ||
* This is used to calculate the Warp complexity in transactions. | ||
*/ | ||
numOfSigners(): number { | ||
return hammingWeight(this.signers.bytes); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { testWarpCodec } from '../../../fixtures/codec'; | ||
import { testSerialization } from '../../../fixtures/utils/serializable'; | ||
import { | ||
warpUnsignedMessage, | ||
warpUnsignedMessageBytes, | ||
} from '../../../fixtures/warp'; | ||
import { WarpUnsignedMessage } from './unsignedMessage'; | ||
|
||
testSerialization( | ||
'WarpUnsignedMessage', | ||
WarpUnsignedMessage, | ||
warpUnsignedMessage, | ||
warpUnsignedMessageBytes, | ||
testWarpCodec, | ||
); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { pack, unpack } from '../../../utils/struct'; | ||
import type { Codec } from '../../codec'; | ||
import { serializable } from '../../common/types'; | ||
import { TypeSymbols } from '../../constants'; | ||
import { Id } from '../../fxs/common'; | ||
import { Bytes, Int } from '../../primitives'; | ||
|
||
@serializable() | ||
export class WarpUnsignedMessage { | ||
_type = TypeSymbols.WarpUnsignedMessage; | ||
|
||
constructor( | ||
public readonly networkId: Int, | ||
public readonly sourceChainId: Id, | ||
public readonly payload: Bytes, | ||
) {} | ||
|
||
static fromBytes( | ||
bytes: Uint8Array, | ||
codec: Codec, | ||
): [WarpUnsignedMessage, Uint8Array] { | ||
const [networkId, sourceChainId, payload, rest] = unpack( | ||
bytes, | ||
[Int, Id, Bytes], | ||
codec, | ||
); | ||
|
||
return [new WarpUnsignedMessage(networkId, sourceChainId, payload), rest]; | ||
} | ||
|
||
toBytes(codec: Codec) { | ||
return pack([this.networkId, this.sourceChainId, this.payload], codec); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.