Skip to content
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

2776 smart rollup origination with whitelist #2781

Merged
merged 13 commits into from
Jan 5, 2024
1 change: 1 addition & 0 deletions cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
"ProxfordY",
"PtNairobi",
"refetched",
"riscv",
"rollups",
"Roxane",
"SAPLINGCONTRACT",
Expand Down
29 changes: 29 additions & 0 deletions packages/taquito-local-forging/src/codec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,18 @@ export const pkhDecoder = (val: Uint8ArrayConsumer) => {
}
};

export const pkhsDecoder = (val: Uint8ArrayConsumer) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what would the s be in this case in pkhs

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as the other comment inherit the naming consistency from proposalsDecoder, I think s means plural

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think for proposals it's because the operation itself is called Proposals instead of proposal.

I think we can remove the S in this case, but that's just personal preference.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there are proposalDecoder and proposalsDecoder. There is already pkhDecoder will we consider pkhArrayDecoder?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah let's do pkhArrayDecoder then, seems more informative than just using s.

if (!boolDecoder(val)) {
return undefined;
}
const pkhs = [];
val.consume(4);
while (val.length() > 0) {
pkhs.push(pkhDecoder(val));
}
return pkhs;
};

export const branchEncoder = prefixEncoder(Prefix.B);
export const tz1Encoder = prefixEncoder(Prefix.TZ1);

Expand Down Expand Up @@ -116,6 +128,8 @@ export const pvmKindEncoder = (pvm: string): string => {
return '00';
case 'wasm_2_0_0':
return '01';
case 'riscv':
return '02';
default:
throw new UnsupportedPvmKindError(pvm);
}
Expand All @@ -128,6 +142,8 @@ export const pvmKindDecoder = (pvm: Uint8ArrayConsumer): string => {
return 'arith';
case 0x01:
return 'wasm_2_0_0';
case 0x02:
return 'riscv';
default:
throw new DecodePvmKindError(value[0].toString());
}
Expand Down Expand Up @@ -213,6 +229,19 @@ export const pkhEncoder = (val: string) => {
}
};

export const pkhsEncoder = (val?: string[]) => {
if (!val) {
return boolEncoder(false);
}
if (val.length === 0) {
return boolEncoder(true) + pad(0);
}
const pkhs = val.reduce((prev, curr) => {
return prev + pkhEncoder(curr);
}, '');
return boolEncoder(true) + pad(pkhs.length / 2) + pkhs;
};

export const publicKeyEncoder = (val: string) => {
const pubkeyPrefix = val.substring(0, 4);
switch (pubkeyPrefix) {
Expand Down
1 change: 1 addition & 0 deletions packages/taquito-local-forging/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export enum CODEC {
ZARITH = 'zarith',
PUBLIC_KEY = 'public_key',
PKH = 'pkh',
PKH_ARR = 'pkhArr',
DELEGATE = 'delegate',
SCRIPT = 'script',
BALLOT_STATEMENT = 'ballotStmt',
Expand Down
2 changes: 2 additions & 0 deletions packages/taquito-local-forging/src/decoder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
paddedBytesDecoder,
parametersDecoder,
pkhDecoder,
pkhsDecoder,
smartRollupMessageDecoder,
proposalDecoder,
proposalsDecoder,
Expand Down Expand Up @@ -63,6 +64,7 @@ export const decoders: { [key: string]: Decoder } = {
[CODEC.ZARITH]: zarithDecoder,
[CODEC.PUBLIC_KEY]: publicKeyDecoder,
[CODEC.PKH]: pkhDecoder,
[CODEC.PKH_ARR]: pkhsDecoder,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would you consider updating this to PKH_ARRAY or PKH_LIST instead for clarity?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At the time, trying to be consistent with existing PROPOSAL_ARR but I like your suggestions better

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if the decoder going with pkhArrayDecoder will update this as PKH_ARRAY.

[CODEC.DELEGATE]: delegateDecoder,
[CODEC.INT32]: int32Decoder,
[CODEC.SCRIPT]: scriptDecoder,
Expand Down
2 changes: 2 additions & 0 deletions packages/taquito-local-forging/src/encoder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
paddedBytesEncoder,
parametersEncoder,
pkhEncoder,
pkhsEncoder,
smartRollupMessageEncoder,
proposalEncoder,
proposalsEncoder,
Expand Down Expand Up @@ -61,6 +62,7 @@ export const encoders: { [key: string]: Encoder<any> } = {
[CODEC.ZARITH]: zarithEncoder,
[CODEC.PUBLIC_KEY]: publicKeyEncoder,
[CODEC.PKH]: pkhEncoder,
[CODEC.PKH_ARR]: pkhsEncoder,
[CODEC.DELEGATE]: delegateEncoder,
[CODEC.SCRIPT]: scriptEncoder,
[CODEC.BALLOT_STATEMENT]: ballotEncoder,
Expand Down
1 change: 1 addition & 0 deletions packages/taquito-local-forging/src/schema/operation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ export const SmartRollupOriginateSchema = {
pvm_kind: CODEC.PVM_KIND,
kernel: CODEC.PADDED_BYTES,
parameters_ty: CODEC.VALUE,
whitelist: CODEC.PKH_ARR,
};

export const SmartRollupAddMessagesSchema = {
Expand Down
4 changes: 3 additions & 1 deletion packages/taquito-local-forging/src/taquito-local-forging.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export * from './interface';
export { VERSION } from './version';
export { ProtocolsHash } from './protocols';

const PROTOCOL_CURRENT = ProtocolsHash.PtMumbai2;
const PROTOCOL_CURRENT = ProtocolsHash.ProxfordY;

export function getCodec(codec: CODEC, _proto: ProtocolsHash) {
return {
Expand Down Expand Up @@ -60,6 +60,8 @@ export class LocalForger implements Forger {
continue;
} else if (content.kind === 'set_deposits_limit' && diff[0] === 'limit') {
continue;
} else if (content.kind === 'smart_rollup_originate' && diff[0] === 'whitelist') {
continue;
} else {
throw new InvalidOperationSchemaError(content, `missing properties "${diff.join(', ')}"`);
}
Expand Down
55 changes: 53 additions & 2 deletions packages/taquito-local-forging/test/codec.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,13 @@ import {
paddedBytesDecoder,
} from '../src/codec';
import { Uint8ArrayConsumer } from '../src/uint8array-consumer';
import { pkhEncoder, publicKeyDecoder, publicKeyEncoder } from '../src/codec';
import {
pkhEncoder,
pkhsEncoder,
pkhsDecoder,
publicKeyDecoder,
publicKeyEncoder,
} from '../src/codec';
import {
DecodeBallotValueError,
DecodePvmKindError,
Expand Down Expand Up @@ -76,6 +82,49 @@ describe('Tests for Entrypoint functions and for encode and decoder error messag
}
});

test(`Verify pkhsEncoder`, async () => {
const none = pkhsEncoder();
expect(none).toEqual('00');
const empty = pkhsEncoder([]);
expect(empty).toEqual('ff00000000');
const tz = pkhsEncoder([
'tz1e42w8ZaGAbM3gucbBy8iRypdbnqUj7oWY',
'tz2Ch1abG7FNiibmV26Uzgdsnfni9XGrk5wD',
'tz3WXYtyDUNL91qfiCJtVUX746QpNv5i5ve5',
'tz4HQ8VeXAyrZMhES1qLMJAc9uAVXjbMpS8u',
]);
expect(tz).toEqual(
'ff0000005400c9fc72e8491bd2973e196f04ec6918ad5bcee22d012ffebbf1560632ca767bc960ccdb84669d284c2c026fde46af0356a0476dae4e4600172dc9309b3aa4035c14a7a05c10fc8b402fbcdd48dc8136236bf3c1'
);

expect(() => pkhsEncoder(['tz5WXYtyDUNL91qfiCJtVUX746QpNv5i5ve5'])).toThrow(
InvalidKeyHashError
);
try {
pkhsEncoder(['tz5WXYtyDUNL91qfiCJtVUX746QpNv5i5ve5']);
} catch (e) {
expect(e.message).toContain(`Invalid public key hash "tz5WXYtyDUNL91qfiCJtVUX746QpNv5i5ve5"`);
}
});

test(`Verify pkhsDecoder`, async () => {
const none = pkhsDecoder(Uint8ArrayConsumer.fromHexString('00'));
expect(none).toEqual(undefined);
const empty = pkhsDecoder(Uint8ArrayConsumer.fromHexString('ff00000000'));
expect(empty).toEqual([]);
const tz = pkhsDecoder(
Uint8ArrayConsumer.fromHexString(
'ff0000005400c9fc72e8491bd2973e196f04ec6918ad5bcee22d012ffebbf1560632ca767bc960ccdb84669d284c2c026fde46af0356a0476dae4e4600172dc9309b3aa4'
)
);
expect(tz).toEqual([
'tz1e42w8ZaGAbM3gucbBy8iRypdbnqUj7oWY',
'tz2Ch1abG7FNiibmV26Uzgdsnfni9XGrk5wD',
'tz3WXYtyDUNL91qfiCJtVUX746QpNv5i5ve5',
]);
//
});

test(`Verify publicKeyEncoder`, async () => {
const edpk = publicKeyEncoder('edpkuLxx9PQD8fZ45eUzrK3BhfDZJHhBuK4Zi49DcEGANwd2rpX82t');
expect(edpk).toEqual('005c8244b8de7d57795962c1bfc855d0813f8c61eddf3795f804ccdea3e4c82ae9');
Expand Down Expand Up @@ -240,13 +289,15 @@ describe('Tests for Entrypoint functions and for encode and decoder error messag
test('Verify that pvmKindEncoder functions correctly and returns UnsupportedPvmKindError on unknown case', () => {
expect(pvmKindEncoder('arith')).toEqual('00');
expect(pvmKindEncoder('wasm_2_0_0')).toEqual('01');
expect(pvmKindEncoder('riscv')).toEqual('02');
expect(() => pvmKindEncoder('foobar')).toThrowError(UnsupportedPvmKindError);
});

test('Verify that pvmKindDecoder functions correctly and returns DecodePvmKindError on unknown case', () => {
expect(pvmKindDecoder(Uint8ArrayConsumer.fromHexString('00'))).toEqual('arith');
expect(pvmKindDecoder(Uint8ArrayConsumer.fromHexString('01'))).toEqual('wasm_2_0_0');
expect(() => pvmKindDecoder(Uint8ArrayConsumer.fromHexString('02'))).toThrowError(
expect(pvmKindDecoder(Uint8ArrayConsumer.fromHexString('02'))).toEqual('riscv');
expect(() => pvmKindDecoder(Uint8ArrayConsumer.fromHexString('03'))).toThrowError(
DecodePvmKindError
);
});
Expand Down
47 changes: 25 additions & 22 deletions packages/taquito-rpc/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,19 @@ interface INodeExtender {

type OtherEltsInner =
| {
value: any;
}
value: any;
}
| {
inode_extender: INodeExtender;
};
inode_extender: INodeExtender;
};

export type OtherElts =
| {
node: [string, { value: string } | { node: string }][];
}
node: [string, { value: string } | { node: string }][];
}
| {
other_elts: OtherEltsInner;
};
other_elts: OtherEltsInner;
};

export interface Inode {
length: string;
Expand Down Expand Up @@ -334,6 +334,7 @@ export interface OperationContentsSmartRollupOriginate {
pvm_kind: PvmKind;
kernel: string;
parameters_ty: MichelsonV1Expression;
whitelist?: string[];
}

export interface OperationContentsSmartRollupAddMessages {
Expand Down Expand Up @@ -761,6 +762,7 @@ export interface OperationContentsAndResultSmartRollupOriginate {
pvm_kind: PvmKind;
kernel: string;
parameters_ty: MichelsonV1Expression;
whitelist?: string[];
metadata: OperationContentsAndResultMetadataSmartRollupOriginate;
}

Expand Down Expand Up @@ -1104,13 +1106,13 @@ export interface ScriptedContracts {

export type BondId =
| {
smart_rollup?: never;
tx_rollup: string;
}
smart_rollup?: never;
tx_rollup: string;
}
| {
smart_rollup: string;
tx_rollup?: never;
};
smart_rollup: string;
tx_rollup?: never;
};

export interface OperationBalanceUpdatesItem {
kind: BalanceUpdateKindEnum;
Expand Down Expand Up @@ -1207,7 +1209,7 @@ export interface OperationResultSmartRollupOriginate {
address?: string;
genesis_commitment_hash?: string;
consumed_milligas?: string;
size: string;
size?: string;
errors?: TezosGenericOperationError[];
}

Expand Down Expand Up @@ -1818,10 +1820,10 @@ export interface ConstantsResponseProto010 extends ConstantsResponseProto009 {
}

// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface ConstantsResponseProto009 extends ConstantsResponseProto008 {}
export interface ConstantsResponseProto009 extends ConstantsResponseProto008 { }

// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface ConstantsResponseProto008 extends ConstantsResponseProto007 {}
export interface ConstantsResponseProto008 extends ConstantsResponseProto007 { }

export interface ConstantsResponseProto007
extends Omit<ConstantsResponseProto006, 'max_revelations_per_block'> {
Expand Down Expand Up @@ -2029,12 +2031,12 @@ export type ProtocolsResponse = {

export type Next =
| {
next: number;
}
next: number;
}
| {
newest: number;
oldest: number;
};
newest: number;
oldest: number;
};

export type LastRemovedCommitmentHashes = {
last_message_hash: string;
Expand Down Expand Up @@ -2080,6 +2082,7 @@ export interface PendingOperationsV2 {
export enum PvmKind {
WASM2 = 'wasm_2_0_0',
ARITH = 'arith',
RISCV = 'riscv',
}

export interface SmartRollupPublishCommitment {
Expand Down
Loading