diff --git a/.changeset/nervous-kangaroos-visit.md b/.changeset/nervous-kangaroos-visit.md new file mode 100644 index 000000000..9cde3beb8 --- /dev/null +++ b/.changeset/nervous-kangaroos-visit.md @@ -0,0 +1,5 @@ +--- +"@ledgerhq/context-module": patch +--- + +Align array element with slice parameters diff --git a/packages/signer/context-module/src/shared/model/GenericPath.ts b/packages/signer/context-module/src/shared/model/GenericPath.ts index 8fdff29f4..c3c06bc26 100644 --- a/packages/signer/context-module/src/shared/model/GenericPath.ts +++ b/packages/signer/context-module/src/shared/model/GenericPath.ts @@ -74,13 +74,13 @@ export interface DataPathElementTuple { * Path element to navigate in an array of variable size. * - itemSize: the length of each item in that array (not the number of items which is variable). * - start: the start of the array slice to iterate on. If unset, start from the beginning of that array. - * - length: the length of the array slice to iterate on. If unset, iterate until the end of that array. + * - end: the end of the array slice to iterate on (exclusive). If unset, iterate until the end of that array. */ export interface DataPathElementArray { type: "ARRAY"; itemSize: number; start?: number; - length?: number; + end?: number; } // Path element to indicate the current item should be de-referenced (its value contains a pointer). diff --git a/packages/signer/context-module/src/transaction/data/CalldataDto.ts b/packages/signer/context-module/src/transaction/data/CalldataDto.ts index 234d8c0c7..42d00afae 100644 --- a/packages/signer/context-module/src/transaction/data/CalldataDto.ts +++ b/packages/signer/context-module/src/transaction/data/CalldataDto.ts @@ -137,7 +137,7 @@ export interface CalldataDescriptorPathElementTupleV1 { export interface CalldataDescriptorPathElementArrayV1 { type: "ARRAY"; start?: number; - length?: number; + end?: number; weight: number; } diff --git a/packages/signer/context-module/src/transaction/data/HttpTransactionDataSource.test.ts b/packages/signer/context-module/src/transaction/data/HttpTransactionDataSource.test.ts index c4590fc55..b7512a008 100644 --- a/packages/signer/context-module/src/transaction/data/HttpTransactionDataSource.test.ts +++ b/packages/signer/context-module/src/transaction/data/HttpTransactionDataSource.test.ts @@ -89,7 +89,7 @@ describe("HttpTransactionDataSource", () => { { type: "ARRAY", start: 0, - length: 5, + end: 5, weight: 1, }, { @@ -340,7 +340,7 @@ describe("HttpTransactionDataSource", () => { { type: "ARRAY", start: 0, - length: 5, + end: 5, itemSize: 1, }, { diff --git a/packages/signer/context-module/src/transaction/data/HttpTransactionDataSource.ts b/packages/signer/context-module/src/transaction/data/HttpTransactionDataSource.ts index a2cf414a0..e2b3daa4e 100644 --- a/packages/signer/context-module/src/transaction/data/HttpTransactionDataSource.ts +++ b/packages/signer/context-module/src/transaction/data/HttpTransactionDataSource.ts @@ -291,8 +291,7 @@ export class HttpTransactionDataSource implements TransactionDataSource { typeof data.weight === "number" && (typeof data.start === "undefined" || typeof data.start === "number") && - (typeof data.length === "undefined" || - typeof data.length === "number")) || + (typeof data.end === "undefined" || typeof data.end === "number")) || (data.type === "LEAF" && typeof data.leaf_type === "string" && ["ARRAY_LEAF", "TUPLE_LEAF", "STATIC_LEAF", "DYNAMIC_LEAF"].includes( diff --git a/packages/signer/signer-eth/src/internal/transaction/service/parser/TransactionParserService.test.ts b/packages/signer/signer-eth/src/internal/transaction/service/parser/TransactionParserService.test.ts index f0326503d..bd221b05f 100644 --- a/packages/signer/signer-eth/src/internal/transaction/service/parser/TransactionParserService.test.ts +++ b/packages/signer/signer-eth/src/internal/transaction/service/parser/TransactionParserService.test.ts @@ -277,7 +277,7 @@ describe("TransactionParserService", () => { type: "ARRAY", itemSize: 1, start: 0, - length: 1, + end: 1, }, { type: "REF", @@ -307,7 +307,7 @@ describe("TransactionParserService", () => { ]); }); - it("Extract all the elements of x[0][-1:]", () => { + it("Extract all the elements of x[0:-1][-1:]", () => { // GIVEN const path: DataPathElement[] = [ { @@ -321,7 +321,7 @@ describe("TransactionParserService", () => { type: "ARRAY", itemSize: 1, start: 0, - length: 1, + end: -1, }, { type: "REF", @@ -363,7 +363,7 @@ describe("TransactionParserService", () => { type: "ARRAY", itemSize: 1, start: 0, - length: 1, + end: 1, }, { type: "REF", @@ -372,7 +372,7 @@ describe("TransactionParserService", () => { type: "ARRAY", itemSize: 1, start: 2, - length: 1, + end: 3, }, { type: "LEAF", @@ -435,7 +435,7 @@ describe("TransactionParserService", () => { { type: "ARRAY", itemSize: 1, - length: 2, + end: 2, }, { type: "REF", @@ -471,7 +471,7 @@ describe("TransactionParserService", () => { type: "ARRAY", itemSize: 1, start: 2, - length: 1, + end: 3, }, { type: "REF", @@ -511,7 +511,7 @@ describe("TransactionParserService", () => { type: "ARRAY", itemSize: 1, start: 2, - length: 1, + end: 3, }, { type: "REF", @@ -548,7 +548,7 @@ describe("TransactionParserService", () => { type: "ARRAY", itemSize: 1, start: 2, - length: 1, + end: 3, }, { type: "REF", diff --git a/packages/signer/signer-eth/src/internal/transaction/service/parser/TransactionParserService.ts b/packages/signer/signer-eth/src/internal/transaction/service/parser/TransactionParserService.ts index 5ec6e5d0a..eb5d5ad6f 100644 --- a/packages/signer/signer-eth/src/internal/transaction/service/parser/TransactionParserService.ts +++ b/packages/signer/signer-eth/src/internal/transaction/service/parser/TransactionParserService.ts @@ -169,16 +169,20 @@ export class TransactionParserService { ? length + element.start : element.start; const end = - element.length === undefined ? length : start + element.length; + element.end === undefined + ? length + : element.end < 0 + ? length + element.end + : element.end; if ( start < 0 || start >= length || end > length || - start === end + start >= end ) { return Left( new Error( - `Array slice out of bounds, start=${element.start}, length=${element.length}`, + `Array slice out of bounds, start=${element.start}, end=${element.end}`, ), ); }