Skip to content
This repository has been archived by the owner on Sep 5, 2023. It is now read-only.

Abi memory #1066

Draft
wants to merge 88 commits into
base: cairo-1.0
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
88 commits
Select commit Hold shift + click to select a range
793838e
Make warplib a scarb project
rodrigo-pino Apr 17, 2023
bf9b585
Add maths module
rodrigo-pino Apr 18, 2023
00c9872
update corelib to alpha 7
rodrigo-pino Apr 18, 2023
692d01d
Add arm binaries from alpha 7
rodrigo-pino Apr 18, 2023
73370a8
Add warp plugin binaries
rodrigo-pino Apr 18, 2023
8f76b9d
Rework structure for
rodrigo-pino Apr 18, 2023
7a0e865
Fix warp dependency
rodrigo-pino Apr 18, 2023
73e4582
Fix warplib and delete files to ignore
rodrigo-pino Apr 19, 2023
b96fc7e
delete autogenerted warplib scripts
rodrigo-pino Apr 19, 2023
ab61da8
Add corelib and bin for linux_x64
rodrigo-pino Apr 19, 2023
f52d419
Scarb package name replaces - for _
rodrigo-pino Apr 19, 2023
7eeb1d1
Update compileCairo1 to use new binary
rodrigo-pino Apr 19, 2023
719cd0e
Update compilation testing framework
rodrigo-pino Apr 19, 2023
78e3da9
Some comments
rodrigo-pino Apr 19, 2023
1b79ba0
Merge branch 'wm-plugin-integration' of https://github.com/Nethermind…
rodrigo-pino Apr 19, 2023
40e08df
Address review
rodrigo-pino Apr 20, 2023
26c0c1a
Add unimplemented traits for WarpMemory
rodrigo-pino Apr 20, 2023
2b89fe6
Typo
rodrigo-pino Apr 20, 2023
bf3b9f5
Merge branch 'warp-memory-base-for-cairo1' into warplib-memory-to-cairo1
rodrigo-pino Apr 20, 2023
0c5bf41
Delete maths.cairo
rodrigo-pino Apr 20, 2023
a746825
Fix comp errors
rodrigo-pino Apr 20, 2023
0b028b3
Merge branch 'cairo-1.0' into warplib-memory-to-cairo1
rodrigo-pino Apr 21, 2023
3a6bd0b
Add array handling logic
rodrigo-pino Apr 21, 2023
f38cbcc
Fix some compilation errors
rodrigo-pino Apr 21, 2023
6b4289c
Make memory operations safe
rodrigo-pino Apr 24, 2023
95fdfb3
Merge branch 'cairo-1.0' into warplib-memory-to-cairo1
rodrigo-pino Apr 25, 2023
e7f2778
Update part of memory systems
rodrigo-pino Apr 25, 2023
d6a2904
Add implicit conversion cases
rodrigo-pino Apr 25, 2023
cac9aa9
fix typo
rodrigo-pino Apr 27, 2023
50c8b66
Merge branch 'warplib-memory-to-cairo1' into warp-memory-util-func-gen
rodrigo-pino Apr 27, 2023
60a0ed9
Array concat
rodrigo-pino May 1, 2023
4bc0ae1
Minor refactoring to importPath.ts
rodrigo-pino May 1, 2023
bdc2074
Use Serde trait to store/retrieve from memory (#1040)
piwonskp May 1, 2023
c32d021
Merge branch 'warplib-memory-to-cairo1' into warp-memory-util-func-gen
rodrigo-pino May 1, 2023
791a782
Address review
rodrigo-pino May 2, 2023
c8db599
Update read_id to get_or_create_id
rodrigo-pino May 2, 2023
68ab655
Merge branch 'warplib-memory-to-cairo1' into warp-memory-util-func-gen
rodrigo-pino May 2, 2023
8a8b504
Remove warplib/target
rodrigo-pino May 3, 2023
3a8d2d9
Update imports
rodrigo-pino May 3, 2023
2181a35
Rewrite memory to calldata
rodrigo-pino May 3, 2023
02bbc22
memory to storage
rodrigo-pino May 3, 2023
463eb66
Update workflow
rodrigo-pino May 8, 2023
0230865
Fix tsc compilation errors
rodrigo-pino May 8, 2023
ad0c204
Update warplib testing framwerk
rodrigo-pino May 8, 2023
7c166b6
Fix bugs and compilation erros in warplib
rodrigo-pino May 8, 2023
dd7b03f
Add unit tests to Warplib
rodrigo-pino May 8, 2023
b95e703
Remove warplib sierra
rodrigo-pino May 8, 2023
bdaf11e
calldata to memory
rodrigo-pino May 8, 2023
5a95fc3
Merge branch 'warplib-memory-to-cairo1' into warp-memory-util-func-gen
rodrigo-pino May 8, 2023
b1996f9
Add storage to memory
rodrigo-pino May 8, 2023
790b55d
Fix tsc compile bugs
rodrigo-pino May 9, 2023
6ea49ce
Add cairo1 compile and format for when using warp
rodrigo-pino May 9, 2023
79828bd
Update abi imports
rodrigo-pino May 11, 2023
2e6dd15
Improvements to memory util func gen
rodrigo-pino May 11, 2023
6731ab0
Other import updates
rodrigo-pino May 11, 2023
77e0e62
Fix some issues with imports
rodrigo-pino May 11, 2023
14c4893
Update a maths util function
rodrigo-pino May 11, 2023
682f8d2
Minor bug fixes in accessors
rodrigo-pino May 11, 2023
06083e7
Address review + add new test
rodrigo-pino May 11, 2023
4c6194e
Use into
rodrigo-pino May 11, 2023
e80d52e
Address review
rodrigo-pino May 12, 2023
2ebf940
Update warplib/src/test/warp_memory_test.cairo
rodrigo-pino May 15, 2023
5c05eb8
Update warplib/src/test/warp_memory_test.cairo
rodrigo-pino May 15, 2023
19e4e26
Update warplib/src/test/warp_memory_test.cairo
rodrigo-pino May 15, 2023
df86239
start_pos -> position
rodrigo-pino May 15, 2023
3078b2f
Fix and test change
rodrigo-pino May 15, 2023
4b1b152
Update warplib/src/test/warp_memory_test.cairo
rodrigo-pino May 16, 2023
ee13cf5
Update warplib/src/test/warp_memory_test.cairo
rodrigo-pino May 16, 2023
c9a9ef1
Update warplib/src/test/warp_memory_test.cairo
rodrigo-pino May 16, 2023
32fd4d8
Update warplib/src/test/warp_memory_test.cairo
rodrigo-pino May 16, 2023
741aa3d
Update warplib/src/test/warp_memory_test.cairo
rodrigo-pino May 16, 2023
0871e3c
Update warplib/src/test/warp_memory_test.cairo
rodrigo-pino May 16, 2023
d7f545b
Merge branch 'cairo-1.0' into warplib-memory-to-cairo1
rodrigo-pino May 16, 2023
5d7db50
Minor stuff
rodrigo-pino May 16, 2023
c24e2a5
Update warplib/src/test/warp_memory_test.cairo
rodrigo-pino May 16, 2023
fae6076
Remove starknet_accounts_devnet
rodrigo-pino May 16, 2023
c55a7dd
Merge branch 'warplib-memory-to-cairo1' into warp-memory-util-func-gen
rodrigo-pino May 16, 2023
468b241
Add super to importPaths
rodrigo-pino May 16, 2023
faa514a
Fix testing
rodrigo-pino May 16, 2023
6a885ef
Merge branch 'warplib-memory-to-cairo1' into warp-memory-util-func-gen
rodrigo-pino May 16, 2023
6d0a4d4
Improvments + linting
rodrigo-pino May 16, 2023
f07adc0
Remove mut
rodrigo-pino May 16, 2023
59db7df
Some minor fixes
rodrigo-pino May 17, 2023
239487f
Merge branch 'cairo-1.0' into warp-memory-util-func-gen
rodrigo-pino May 17, 2023
faad4d8
Fix
rodrigo-pino May 21, 2023
8fb17f7
linting
rodrigo-pino May 21, 2023
750cf03
Mergin'
rodrigo-pino May 22, 2023
08cbdb3
abi Enocde WIP
rjnrohit May 22, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"error",
{ "argsIgnorePattern": "^_", "varsIgnorePattern": "^_" }
],
"@typescript-eslint/ban-ts-comment": ["error", { "ts-ignore": "allow-with-description" }]
"@typescript-eslint/ban-ts-comment": ["error", { "ts-ignore": "allow-with-description" }],
"no-case-declarations": "off"
}
}
4 changes: 2 additions & 2 deletions src/cairoUtilFuncGen/abi/abiDecode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ import {
BYTE_ARRAY_TO_FELT_VALUE,
DYNAMIC_ARRAYS_UTIL,
FELT_TO_UINT256,
NARROW_SAFE,
U256_TO_FELT252,
U128_FROM_FELT,
WM_INDEX_DYN,
WM_NEW,
Expand Down Expand Up @@ -439,7 +439,7 @@ export class AbiDecode extends StringIndexedFuncGenWithAuxiliar {
this.requireImport(...U128_FROM_FELT),
this.requireImport(...WM_INDEX_DYN),
this.requireImport(...FELT_TO_UINT256),
this.requireImport(...NARROW_SAFE),
this.requireImport(...U256_TO_FELT252),
];

const funcInfo = {
Expand Down
81 changes: 38 additions & 43 deletions src/cairoUtilFuncGen/abi/abiEncode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,16 @@ import { printTypeNode } from '../../utils/astPrinter';
import { CairoType, MemoryLocation, TypeConversionContext } from '../../utils/cairoTypeSystem';
import { TranspileFailedError } from '../../utils/errors';
import {
ALLOC,
DYNAMIC_ARRAYS_UTIL,
FELT_ARRAY_TO_WARP_MEMORY_ARRAY,
FELT_TO_UINT256,
NARROW_SAFE,
U256_TO_FELT252,
U128_FROM_FELT,
WM_DYN_ARRAY_LENGTH,
WM_INDEX_DYN,
WM_NEW,
ARRAY,
ARRAY_TRAIT,
} from '../../utils/importPaths';
import {
getByteSize,
Expand Down Expand Up @@ -78,6 +79,8 @@ export class AbiEncode extends AbiBase {
);

const initialOffset = types.reduce(
// these sizes are not actual byte size of elements but the space it takes for the headencoding
// for more details: https://docs.soliditylang.org/en/develop/abi-spec.html#formal-specification-of-the-encoding
(pv, cv) => pv + BigInt(getByteSize(cv, this.ast.inference)),
0n,
);
Expand All @@ -86,23 +89,21 @@ export class AbiEncode extends AbiBase {
const funcName = `${this.functionName}${this.generatedFunctionsDef.size}`;
const code = endent`
#[implicit(warp_memory)]
func ${funcName}(${cairoParams}) -> (result_ptr : felt){
alloc_locals;
let bytes_index : felt = 0;
let bytes_offset : felt = ${initialOffset};
let (bytes_array : felt*) = alloc();
fn ${funcName}(${cairoParams}) -> felt252 {
let bytes_index: felt252 = 0; // current index of the array which would have the encodeded data
let bytes_offset: felt252 = ${initialOffset}; // var represents the length of final array which has encodeded data
let bytes_array: Array<felt252> = ArrayImpl::<felt252>::new(); // array which would have the encodeded data
${encodings.join('\n')}
let (max_length256) = felt_to_uint256(bytes_offset);
let (mem_ptr) = wm_new(max_length256, ${uint256(1)});
let mem_ptr = warp_memory.new_dynamic_array(bytes_offset, 1);
felt_array_to_warp_memory_array(0, bytes_array, 0, mem_ptr, bytes_offset);
return (mem_ptr,);
mem_ptr
}
`;

const importedFuncs = [
this.requireImport(...ALLOC),
this.requireImport(...ARRAY),
this.requireImport(...ARRAY_TRAIT),
this.requireImport(...U128_FROM_FELT),
this.requireImport(...FELT_TO_UINT256),
this.requireImport(...WM_NEW),
this.requireImport(...FELT_ARRAY_TO_WARP_MEMORY_ARRAY),
];
Expand Down Expand Up @@ -235,26 +236,25 @@ export class AbiEncode extends AbiBase {
const name = `${this.functionName}_head_dynamic_array${this.auxiliarGeneratedFunctions.size}`;
const code = endent`
#[implicit(warp_memory)]
func ${name}(
bytes_index: felt,
bytes_offset: felt,
bytes_array: felt*,
element_offset: felt,
mem_ptr : felt
) -> (final_bytes_index : felt, final_bytes_offset : felt){
alloc_locals;
fn ${name}(
bytes_index: felt252,
bytes_offset: felt252,
bytes_array: @Array<felt252>,
element_offset: felt252,
mem_ptr : felt252
) -> (felt252, felt252){
// Storing pointer to data
let (bytes_offset256) = felt_to_uint256(bytes_offset - element_offset);
${valueEncoding.name}(bytes_index, bytes_array, 0, bytes_offset256);
let new_index = bytes_index + 32;
// Storing the length
let (length256) = wm_dyn_array_length(mem_ptr);
let length = warp_memory.length_dyn(mem_ptr);
let length256 = felt_to_uint256(length);
${valueEncoding.name}(bytes_offset, bytes_array, 0, length256);
let bytes_offset = bytes_offset + 32;
// Storing the data
let (length) = narrow_safe(length256);
let bytes_offset_offset = bytes_offset + ${mul('length', elementByteSize)};
let (extended_offset) = ${tailEncoding.name}(
let extended_offset = ${tailEncoding.name}(
bytes_offset,
bytes_offset_offset,
bytes_array,
Expand All @@ -263,17 +263,14 @@ export class AbiEncode extends AbiBase {
length,
mem_ptr
);
return (
final_bytes_index=new_index,
final_bytes_offset=extended_offset
);
(new_index,extended_offset)
}
`;

const importedFuncs = [
this.requireImport(...WM_DYN_ARRAY_LENGTH),
this.requireImport(...FELT_TO_UINT256),
this.requireImport(...NARROW_SAFE),
this.requireImport(...U256_TO_FELT252),
];

const genFuncInfo = {
Expand Down Expand Up @@ -306,22 +303,20 @@ export class AbiEncode extends AbiBase {
const name = `${this.functionName}_tail_dynamic_array${this.auxiliarGeneratedFunctions.size}`;
const code = endent`
#[implicit(warp_memory)]
func ${name}(
bytes_index : felt,
bytes_offset : felt,
bytes_array : felt*,
element_offset : felt,
index : felt,
length : felt,
mem_ptr : felt
) -> (final_offset : felt){
alloc_locals;
if (index == length){
return (final_offset=bytes_offset);
fn ${name}(
bytes_index : felt252,
bytes_offset : felt252,
bytes_array : @Array<felt252>,
element_offset : felt252,
index : felt252,
length : felt252,
mem_ptr : felt252
) -> felt252{
if index == length {
bytes_offset;
}
let (index256) = felt_to_uint256(index);
let (elem_loc) = wm_index_dyn(mem_ptr, index256, ${uint256(elementTSize)});
let (elem) = ${readElement};
let elem_loc = warp_memory.index_dyn(mem_ptr, index, ${elementTSize});
let elem = ${readElement};
${headEncodingCode}
return ${name}(new_bytes_index, new_bytes_offset, bytes_array, element_offset, index + 1, length, mem_ptr);
}
Expand Down
4 changes: 2 additions & 2 deletions src/cairoUtilFuncGen/abi/abiEncodePacked.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import {
FELT_ARRAY_TO_WARP_MEMORY_ARRAY,
FELT_TO_UINT256,
FIXED_BYTES256_TO_FELT_DYNAMIC_ARRAY,
NARROW_SAFE,
U256_TO_FELT252,
U128_FROM_FELT,
WM_DYN_ARRAY_LENGTH,
WM_INDEX_DYN,
Expand Down Expand Up @@ -146,7 +146,7 @@ export class AbiEncodePacked extends AbiBase {
let (length) = narrow_safe(length256);
let (${newIndexVar}) = ${func.name}(bytes_index, bytes_array, 0, length, ${varToEncode});
`,
[this.requireImport(...WM_DYN_ARRAY_LENGTH), this.requireImport(...NARROW_SAFE), func],
[this.requireImport(...WM_DYN_ARRAY_LENGTH), this.requireImport(...U256_TO_FELT252), func],
];
}

Expand Down
4 changes: 2 additions & 2 deletions src/cairoUtilFuncGen/abi/indexEncode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
DYNAMIC_ARRAYS_UTIL,
FELT_ARRAY_TO_WARP_MEMORY_ARRAY,
FELT_TO_UINT256,
NARROW_SAFE,
U256_TO_FELT252,
U128_FROM_FELT,
WM_DYN_ARRAY_LENGTH,
WM_INDEX_DYN,
Expand Down Expand Up @@ -238,7 +238,7 @@ export class IndexEncode extends AbiBase {
const importedFuncs = [
this.requireImport(...WM_DYN_ARRAY_LENGTH),
this.requireImport(...FELT_TO_UINT256),
this.requireImport(...NARROW_SAFE),
this.requireImport(...U256_TO_FELT252),
];

const funcInfo = { name, code, functionsCalled: [...importedFuncs, tailEncoding] };
Expand Down
87 changes: 38 additions & 49 deletions src/cairoUtilFuncGen/calldata/calldataToMemory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import assert from 'assert';
import { createCairoGeneratedFunction, createCallToFunction } from '../../utils/functionGeneration';
import { CairoDynArray, CairoType, TypeConversionContext } from '../../utils/cairoTypeSystem';
import { add, delegateBasedOnType, GeneratedFunctionInfo, StringIndexedFuncGen } from '../base';
import { uint256 } from '../../warplib/utils';
import { NotSupportedYetError } from '../../utils/errors';
import { printTypeNode } from '../../utils/astPrinter';
import { mapRange, narrowBigIntSafe, typeNameFromTypeNode } from '../../utils/utils';
Expand All @@ -32,6 +31,7 @@ import {
U128_FROM_FELT,
WM_ALLOC,
WM_NEW,
WM_UNSAFE_WRITE,
} from '../../utils/importPaths';
import endent from 'endent';

Expand Down Expand Up @@ -96,44 +96,40 @@ export class CallDataToMemoryGen extends StringIndexedFuncGen {
if (isReferenceType(elementT)) {
const recursiveFunc = this.getOrCreateFuncDef(elementT);
copyCode = endent`
let cdElem = calldata[0];
let (mElem) = ${recursiveFunc.name}(cdElem);
dict_write{dict_ptr=warp_memory}(mem_start, mElem);
let calldata_elem = calldata[index];
let memory_elem = ${recursiveFunc.name}(calldata_elem);
warp_memory.unsafe_write(calldata_elem, memory_elem)
`;
auxFunc = recursiveFunc;
} else if (memoryElementWidth === 2) {
copyCode = endent`
dict_write{dict_ptr=warp_memory}(mem_start, calldata[0].low);
dict_write{dict_ptr=warp_memory}(mem_start+1, calldata[0].high);
warp_memory.unsafe_write(mem_ptr, calldata[index].low)
warp_memory.unsafe_write(mem_ptr + 1, calldata[index].high)
`;
auxFunc = this.requireImport(...DICT_WRITE);
auxFunc = this.requireImport(...WM_UNSAFE_WRITE);
} else {
copyCode = `dict_write{dict_ptr=warp_memory}(mem_start, calldata[0]);`;
auxFunc = this.requireImport(...DICT_WRITE);
copyCode = `warp_memory.unsafe_write(mem_start, calldata[index]);`;
auxFunc = this.requireImport(...WM_UNSAFE_WRITE);
}

const funcName = `cd_to_memory_dynamic_array${this.generatedFunctionsDef.size}`;
return {
name: funcName,
code: endent`
#[implicit(warp_memory)]
func ${funcName}_elem(calldata: ${callDataType.vPtr}, mem_start: felt, length: felt){
alloc_locals;
if (length == 0){
#[implicit(warp_memory: WarpMemory)]
fn ${funcName}_elem(calldata: ${callDataType}, mem_ptr: felt252, length: felt252) {
if index == length {
return ();
}
${copyCode}
return ${funcName}_elem(calldata + ${
callDataType.vPtr.to.width
}, mem_start + ${memoryElementWidth}, length - 1);
${funcName}_elem(calldata, mem_ptr + ${memoryElementWidth}, index + 1, length)
}
#[implicit(warp_memory)]
func ${funcName}(calldata : ${callDataType}) -> (mem_loc: felt){
alloc_locals;
let (len256) = felt_to_uint256(calldata.len);
let (mem_start) = wm_new(len256, ${uint256(memoryElementWidth)});
${funcName}_elem(calldata.ptr, mem_start + 2, calldata.len);
return (mem_start,);

#[implicit(warp_memory: WarpMemory)]
fn ${funcName}(calldata : ${callDataType}) -> felt{
let mem_start = warp_memory.new_dynamic_array(calldata.len, ${memoryElementWidth});
${funcName}_elem(calldata, mem_start + 1, calldata.len);
mem_start
}
`,
functionsCalled: [
Expand Down Expand Up @@ -161,37 +157,35 @@ export class CallDataToMemoryGen extends StringIndexedFuncGen {
const recursiveFunc = this.getOrCreateFuncDef(type.elementT);
copyCode = (index) =>
endent`
let cdElem = calldata[${index}];
let (mElem) = ${recursiveFunc.name}(cdElem);
dict_write{dict_ptr=warp_memory}(${loc(index)}, mElem);
let calldata_elem = calldata[${index}];
let memory_elem = ${recursiveFunc.name}(calldata_elem);
warp_memory.unsafe_write(${loc(index)}, memory_elem);
`;
funcCalls = [recursiveFunc];
} else if (memoryElementWidth === 2) {
copyCode = (index) =>
endent`
dict_write{dict_ptr=warp_memory}(${loc(index)}, calldata[${index}].low);
dict_write{dict_ptr=warp_memory}(${loc(index)} + 1, calldata[${index}].high);
warp_memory.unsafe_write(${loc(index)}, calldata[${index}].low);
warp_memory.unsafe_write(${loc(index)} + 1, calldata[${index}].high);
`;
} else {
copyCode = (index) => `dict_write{dict_ptr=warp_memory}(${loc(index)}, calldata[${index}]);`;
copyCode = (index) => `warp_memory.unsafe_write(${loc(index)}, calldata[${index}]);`;
}

const funcName = `cd_to_memory_static_array${this.generatedFunctionsDef.size}`;
return {
name: funcName,
code: endent`
#[implicit(warp_memory)]
func ${funcName}(calldata : ${callDataType}) -> (mem_loc: felt){
alloc_locals;
let (mem_start) = wm_alloc(${uint256(memoryType.width)});
#[implicit(warp_memory: WarpMemory)]
fn ${funcName}(calldata : ${callDataType}) -> felt252{
let mem_start = warp_memory.alloc(${memoryType.width});
${mapRange(narrowBigIntSafe(type.size), (n) => copyCode(n)).join('\n')}
return (mem_start,);
mem_start
}
`,
functionsCalled: [
this.requireImport(...WM_ALLOC),
this.requireImport(...U128_FROM_FELT),
this.requireImport(...DICT_WRITE),
...funcCalls,
],
};
Expand All @@ -211,8 +205,8 @@ export class CallDataToMemoryGen extends StringIndexedFuncGen {
if (isReferenceType(type)) {
const recursiveFunc = this.getOrCreateFuncDef(type);
const code = [
`let (member_${decl.name}) = ${recursiveFunc.name}(calldata.${decl.name});`,
`dict_write{dict_ptr=warp_memory}(${add('mem_start', offset)}, member_${decl.name});`,
`let member_${decl.name} = ${recursiveFunc.name}(calldata.${decl.name});`,
`warp_memory.unsafe_write(${add('mem_start', offset)}, member_${decl.name});`,
].join('\n');
return [[...copyCode, code], [...funcCalls, recursiveFunc], offset + 1];
}
Expand All @@ -221,16 +215,12 @@ export class CallDataToMemoryGen extends StringIndexedFuncGen {
const code =
memberWidth === 2
? [
`dict_write{dict_ptr=warp_memory}(${add('mem_start', offset)}, calldata.${
decl.name
}.low);`,
`dict_write{dict_ptr=warp_memory}(${add('mem_start', offset + 1)}, calldata.${
`warp_memory.unsafe_write(${add('mem_start', offset)}, calldata.${decl.name}.low);`,
`warp_memory.unsafe_write(${add('mem_start', offset + 1)}, calldata.${
decl.name
}.high);`,
].join('\n')
: `dict_write{dict_ptr=warp_memory}(${add('mem_start', offset)}, calldata.${
decl.name
});`;
: `warp_memory.unsafe_write(${add('mem_start', offset)}, calldata.${decl.name});`;
return [[...copyCode, code], funcCalls, offset + memberWidth];
},
[new Array<string>(), new Array<CairoFunctionDefinition>(), 0],
Expand All @@ -240,12 +230,11 @@ export class CallDataToMemoryGen extends StringIndexedFuncGen {
return {
name: funcName,
code: endent`
#[implicit(warp_memory)]
func ${funcName}(calldata : ${calldataType}) -> (mem_loc: felt){
alloc_locals;
let (mem_start) = wm_alloc(${uint256(memoryType.width)});
#[implicit(warp_memory: WarpMemory)]
fn ${funcName}(calldata : ${calldataType}) -> felt252 {
let mem_start = warp_memory.alloc(${memoryType.width});
${copyCode.join('\n')}
return (mem_start,
mem_start
}
`,
functionsCalled: [
Expand Down
Loading