From b5fabd3ef75ab8059a12e3d09bb4b62cb6cf2848 Mon Sep 17 00:00:00 2001 From: Guilherme Dantas Date: Wed, 12 Jun 2024 13:12:33 -0300 Subject: [PATCH] Bump `@cartesi/rollups` to 2.0.0-rc.3 (#16) --- package.json | 2 +- pnpm-lock.yaml | 59 ++++++++++++++++++++++++++++++++++++++-------- src/cli.ts | 25 ++++++++++++++++++++ src/index.ts | 33 +++++++++++++++++++++++++- test/index.test.ts | 52 ++++++++++++++++++++++++++++++++++++++-- 5 files changed, 157 insertions(+), 14 deletions(-) diff --git a/package.json b/package.json index 2e5cc0e..566406a 100644 --- a/package.json +++ b/package.json @@ -36,7 +36,7 @@ "test": "jest" }, "dependencies": { - "@cartesi/rollups": "2.0.0-rc.2", + "@cartesi/rollups": "2.0.0-rc.3", "@commander-js/extra-typings": "^12.0.1", "commander": "^12.0.0", "ethers": "^6.11.1", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 38f0432..59c6d6b 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -6,8 +6,8 @@ settings: dependencies: '@cartesi/rollups': - specifier: 2.0.0-rc.2 - version: 2.0.0-rc.2 + specifier: 2.0.0-rc.3 + version: 2.0.0-rc.3 '@commander-js/extra-typings': specifier: ^12.0.1 version: 12.0.1(commander@12.0.0) @@ -392,16 +392,17 @@ packages: resolution: {integrity: sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw==} dev: true - /@cartesi/rollups@2.0.0-rc.2: - resolution: {integrity: sha512-BQ7zx8b651tCqBI0JnGcWkuwc9olxEj3Uoi0/vK4mz66yeWh41XM3ApqH5P49J5tyCZ38DC6mJsSqjgplRQzLQ==} + /@cartesi/rollups@2.0.0-rc.3: + resolution: {integrity: sha512-IXlHzUJCv2eZh/59KxVJD55IQUOS/uU1h7VbtUQ9Uet3n//sf2U2GgOusshrjjpTVjQjPJGT+j8JSHJ+rq8wfA==} requiresBuild: true dependencies: - '@cartesi/util': 6.1.0 - '@openzeppelin/contracts': 5.0.0 + '@cartesi/util': 6.3.0 + '@ensdomains/ens-contracts': 1.1.4 + '@openzeppelin/contracts': 5.0.2 dev: false - /@cartesi/util@6.1.0: - resolution: {integrity: sha512-j92nSoMHCyu6h7nZgn+MeXjkp8oa1Cy6qaImyxVXmPN2Rcqzl/TkWm/RkhbODU9rh4U3OuUteYqKRjefI3/XIQ==} + /@cartesi/util@6.3.0: + resolution: {integrity: sha512-UgsyTklI4mf3ZbnPHQTuYJcMyldM3y9Xm+ib9xBgDzDq6TxMO81xkrPv/gwA23seHL2/bkJ5flXJEhCE8poW8Q==} dev: false /@commander-js/extra-typings@12.0.1(commander@12.0.0): @@ -419,6 +420,25 @@ packages: '@jridgewell/trace-mapping': 0.3.9 dev: true + /@ensdomains/buffer@0.1.1: + resolution: {integrity: sha512-92SfSiNS8XorgU7OUBHo/i1ZU7JV7iz/6bKuLPNVsMxV79/eI7fJR6jfJJc40zAHjs3ha+Xo965Idomlq3rqnw==} + dev: false + + /@ensdomains/ens-contracts@1.1.4: + resolution: {integrity: sha512-kjdcjaznMtE2lwjAVTX2irs8mgNgJCVuB5hnhFhiMaO8dR/tlHQ5UhtZjhSYRhkZd0hLXYrMkXp6thnwpG+ltg==} + dependencies: + '@ensdomains/buffer': 0.1.1 + '@ensdomains/solsha1': 0.0.3 + '@openzeppelin/contracts': 4.9.6 + dns-packet: 5.6.1 + dev: false + + /@ensdomains/solsha1@0.0.3: + resolution: {integrity: sha512-uhuG5LzRt/UJC0Ux83cE2rCKwSleRePoYdQVcqPN1wyf3/ekMzT/KZUF9+v7/AG5w9jlMLCQkUM50vfjr0Yu9Q==} + dependencies: + hash-test-vectors: 1.3.2 + dev: false + /@isaacs/cliui@8.0.2: resolution: {integrity: sha512-O8jcjabXaleOG9DQ0+ARXWZBTfnP4WNAqzuiJK7ll44AmxGKv/J2M4TPjxjY3znBCfvBXFzucm1twdyFybFqEA==} engines: {node: '>=12'} @@ -698,6 +718,10 @@ packages: '@jridgewell/sourcemap-codec': 1.4.15 dev: true + /@leichtgewicht/ip-codec@2.0.5: + resolution: {integrity: sha512-Vo+PSpZG2/fmgmiNzYK9qWRh8h/CHrwD0mo1h1DzL4yzHNSfWYujGTYsWGreD000gcgmZ7K4Ys6Tx9TxtsKdDw==} + dev: false + /@noble/curves@1.2.0: resolution: {integrity: sha512-oYclrNgRaM9SsBUBVbb8M6DTV7ZHRTKugureoYEncY5c65HOmRzvSiTE3y5CYaPYJA/GVkrhXEoF0M3Ya9PMnw==} dependencies: @@ -709,8 +733,12 @@ packages: engines: {node: '>= 16'} dev: false - /@openzeppelin/contracts@5.0.0: - resolution: {integrity: sha512-bv2sdS6LKqVVMLI5+zqnNrNU/CA+6z6CmwFXm/MzmOPBRSO5reEJN7z0Gbzvs0/bv/MZZXNklubpwy3v2+azsw==} + /@openzeppelin/contracts@4.9.6: + resolution: {integrity: sha512-xSmezSupL+y9VkHZJGDoCBpmnB2ogM13ccaYDWqJTfS3dbuHkgjuwDFUmaFauBCboQMGB/S5UqUl2y54X99BmA==} + dev: false + + /@openzeppelin/contracts@5.0.2: + resolution: {integrity: sha512-ytPc6eLGcHHnapAZ9S+5qsdomhjo6QBHTDRRBFfTxXIpsicMhVPouPgmUPebZZZGX7vt9USA+Z+0M0dSVtSUEA==} dev: false /@pkgjs/parseargs@0.11.0: @@ -1233,6 +1261,13 @@ packages: engines: {node: '>=0.3.1'} dev: true + /dns-packet@5.6.1: + resolution: {integrity: sha512-l4gcSouhcgIKRvyy99RNVOgxXiicE+2jZoNmaNmZ6JXiGajBOJAesk1OBlJuM5k2c+eudGdLxDqXuPCKIj6kpw==} + engines: {node: '>=6'} + dependencies: + '@leichtgewicht/ip-codec': 2.0.5 + dev: false + /eastasianwidth@0.2.0: resolution: {integrity: sha512-I88TYZWc9XiYHRQ4/3c5rjjfgkjhLyW2luGIheGERbNQ6OY7yTybanSpDXZa8y7VUP9YmDcYa+eyq4ca7iLqWA==} dev: true @@ -1439,6 +1474,10 @@ packages: engines: {node: '>=8'} dev: true + /hash-test-vectors@1.3.2: + resolution: {integrity: sha512-PKd/fitmsrlWGh3OpKbgNLE04ZQZsvs1ZkuLoQpeIKuwx+6CYVNdW6LaPIS1QAdZvV40+skk0w4YomKnViUnvQ==} + dev: false + /hasown@2.0.2: resolution: {integrity: sha512-0hJU9SCPvmMzIBdZFqNPXWa6dqh7WdH0cII9y+CyS8rG3nL48Bclra9HmKhVVUHyPWNH5Y7xDwAB7bfgSjkUMQ==} engines: {node: '>= 0.4'} diff --git a/src/cli.ts b/src/cli.ts index e76c0ab..7b4085e 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -17,6 +17,7 @@ import { Input, Notice, Voucher, + DelegateCallVoucher, } from "../src"; import { version } from "../package.json"; @@ -134,6 +135,11 @@ encodeCommand "the timestamp of the block", parseBigInt, ) + .requiredOption( + "--prev-randao ", + "the latest RANDAO mix of the post beacon state of the previous block", + parseBigInt, + ) .requiredOption( "--index ", "the index of the input in the input box", @@ -179,6 +185,25 @@ encodeCommand writeHexToStdout(encodeOutputBlob(notice), binary); }); +encodeCommand + .command("delegatecallvoucher") + .description("Encodes a delegate call voucher blob") + .requiredOption( + "--destination
", + "the destination address", + parseAddress, + ) + .requiredOption("--payload ", "the destination address", parseHex) + .option("-b, --binary", "write to stdout as binary data", false) + .action((options) => { + const delegatecallvoucher: DelegateCallVoucher = { + type: "delegatecallvoucher", + ...options, + }; + const { binary } = options; + writeHexToStdout(encodeOutputBlob(delegatecallvoucher), binary); + }); + const decodeCommand = program.command("decode"); decodeCommand.description("Decodes a blob"); diff --git a/src/index.ts b/src/index.ts index ac17a62..a75a3a9 100644 --- a/src/index.ts +++ b/src/index.ts @@ -8,6 +8,7 @@ export interface Input { msgSender: Address; blockNumber: bigint; blockTimestamp: bigint; + prevRandao: bigint; index: bigint; payload: Hex; } @@ -19,6 +20,7 @@ export const encodeInputBlob = (input: Input): Hex => { msgSender, blockNumber, blockTimestamp, + prevRandao, index, payload, } = input; @@ -32,6 +34,7 @@ export const encodeInputBlob = (input: Input): Hex => { msgSender, blockNumber, blockTimestamp, + prevRandao, index, payload, ], @@ -54,6 +57,7 @@ export const decodeInputBlob = (blob: Hex): Input => { msgSender, blockNumber, blockTimestamp, + prevRandao, index, payload, ] = args; @@ -64,6 +68,7 @@ export const decodeInputBlob = (blob: Hex): Input => { msgSender, blockNumber, blockTimestamp, + prevRandao, index, payload, }; @@ -83,7 +88,13 @@ export interface Voucher { payload: Hex; } -export type Output = Notice | Voucher; +export interface DelegateCallVoucher { + type: "delegatecallvoucher"; + destination: Address; + payload: Hex; +} + +export type Output = Notice | Voucher | DelegateCallVoucher; export const encodeOutputBlob = (output: Output): Hex => { switch (output.type) { @@ -107,6 +118,17 @@ export const encodeOutputBlob = (output: Output): Hex => { args: [destination, value, payload], }); + return blob; + } + case "delegatecallvoucher": { + const { destination, payload } = output; + + const blob = encodeFunctionData({ + abi: Outputs__factory.abi, + functionName: "DelegateCallVoucher", + args: [destination, payload], + }); + return blob; } } @@ -137,5 +159,14 @@ export const decodeOutputBlob = (blob: Hex): Output => { payload, }; } + case "DelegateCallVoucher": { + const [destination, payload] = args; + + return { + type: "delegatecallvoucher", + destination, + payload, + }; + } } }; diff --git a/test/index.test.ts b/test/index.test.ts index c89fcd6..4f70ee9 100644 --- a/test/index.test.ts +++ b/test/index.test.ts @@ -10,7 +10,7 @@ import { describe, expect, test } from "@jest/globals"; describe("decode/encode", () => { test("input", () => { const blob = - "0xcc7dee1f000000000000000000000000000000000000000000000000000000000000000100000000000000000000000070ac08179605af2d9e75782b8decdd3c22aa4d0c000000000000000000000000f39fd6e51aad88f6f4ce6ab8827279cfffb92266000000000000000000000000000000000000000000000000000000000129bbad0000000000000000000000000000000000000000000000000000000066019521000000000000000000000000000000000000000000000000000000000000002a00000000000000000000000000000000000000000000000000000000000000e00000000000000000000000000000000000000000000000000000000000000004deadbeef00000000000000000000000000000000000000000000000000000000"; + "0x415bf363000000000000000000000000000000000000000000000000000000000000000100000000000000000000000070ac08179605af2d9e75782b8decdd3c22aa4d0c000000000000000000000000f39fd6e51aad88f6f4ce6ab8827279cfffb92266000000000000000000000000000000000000000000000000000000000129bbad00000000000000000000000000000000000000000000000000000000660195215a41539c3688747a1a8c7811b98b0427331ff73aab018eb5c9921993d617f314000000000000000000000000000000000000000000000000000000000000002a00000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000004deadbeef00000000000000000000000000000000000000000000000000000000"; const input = decodeInputBlob(blob); @@ -25,13 +25,16 @@ describe("decode/encode", () => { ); expect(input.blockNumber).toEqual(19512237n); expect(input.blockTimestamp).toEqual(1711379745n); + expect(input.prevRandao).toEqual( + 40823578488146031703637781058841789769586951870728503003341100870835983872788n, + ); expect(input.index).toEqual(42n); expect(input.payload).toEqual("0xdeadbeef"); }); test("input with empty payload", () => { const blob = - "0xcc7dee1f000000000000000000000000000000000000000000000000000000000000000100000000000000000000000070ac08179605af2d9e75782b8decdd3c22aa4d0c000000000000000000000000f39fd6e51aad88f6f4ce6ab8827279cfffb92266000000000000000000000000000000000000000000000000000000000129bbad0000000000000000000000000000000000000000000000000000000066019521000000000000000000000000000000000000000000000000000000000000002a00000000000000000000000000000000000000000000000000000000000000e00000000000000000000000000000000000000000000000000000000000000000"; + "0x415bf363000000000000000000000000000000000000000000000000000000000000000100000000000000000000000070ac08179605af2d9e75782b8decdd3c22aa4d0c000000000000000000000000f39fd6e51aad88f6f4ce6ab8827279cfffb92266000000000000000000000000000000000000000000000000000000000129bbad00000000000000000000000000000000000000000000000000000000660195215a41539c3688747a1a8c7811b98b0427331ff73aab018eb5c9921993d617f314000000000000000000000000000000000000000000000000000000000000002a00000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000"; const input = decodeInputBlob(blob); @@ -46,6 +49,9 @@ describe("decode/encode", () => { ); expect(input.blockNumber).toEqual(19512237n); expect(input.blockTimestamp).toEqual(1711379745n); + expect(input.prevRandao).toEqual( + 40823578488146031703637781058841789769586951870728503003341100870835983872788n, + ); expect(input.index).toEqual(42n); expect(input.payload).toEqual("0x"); }); @@ -129,4 +135,46 @@ describe("decode/encode", () => { throw new Error("expected output to be a voucher"); } }); + + test("delegate call voucher", () => { + const blob = + "0x10321e8b000000000000000000000000f39fd6e51aad88f6f4ce6ab8827279cfffb9226600000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000003fafafa0000000000000000000000000000000000000000000000000000000000"; + + const output = decodeOutputBlob(blob); + + expect(encodeOutputBlob(output)).toEqual(blob); + + switch (output.type) { + case "delegatecallvoucher": { + expect(output.destination).toEqual( + "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + ); + expect(output.payload).toEqual("0xfafafa"); + break; + } + default: + throw new Error("expected output to be a voucher"); + } + }); + + test("delegate call voucher with empty payload", () => { + const blob = + "0x10321e8b000000000000000000000000f39fd6e51aad88f6f4ce6ab8827279cfffb9226600000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000000"; + + const output = decodeOutputBlob(blob); + + expect(encodeOutputBlob(output)).toEqual(blob); + + switch (output.type) { + case "delegatecallvoucher": { + expect(output.destination).toEqual( + "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + ); + expect(output.payload).toEqual("0x"); + break; + } + default: + throw new Error("expected output to be a voucher"); + } + }); });