diff --git a/src/cairoUtilFuncGen/memory/memoryRead.ts b/src/cairoUtilFuncGen/memory/memoryRead.ts index 24c1f0fea..b3245e014 100644 --- a/src/cairoUtilFuncGen/memory/memoryRead.ts +++ b/src/cairoUtilFuncGen/memory/memoryRead.ts @@ -11,13 +11,13 @@ import { CairoFunctionDefinition, typeNameFromTypeNode } from '../../export'; import { CairoFelt, CairoType, - CairoUint256, + CairoUint, MemoryLocation, TypeConversionContext, } from '../../utils/cairoTypeSystem'; import { cloneASTNode } from '../../utils/cloning'; import { createCairoGeneratedFunction, createCallToFunction } from '../../utils/functionGeneration'; -import { DICT_READ, WM_READ256, WM_READ_FELT, WM_READ_ID } from '../../utils/importPaths'; +import { DICT_READ, WARPLIB_MEMORY, WM_READ_FELT, WM_READ_ID } from '../../utils/importPaths'; import { createNumberLiteral, createNumberTypeName } from '../../utils/nodeTemplates'; import { isDynamicArray, safeGetNodeType } from '../../utils/nodeTypeProcessing'; import { add, GeneratedFunctionInfo, locationIfComplexType, StringIndexedFuncGen } from '../base'; @@ -83,8 +83,13 @@ export class MemoryReadGen extends StringIndexedFuncGen { funcDef = this.requireImport(...WM_READ_ID, inputs, outputs); } else if (resultCairoType instanceof CairoFelt) { funcDef = this.requireImport(...WM_READ_FELT, inputs, outputs); - } else if (resultCairoType.fullStringRepresentation === CairoUint256.fullStringRepresentation) { - funcDef = this.requireImport(...WM_READ256, inputs, outputs); + } else if (resultCairoType instanceof CairoUint) { + funcDef = this.requireImport( + [...WARPLIB_MEMORY], + `wm_read_${resultCairoType.nBits}`, + inputs, + outputs, + ); } else { const funcInfo = this.getOrCreate(resultCairoType); funcDef = createCairoGeneratedFunction(funcInfo, inputs, outputs, this.ast, this.sourceUnit, { diff --git a/src/cairoUtilFuncGen/memory/memoryToCalldata.ts b/src/cairoUtilFuncGen/memory/memoryToCalldata.ts index ac0f151db..c2e368d7b 100644 --- a/src/cairoUtilFuncGen/memory/memoryToCalldata.ts +++ b/src/cairoUtilFuncGen/memory/memoryToCalldata.ts @@ -22,9 +22,9 @@ import { createCairoGeneratedFunction, createCallToFunction } from '../../utils/ import { ALLOC, NARROW_SAFE, - WM_READ256, U128_FROM_FELT, U32_FROM_FELT, + WARPLIB_MEMORY, } from '../../utils/importPaths'; import { getElementType, @@ -204,7 +204,7 @@ export class MemoryToCallDataGen extends StringIndexedFuncGen { functionsCalled: [ this.requireImport(...ALLOC), this.requireImport(...NARROW_SAFE), - this.requireImport(...WM_READ256), + this.requireImport([...WARPLIB_MEMORY], 'wm_read_256'), calldataDynArrayStruct, ...dynArrayReaderInfo.functionsCalled, ], @@ -279,7 +279,7 @@ export class MemoryToCallDataGen extends StringIndexedFuncGen { const memberFeltSize = CairoType.fromSol(type, this.ast).width; return [ - [`let member${index} = *warp_memory.at(u32_from_felt(${add('mem_loc', offset)}));`], + [`let member${index} = *warp_memory.at(u32_from_felt252(${add('mem_loc', offset)}));`], [this.requireImport(...U32_FROM_FELT)], offset + memberFeltSize, ]; diff --git a/src/cairoUtilFuncGen/memory/memoryWrite.ts b/src/cairoUtilFuncGen/memory/memoryWrite.ts index cc8c2c5b4..693cd756c 100644 --- a/src/cairoUtilFuncGen/memory/memoryWrite.ts +++ b/src/cairoUtilFuncGen/memory/memoryWrite.ts @@ -1,12 +1,12 @@ import { Expression, FunctionCall, TypeNode, DataLocation, PointerType } from 'solc-typed-ast'; -import { CairoFelt, CairoType, CairoUint256 } from '../../utils/cairoTypeSystem'; +import { CairoFelt, CairoType, CairoUint } from '../../utils/cairoTypeSystem'; import { cloneASTNode } from '../../utils/cloning'; import { createCairoGeneratedFunction, createCallToFunction, ParameterInfo, } from '../../utils/functionGeneration'; -import { DICT_WRITE, WM_WRITE256, WM_WRITE_FELT } from '../../utils/importPaths'; +import { DICT_WRITE, WARPLIB_MEMORY, WM_WRITE_FELT } from '../../utils/importPaths'; import { safeGetNodeType } from '../../utils/nodeTypeProcessing'; import { typeNameFromTypeNode } from '../../utils/utils'; import { add, GeneratedFunctionInfo, StringIndexedFuncGen } from '../base'; @@ -49,10 +49,15 @@ export class MemoryWriteGen extends StringIndexedFuncGen { const cairoTypeToWrite = CairoType.fromSol(typeToWrite, this.ast); if (cairoTypeToWrite instanceof CairoFelt) { return this.requireImport(...WM_WRITE_FELT, inputs, outputs); - } else if ( - cairoTypeToWrite.fullStringRepresentation === CairoUint256.fullStringRepresentation - ) { - return this.requireImport(...WM_WRITE256, inputs, outputs); + } + + if (cairoTypeToWrite instanceof CairoUint) { + return this.requireImport( + [...WARPLIB_MEMORY], + `wm_write_${cairoTypeToWrite.nBits}`, + inputs, + outputs, + ); } const funcInfo = this.getOrCreate(typeToWrite); diff --git a/src/cairoUtilFuncGen/serialisation.ts b/src/cairoUtilFuncGen/serialisation.ts index 06ebb0858..819bd5df4 100644 --- a/src/cairoUtilFuncGen/serialisation.ts +++ b/src/cairoUtilFuncGen/serialisation.ts @@ -3,6 +3,7 @@ import { CairoStaticArray, CairoStruct, CairoType, + CairoUint, CairoUint256, WarpLocation, } from '../utils/cairoTypeSystem'; @@ -48,24 +49,30 @@ function producePackExpression(type: CairoType): (string | Read)[] { ')', ]; } - if (type instanceof CairoStruct) { + + if (type instanceof CairoUint) { if (type.fullStringRepresentation === CairoUint256.fullStringRepresentation) { return [ - type.name, + type.toString(), '{', - ...[...type.members.entries()] + ...[ + ['low', new CairoUint(128)], + ['high', new CairoUint(128)], + ] .flatMap(([memberName, memberType]) => [ - memberName, + memberName as string, ':', - 'u128_from_felt252(', - ...producePackExpression(memberType), - ')', + ...producePackExpression(memberType as CairoType), ',', ]) .slice(0, -1), '}', ]; } + return [`core::integer::${type.toString()}_from_felt252(${Read.Felt})`]; + } + + if (type instanceof CairoStruct) { return [ type.name, '{', diff --git a/src/cairoUtilFuncGen/storage/storageWrite.ts b/src/cairoUtilFuncGen/storage/storageWrite.ts index b7ccb8555..c0b50c3be 100644 --- a/src/cairoUtilFuncGen/storage/storageWrite.ts +++ b/src/cairoUtilFuncGen/storage/storageWrite.ts @@ -1,12 +1,18 @@ import endent from 'endent'; import { Expression, FunctionCall, TypeNode, DataLocation, PointerType } from 'solc-typed-ast'; -import { CairoType, CairoUint256, TypeConversionContext } from '../../utils/cairoTypeSystem'; +import { + CairoType, + CairoUint, + CairoUint256, + TypeConversionContext, +} from '../../utils/cairoTypeSystem'; import { cloneASTNode } from '../../utils/cloning'; import { createCairoGeneratedFunction, createCallToFunction } from '../../utils/functionGeneration'; import { U128_TO_FELT } from '../../utils/importPaths'; import { safeGetNodeType } from '../../utils/nodeTypeProcessing'; import { typeNameFromTypeNode } from '../../utils/utils'; import { add, GeneratedFunctionInfo, StringIndexedFuncGen } from '../base'; +import { toFeltfromuXImport } from '../utils/uNselector'; export class StorageWriteGen extends StringIndexedFuncGen { public gen(storageLocation: Expression, writeValue: Expression): FunctionCall { @@ -55,11 +61,16 @@ export class StorageWriteGen extends StringIndexedFuncGen { TypeConversionContext.StorageAllocation, ); const cairoTypeString = cairoTypeToWrite.toString(); + const fnsToImport: [string[], string][] = []; const writeCode = cairoTypeToWrite .serialiseMembers('value') .map((name, index) => { if (cairoTypeToWrite.fullStringRepresentation === CairoUint256.fullStringRepresentation) { name = `u128_to_felt252(${name})`; + fnsToImport.push(U128_TO_FELT); + } else if (cairoTypeToWrite instanceof CairoUint) { + name = `${cairoTypeString}_to_felt252(${name})`; + fnsToImport.push(toFeltfromuXImport(cairoTypeToWrite)); } return ` ${write(add('loc', index), name)}`; }) @@ -74,7 +85,7 @@ export class StorageWriteGen extends StringIndexedFuncGen { return value; } `, - functionsCalled: [this.requireImport(...U128_TO_FELT)], + functionsCalled: [...fnsToImport.map((imp) => this.requireImport(...imp))], }; return funcInfo; } diff --git a/src/cairoUtilFuncGen/utils/uNselector.ts b/src/cairoUtilFuncGen/utils/uNselector.ts new file mode 100644 index 000000000..20b2577a0 --- /dev/null +++ b/src/cairoUtilFuncGen/utils/uNselector.ts @@ -0,0 +1,203 @@ +import { CairoUint } from '../../export'; +import { + U8_TO_FELT, + U16_TO_FELT, + U24_TO_FELT, + U32_TO_FELT, + U40_TO_FELT, + U48_TO_FELT, + U56_TO_FELT, + U64_TO_FELT, + U72_TO_FELT, + U80_TO_FELT, + U88_TO_FELT, + U96_TO_FELT, + U104_TO_FELT, + U112_TO_FELT, + U120_TO_FELT, + U128_TO_FELT, + U136_TO_FELT, + U144_TO_FELT, + U152_TO_FELT, + U160_TO_FELT, + U168_TO_FELT, + U176_TO_FELT, + U184_TO_FELT, + U192_TO_FELT, + U200_TO_FELT, + U208_TO_FELT, + U216_TO_FELT, + U224_TO_FELT, + U232_TO_FELT, + U240_TO_FELT, + U248_TO_FELT, + U8_FROM_FELT, + U16_FROM_FELT, + U24_FROM_FELT, + U32_FROM_FELT, + U40_FROM_FELT, + U48_FROM_FELT, + U56_FROM_FELT, + U64_FROM_FELT, + U72_FROM_FELT, + U80_FROM_FELT, + U88_FROM_FELT, + U96_FROM_FELT, + U104_FROM_FELT, + U112_FROM_FELT, + U120_FROM_FELT, + U128_FROM_FELT, + U136_FROM_FELT, + U144_FROM_FELT, + U152_FROM_FELT, + U160_FROM_FELT, + U168_FROM_FELT, + U176_FROM_FELT, + U184_FROM_FELT, + U192_FROM_FELT, + U200_FROM_FELT, + U208_FROM_FELT, + U216_FROM_FELT, + U224_FROM_FELT, + U232_FROM_FELT, + U240_FROM_FELT, + U248_FROM_FELT, +} from '../../utils/importPaths'; + +export const toFeltfromuXImport = (uNtype: CairoUint) => { + switch (uNtype.toString()) { + case 'u8': + return U8_TO_FELT; + case 'u16': + return U16_TO_FELT; + case 'u24': + return U24_TO_FELT; + case 'u32': + return U32_TO_FELT; + case 'u40': + return U40_TO_FELT; + case 'u48': + return U48_TO_FELT; + case 'u56': + return U56_TO_FELT; + case 'u64': + return U64_TO_FELT; + case 'u72': + return U72_TO_FELT; + case 'u80': + return U80_TO_FELT; + case 'u88': + return U88_TO_FELT; + case 'u96': + return U96_TO_FELT; + case 'u104': + return U104_TO_FELT; + case 'u112': + return U112_TO_FELT; + case 'u120': + return U120_TO_FELT; + case 'u128': + return U128_TO_FELT; + case 'u136': + return U136_TO_FELT; + case 'u144': + return U144_TO_FELT; + case 'u152': + return U152_TO_FELT; + case 'u160': + return U160_TO_FELT; + case 'u168': + return U168_TO_FELT; + case 'u176': + return U176_TO_FELT; + case 'u184': + return U184_TO_FELT; + case 'u192': + return U192_TO_FELT; + case 'u200': + return U200_TO_FELT; + case 'u208': + return U208_TO_FELT; + case 'u216': + return U216_TO_FELT; + case 'u224': + return U224_TO_FELT; + case 'u232': + return U232_TO_FELT; + case 'u240': + return U240_TO_FELT; + case 'u248': + return U248_TO_FELT; + default: + throw new Error('Invalid CairoUint type'); + } +}; + +export const getFeltfromuXImport = (uNtype: CairoUint) => { + switch (uNtype.toString()) { + case 'u8': + return U8_FROM_FELT; + case 'u16': + return U16_FROM_FELT; + case 'u24': + return U24_FROM_FELT; + case 'u32': + return U32_FROM_FELT; + case 'u40': + return U40_FROM_FELT; + case 'u48': + return U48_FROM_FELT; + case 'u56': + return U56_FROM_FELT; + case 'u64': + return U64_FROM_FELT; + case 'u72': + return U72_FROM_FELT; + case 'u80': + return U80_FROM_FELT; + case 'u88': + return U88_FROM_FELT; + case 'u96': + return U96_FROM_FELT; + case 'u104': + return U104_FROM_FELT; + case 'u112': + return U112_FROM_FELT; + case 'u120': + return U120_FROM_FELT; + case 'u128': + return U128_FROM_FELT; + case 'u136': + return U136_FROM_FELT; + case 'u144': + return U144_FROM_FELT; + case 'u152': + return U152_FROM_FELT; + case 'u160': + return U160_FROM_FELT; + case 'u168': + return U168_FROM_FELT; + case 'u176': + return U176_FROM_FELT; + case 'u184': + return U184_FROM_FELT; + case 'u192': + return U192_FROM_FELT; + case 'u200': + return U200_FROM_FELT; + case 'u208': + return U208_FROM_FELT; + case 'u216': + return U216_FROM_FELT; + case 'u224': + return U224_FROM_FELT; + case 'u232': + return U232_FROM_FELT; + case 'u240': + return U240_FROM_FELT; + case 'u248': + return U248_FROM_FELT; + default: + throw new Error('Invalid CairoUint type'); + } +}; diff --git a/src/cairoWriter/writers/literalWriter.ts b/src/cairoWriter/writers/literalWriter.ts index 263564b20..1e9126e89 100644 --- a/src/cairoWriter/writers/literalWriter.ts +++ b/src/cairoWriter/writers/literalWriter.ts @@ -1,24 +1,28 @@ import { ASTWriter, Literal, LiteralKind, SrcDesc } from 'solc-typed-ast'; import { TranspileFailedError } from '../../utils/errors'; -import { divmod, primitiveTypeToCairo } from '../../utils/utils'; +import { primitiveTypeToCairo, isCairoPrimitiveIntType } from '../../utils/utils'; import { CairoASTNodeWriter } from '../base'; +import { CairoUint256, divmod } from '../../export'; export class LiteralWriter extends CairoASTNodeWriter { writeInner(node: Literal, _: ASTWriter): SrcDesc { + const type = primitiveTypeToCairo(node.typeString); switch (node.kind) { case LiteralKind.Number: - switch (primitiveTypeToCairo(node.typeString)) { - case 'Uint256': { + if (isCairoPrimitiveIntType(type)) { + if (type === CairoUint256.toString()) { const [high, low] = divmod(BigInt(node.value), BigInt(Math.pow(2, 128))); return [`u256_from_felts( ${low}, ${high} )`]; } - case 'ContractAddress': - return [`starknet::contract_address_const::<${node.value}>()`]; - case 'felt': - return [node.value]; - default: - throw new TranspileFailedError('Attempted to write unexpected cairo type'); + return [`${node.value}_${type}`]; + } else if (type === 'ContractAddress') { + return [`starknet::contract_address_const::<${node.value}>()`]; + } else if (type === 'felt') { + return [node.value]; + } else { + throw new TranspileFailedError(`Attempted to write unexpected cairo type: ${type}`); } + case LiteralKind.Bool: return [node.value === 'true' ? '1' : '0']; case LiteralKind.String: @@ -33,18 +37,19 @@ export class LiteralWriter extends CairoASTNodeWriter { return [`0x${node.hexValue}`]; } case LiteralKind.HexString: - switch (primitiveTypeToCairo(node.typeString)) { - case 'Uint256': { + if (isCairoPrimitiveIntType(type)) { + if (type === CairoUint256.toString()) { return [ `u256_from_felts( ${node.hexValue.slice(32, 64)}, ${node.hexValue.slice(0, 32)} )`, ]; } - case 'ContractAddress': - return [`starknet::contract_address_const::<${node.hexValue}>()`]; - case 'felt': - return [`0x${node.hexValue}`]; - default: - throw new TranspileFailedError('Attempted to write unexpected cairo type'); + return [`0x${node.hexValue}_${type}`]; + } else if (type === 'ContractAddress') { + return [`starknet::contract_address_const::<${node.hexValue}>()`]; + } else if (type === 'felt') { + return [`0x${node.hexValue}`]; + } else { + throw new TranspileFailedError('Attempted to write unexpected cairo type'); } } } diff --git a/src/passes/cairoUtilImporter.ts b/src/passes/cairoUtilImporter.ts index 084c3a3b0..cde89f9d4 100644 --- a/src/passes/cairoUtilImporter.ts +++ b/src/passes/cairoUtilImporter.ts @@ -42,7 +42,7 @@ export class CairoUtilImporter extends ASTMapper { visitElementaryTypeName(node: ElementaryTypeName, ast: AST): void { const cairoType = primitiveTypeToCairo(node.name); - if (cairoType === 'Uint256') { + if (cairoType === 'u256') { createImport(...U128_FROM_FELT, this.dummySourceUnit ?? node, ast); } else if (cairoType === 'ContractAddress') { createImport(...CONTRACT_ADDRESS, this.dummySourceUnit ?? node, ast); diff --git a/src/utils/cairoTypeSystem.ts b/src/utils/cairoTypeSystem.ts index 7e1689ca3..551f646c5 100644 --- a/src/utils/cairoTypeSystem.ts +++ b/src/utils/cairoTypeSystem.ts @@ -92,11 +92,11 @@ export abstract class CairoType { return new WarpLocation(); } } else if (tp instanceof FixedBytesType) { - return tp.size === 32 ? CairoUint256 : new CairoFelt(); + return new CairoUint(tp.size * 8); } else if (tp instanceof FunctionType) { throw new NotSupportedYetError('Serialising FunctionType not supported yet'); } else if (tp instanceof IntType) { - return tp.nBits > 251 ? CairoUint256 : new CairoFelt(); + return new CairoUint(tp.nBits); } else if (tp instanceof MappingType) { return new WarpLocation(); } else if (tp instanceof PointerType) { @@ -169,6 +169,26 @@ export class CairoFelt extends CairoType { } } +export class CairoUint extends CairoType { + constructor(public nBits: number = 256) { + super(); + } + get fullStringRepresentation(): string { + return `[u${this.nBits}]`; + } + toString(): string { + return `u${this.nBits}`; + } + get width(): number { + if (this.nBits === 256) return 2; + return 1; + } + serialiseMembers(name: string): string[] { + if (this.nBits === 256) return [`${name}.low`, `${name}.high`]; + return [name]; + } +} + export class CairoContractAddress extends CairoType { get fullStringRepresentation(): string { return '[ContractAddress]'; @@ -292,13 +312,7 @@ export class WarpLocation extends CairoFelt { export class MemoryLocation extends CairoFelt {} -export const CairoUint256 = new CairoStruct( - 'u256', - new Map([ - ['low', new CairoFelt()], - ['high', new CairoFelt()], - ]), -); +export const CairoUint256 = new CairoUint(256); const cd_dynarray_prefix = 'cd_dynarray_'; export function generateCallDataDynArrayStructName(elementType: TypeNode, ast: AST): string { diff --git a/src/utils/importFuncGenerator.ts b/src/utils/importFuncGenerator.ts index 6655a27ba..4528c4cfc 100644 --- a/src/utils/importFuncGenerator.ts +++ b/src/utils/importFuncGenerator.ts @@ -26,9 +26,69 @@ import { IS_LE, IS_LE_FELT, SPLIT_FELT, + U8_TO_FELT, + U16_TO_FELT, + U24_TO_FELT, + U32_TO_FELT, + U40_TO_FELT, + U48_TO_FELT, + U56_TO_FELT, + U64_TO_FELT, + U72_TO_FELT, + U80_TO_FELT, + U88_TO_FELT, + U96_TO_FELT, + U104_TO_FELT, + U112_TO_FELT, + U120_TO_FELT, U128_TO_FELT, + U136_TO_FELT, + U144_TO_FELT, + U152_TO_FELT, + U160_TO_FELT, + U168_TO_FELT, + U176_TO_FELT, + U184_TO_FELT, + U192_TO_FELT, + U200_TO_FELT, + U208_TO_FELT, + U216_TO_FELT, + U224_TO_FELT, + U232_TO_FELT, + U240_TO_FELT, + U248_TO_FELT, U256_FROM_FELTS, + U8_FROM_FELT, + U16_FROM_FELT, + U24_FROM_FELT, + U32_FROM_FELT, + U40_FROM_FELT, + U48_FROM_FELT, + U56_FROM_FELT, + U64_FROM_FELT, + U72_FROM_FELT, + U80_FROM_FELT, + U88_FROM_FELT, + U96_FROM_FELT, + U104_FROM_FELT, + U112_FROM_FELT, + U120_FROM_FELT, U128_FROM_FELT, + U136_FROM_FELT, + U144_FROM_FELT, + U152_FROM_FELT, + U160_FROM_FELT, + U168_FROM_FELT, + U176_FROM_FELT, + U184_FROM_FELT, + U192_FROM_FELT, + U200_FROM_FELT, + U208_FROM_FELT, + U216_FROM_FELT, + U224_FROM_FELT, + U232_FROM_FELT, + U240_FROM_FELT, + U248_FROM_FELT, UINT256_ADD, UINT256_EQ, UINT256_LE, @@ -38,8 +98,6 @@ import { INTO, ARRAY, ARRAY_TRAIT, - U32_FROM_FELT, - U32_TO_FELT, WARP_MEMORY, MEMORY_TRAIT, CONTRACT_ADDRESS, @@ -107,7 +165,37 @@ export function createImport( return createFuncImport('dict_ptr'); case encodePath(DICT_ACCESS): return createStructImport(); + case encodePath(U8_FROM_FELT): + case encodePath(U16_FROM_FELT): + case encodePath(U24_FROM_FELT): + case encodePath(U32_FROM_FELT): + case encodePath(U40_FROM_FELT): + case encodePath(U48_FROM_FELT): + case encodePath(U56_FROM_FELT): + case encodePath(U64_FROM_FELT): + case encodePath(U72_FROM_FELT): + case encodePath(U80_FROM_FELT): + case encodePath(U88_FROM_FELT): + case encodePath(U96_FROM_FELT): + case encodePath(U104_FROM_FELT): + case encodePath(U112_FROM_FELT): + case encodePath(U120_FROM_FELT): case encodePath(U128_FROM_FELT): + case encodePath(U136_FROM_FELT): + case encodePath(U144_FROM_FELT): + case encodePath(U152_FROM_FELT): + case encodePath(U160_FROM_FELT): + case encodePath(U168_FROM_FELT): + case encodePath(U176_FROM_FELT): + case encodePath(U184_FROM_FELT): + case encodePath(U192_FROM_FELT): + case encodePath(U200_FROM_FELT): + case encodePath(U208_FROM_FELT): + case encodePath(U216_FROM_FELT): + case encodePath(U224_FROM_FELT): + case encodePath(U232_FROM_FELT): + case encodePath(U240_FROM_FELT): + case encodePath(U248_FROM_FELT): return createStructImport(); case encodePath(SPLIT_FELT): case encodePath(IS_LE): @@ -127,12 +215,40 @@ export function createImport( // Import libraries from Cairo1 case encodePath(INTO): case encodePath(CONTRACT_ADDRESS): + case encodePath(U8_TO_FELT): + case encodePath(U16_TO_FELT): + case encodePath(U24_TO_FELT): + case encodePath(U32_TO_FELT): + case encodePath(U40_TO_FELT): + case encodePath(U48_TO_FELT): + case encodePath(U56_TO_FELT): + case encodePath(U64_TO_FELT): + case encodePath(U72_TO_FELT): + case encodePath(U80_TO_FELT): + case encodePath(U88_TO_FELT): + case encodePath(U96_TO_FELT): + case encodePath(U104_TO_FELT): + case encodePath(U112_TO_FELT): + case encodePath(U120_TO_FELT): case encodePath(U128_TO_FELT): + case encodePath(U136_TO_FELT): + case encodePath(U144_TO_FELT): + case encodePath(U152_TO_FELT): + case encodePath(U160_TO_FELT): + case encodePath(U168_TO_FELT): + case encodePath(U176_TO_FELT): + case encodePath(U184_TO_FELT): + case encodePath(U192_TO_FELT): + case encodePath(U200_TO_FELT): + case encodePath(U208_TO_FELT): + case encodePath(U216_TO_FELT): + case encodePath(U224_TO_FELT): + case encodePath(U232_TO_FELT): + case encodePath(U240_TO_FELT): + case encodePath(U248_TO_FELT): case encodePath(U256_FROM_FELTS): case encodePath(ARRAY): case encodePath(ARRAY_TRAIT): - case encodePath(U32_FROM_FELT): - case encodePath(U32_TO_FELT): case encodePath(WARP_MEMORY): case encodePath(MEMORY_TRAIT): return createFuncImport(); diff --git a/src/utils/importPaths.ts b/src/utils/importPaths.ts index fcd01ee06..a65ce1db9 100644 --- a/src/utils/importPaths.ts +++ b/src/utils/importPaths.ts @@ -86,24 +86,143 @@ export const WM_DYN_ARRAY_LENGTH: [string[], string] = [[...WARPLIB_MEMORY], 'wm export const WM_INDEX_DYN: [string[], string] = [[...WARPLIB_MEMORY], 'wm_index_dyn']; export const WM_INDEX_STATIC: [string[], string] = [[...WARPLIB_MEMORY], 'wm_index_static']; export const WM_NEW: [string[], string] = [[...WARPLIB_MEMORY], 'wm_new']; -export const WM_READ256: [string[], string] = [[...WARPLIB_MEMORY], 'wm_read_256']; export const WM_READ_FELT: [string[], string] = [[...WARPLIB_MEMORY], 'wm_read_felt']; export const WM_READ_ID: [string[], string] = [[...WARPLIB_MEMORY], 'wm_read_id']; export const WM_TO_FELT_ARRAY: [string[], string] = [[...WARPLIB_MEMORY], 'wm_to_felt_array']; export const WM_ALLOC: [string[], string] = [[...WARPLIB_MEMORY], 'wm_alloc']; -export const WM_WRITE256: [string[], string] = [[...WARPLIB_MEMORY], 'wm_write_256']; export const WM_WRITE_FELT: [string[], string] = [[...WARPLIB_MEMORY], 'wm_write_felt']; - -//------------------------------------------------------ - export const ARRAY: [string[], string] = [['array'], 'Array']; export const ARRAY_TRAIT: [string[], string] = [['array'], 'ArrayTrait']; export const U256_FROM_FELTS: [string[], string] = [['warplib', 'integer'], 'u256_from_felts']; -export const U128_FROM_FELT: [string[], string] = [['integer'], 'u128_from_felt252']; -export const U128_TO_FELT: [string[], string] = [['integer'], 'u128_to_felt252']; + +/** cairo1 uX <-> felt conversions */ + +// u8 <-> felt +export const U8_FROM_FELT: [string[], string] = [['integer'], 'u8_from_felt252']; +export const U8_TO_FELT: [string[], string] = [['integer'], 'u8_to_felt252']; + +// u16 <-> felt +export const U16_FROM_FELT: [string[], string] = [['integer'], 'u16_from_felt252']; +export const U16_TO_FELT: [string[], string] = [['integer'], 'u16_to_felt252']; + +// u24 <-> felt +export const U24_FROM_FELT: [string[], string] = [['integer'], 'u24_from_felt252']; +export const U24_TO_FELT: [string[], string] = [['integer'], 'u24_to_felt252']; + +// u32 <-> felt export const U32_FROM_FELT: [string[], string] = [['integer'], 'u32_from_felt252']; export const U32_TO_FELT: [string[], string] = [['integer'], 'u32_to_felt252']; +// u40 <-> felt +export const U40_FROM_FELT: [string[], string] = [['integer'], 'u40_from_felt252']; +export const U40_TO_FELT: [string[], string] = [['integer'], 'u40_to_felt252']; + +// u48 <-> felt +export const U48_FROM_FELT: [string[], string] = [['integer'], 'u48_from_felt252']; +export const U48_TO_FELT: [string[], string] = [['integer'], 'u48_to_felt252']; + +// u56 <-> felt +export const U56_FROM_FELT: [string[], string] = [['integer'], 'u56_from_felt252']; +export const U56_TO_FELT: [string[], string] = [['integer'], 'u56_to_felt252']; + +// u64 <-> felt +export const U64_FROM_FELT: [string[], string] = [['integer'], 'u64_from_felt252']; +export const U64_TO_FELT: [string[], string] = [['integer'], 'u64_to_felt252']; + +// u72 <-> felt +export const U72_FROM_FELT: [string[], string] = [['integer'], 'u72_from_felt252']; +export const U72_TO_FELT: [string[], string] = [['integer'], 'u72_to_felt252']; + +// u80 <-> felt +export const U80_FROM_FELT: [string[], string] = [['integer'], 'u80_from_felt252']; +export const U80_TO_FELT: [string[], string] = [['integer'], 'u80_to_felt252']; + +// u88 <-> felt +export const U88_FROM_FELT: [string[], string] = [['integer'], 'u88_from_felt252']; +export const U88_TO_FELT: [string[], string] = [['integer'], 'u88_to_felt252']; + +// u96 <-> felt +export const U96_FROM_FELT: [string[], string] = [['integer'], 'u96_from_felt252']; +export const U96_TO_FELT: [string[], string] = [['integer'], 'u96_to_felt252']; + +// u104 <-> felt +export const U104_FROM_FELT: [string[], string] = [['integer'], 'u104_from_felt252']; +export const U104_TO_FELT: [string[], string] = [['integer'], 'u104_to_felt252']; + +// u112 <-> felt +export const U112_FROM_FELT: [string[], string] = [['integer'], 'u112_from_felt252']; +export const U112_TO_FELT: [string[], string] = [['integer'], 'u112_to_felt252']; + +// u120 <-> felt +export const U120_FROM_FELT: [string[], string] = [['integer'], 'u120_from_felt252']; +export const U120_TO_FELT: [string[], string] = [['integer'], 'u120_to_felt252']; + +// u128 <-> felt +export const U128_FROM_FELT: [string[], string] = [['integer'], 'u128_from_felt252']; +export const U128_TO_FELT: [string[], string] = [['integer'], 'u128_to_felt252']; + +// u136 <-> felt +export const U136_FROM_FELT: [string[], string] = [['integer'], 'u136_from_felt252']; +export const U136_TO_FELT: [string[], string] = [['integer'], 'u136_to_felt252']; + +// u144 <-> felt +export const U144_FROM_FELT: [string[], string] = [['integer'], 'u144_from_felt252']; +export const U144_TO_FELT: [string[], string] = [['integer'], 'u144_to_felt252']; + +// u152 <-> felt +export const U152_FROM_FELT: [string[], string] = [['integer'], 'u152_from_felt252']; +export const U152_TO_FELT: [string[], string] = [['integer'], 'u152_to_felt252']; + +// u160 <-> felt +export const U160_FROM_FELT: [string[], string] = [['integer'], 'u160_from_felt252']; +export const U160_TO_FELT: [string[], string] = [['integer'], 'u160_to_felt252']; + +// u168 <-> felt +export const U168_FROM_FELT: [string[], string] = [['integer'], 'u168_from_felt252']; +export const U168_TO_FELT: [string[], string] = [['integer'], 'u168_to_felt252']; + +// u176 <-> felt +export const U176_FROM_FELT: [string[], string] = [['integer'], 'u176_from_felt252']; +export const U176_TO_FELT: [string[], string] = [['integer'], 'u176_to_felt252']; + +// u184 <-> felt +export const U184_FROM_FELT: [string[], string] = [['integer'], 'u184_from_felt252']; +export const U184_TO_FELT: [string[], string] = [['integer'], 'u184_to_felt252']; + +// u192 <-> felt +export const U192_FROM_FELT: [string[], string] = [['integer'], 'u192_from_felt252']; +export const U192_TO_FELT: [string[], string] = [['integer'], 'u192_to_felt252']; + +// u200 <-> felt +export const U200_FROM_FELT: [string[], string] = [['integer'], 'u200_from_felt252']; +export const U200_TO_FELT: [string[], string] = [['integer'], 'u200_to_felt252']; + +// u208 <-> felt +export const U208_FROM_FELT: [string[], string] = [['integer'], 'u208_from_felt252']; +export const U208_TO_FELT: [string[], string] = [['integer'], 'u208_to_felt252']; + +// u216 <-> felt +export const U216_FROM_FELT: [string[], string] = [['integer'], 'u216_from_felt252']; +export const U216_TO_FELT: [string[], string] = [['integer'], 'u216_to_felt252']; + +// u224 <-> felt +export const U224_FROM_FELT: [string[], string] = [['integer'], 'u224_from_felt252']; +export const U224_TO_FELT: [string[], string] = [['integer'], 'u224_to_felt252']; + +// u232 <-> felt +export const U232_FROM_FELT: [string[], string] = [['integer'], 'u232_from_felt252']; +export const U232_TO_FELT: [string[], string] = [['integer'], 'u232_to_felt252']; + +// u240 <-> felt +export const U240_FROM_FELT: [string[], string] = [['integer'], 'u240_from_felt252']; +export const U240_TO_FELT: [string[], string] = [['integer'], 'u240_to_felt252']; + +// u248 <-> felt +export const U248_FROM_FELT: [string[], string] = [['integer'], 'u248_from_felt252']; +export const U248_TO_FELT: [string[], string] = [['integer'], 'u248_to_felt252']; + +/** ------------------------------ */ + export const GET_CALLER_ADDRESS: [string[], string] = [['starknet'], 'get_caller_address']; export const CONTRACT_ADDRESS: [string[], string] = [['starknet'], 'ContractAddress']; export const INTO: [string[], string] = [['traits'], 'Into']; diff --git a/src/utils/utils.ts b/src/utils/utils.ts index c61dd7dfc..e6c7dba25 100644 --- a/src/utils/utils.ts +++ b/src/utils/utils.ts @@ -81,22 +81,79 @@ export function divmod(x: bigint, y: bigint): [bigint, bigint] { return [div, rem]; } -export function primitiveTypeToCairo(typeString: string): 'Uint256' | 'felt' | 'ContractAddress' { - switch (typeString) { - case 'address': - case 'address payable': - return 'ContractAddress'; - case 'uint': - case 'uint256': - case 'int': - case 'int256': - return 'Uint256'; - case 'fixed': - case 'ufixed': - throw new NotSupportedYetError('Fixed types not implemented'); - default: - return 'felt'; +const cairoPrimitiveIntTypes = [ + 'u8', + 'u16', + 'u24', + 'u32', + 'u40', + 'u48', + 'u56', + 'u64', + 'u72', + 'u80', + 'u88', + 'u96', + 'u104', + 'u112', + 'u120', + 'u128', + 'u136', + 'u144', + 'u152', + 'u160', + 'u168', + 'u176', + 'u184', + 'u192', + 'u200', + 'u208', + 'u216', + 'u224', + 'u232', + 'u240', + 'u248', + 'u256', +] as const; + +type CairoPrimitiveIntType = typeof cairoPrimitiveIntTypes[number]; +export const isCairoPrimitiveIntType = (x: string): x is CairoPrimitiveIntType => { + return cairoPrimitiveIntTypes.includes(x as CairoPrimitiveIntType); +}; + +export function primitiveTypeToCairo( + typeString: string, +): CairoPrimitiveIntType | 'felt' | 'ContractAddress' { + if (typeString === 'address' || typeString === 'address payable') return 'ContractAddress'; + + if (typeString === 'uint' || typeString === 'int') return 'u256'; + + if (typeString === 'fixed' || typeString === 'ufixed') { + throw new NotSupportedYetError('Fixed types not implemented'); + } + + // regex match if typeString is uintN or intN + + const uintMatch = typeString.match(/^uint([0-9]+)$/); + const intMatch = typeString.match(/^int([0-9]+)$/); + + if (uintMatch) { + const bits = BigInt(uintMatch[1]); + if (bits > 256) { + throw new NotSupportedYetError('uint types larger than 256 bits not supported'); + } + return `u${bits}` as CairoPrimitiveIntType; } + + if (intMatch) { + const bits = BigInt(intMatch[1]); + if (bits > 256) { + throw new NotSupportedYetError('int types larger than 256 bits not supported'); + } + return `u${bits}` as CairoPrimitiveIntType; + } + + return 'felt'; } export function union(setA: Set, setB: Set) { diff --git a/warplib/memory.cairo b/warplib/memory.cairo index 96db05b0c..eb8f0daed 100644 --- a/warplib/memory.cairo +++ b/warplib/memory.cairo @@ -40,7 +40,162 @@ func wm_read_felt{warp_memory: DictAccess*}(loc: felt) -> (val: felt) { return (res,); } -func wm_read_256{warp_memory: DictAccess*}(loc: felt) -> (val: Uint256) { +func wm_read_8{warp_memory: DictAccess*}(loc: felt) -> (val: u8) { + let (res) = dict_read{dict_ptr=warp_memory}(loc); + return (u8_from_felt(res),); +} + +func wm_read_16{warp_memory: DictAccess*}(loc: felt) -> (val: u16) { + let (res) = dict_read{dict_ptr=warp_memory}(loc); + return (u16_from_felt(res),); +} + +func wm_read_24{warp_memory: DictAccess*}(loc: felt) -> (val: u24) { + let (res) = dict_read{dict_ptr=warp_memory}(loc); + return (u24_from_felt(res),); +} + +func wm_read_32{warp_memory: DictAccess*}(loc: felt) -> (val: u32) { + let (res) = dict_read{dict_ptr=warp_memory}(loc); + return (u32_from_felt(res),); +} + +func wm_read_40{warp_memory: DictAccess*}(loc: felt) -> (val: u40) { + let (res) = dict_read{dict_ptr=warp_memory}(loc); + return (u40_from_felt(res),); +} + +func wm_read_48{warp_memory: DictAccess*}(loc: felt) -> (val: u48) { + let (res) = dict_read{dict_ptr=warp_memory}(loc); + return (u48_from_felt(res),); +} + +func wm_read_56{warp_memory: DictAccess*}(loc: felt) -> (val: u56) { + let (res) = dict_read{dict_ptr=warp_memory}(loc); + return (u56_from_felt(res),); +} + +func wm_read_64{warp_memory: DictAccess*}(loc: felt) -> (val: u64) { + let (res) = dict_read{dict_ptr=warp_memory}(loc); + return (u64_from_felt(res),); +} + +func wm_read_72{warp_memory: DictAccess*}(loc: felt) -> (val: u72) { + let (res) = dict_read{dict_ptr=warp_memory}(loc); + return (u72_from_felt(res),); +} + +func wm_read_80{warp_memory: DictAccess*}(loc: felt) -> (val: u80) { + let (res) = dict_read{dict_ptr=warp_memory}(loc); + return (u80_from_felt(res),); +} + +func wm_read_88{warp_memory: DictAccess*}(loc: felt) -> (val: u88) { + let (res) = dict_read{dict_ptr=warp_memory}(loc); + return (u88_from_felt(res),); +} + +func wm_read_96{warp_memory: DictAccess*}(loc: felt) -> (val: u96) { + let (res) = dict_read{dict_ptr=warp_memory}(loc); + return (u96_from_felt(res),); +} + +func wm_read_104{warp_memory: DictAccess*}(loc: felt) -> (val: u104) { + let (res) = dict_read{dict_ptr=warp_memory}(loc); + return (u104_from_felt(res),); +} + +func wm_read_112{warp_memory: DictAccess*}(loc: felt) -> (val: u112) { + let (res) = dict_read{dict_ptr=warp_memory}(loc); + return (u112_from_felt(res),); +} + +func wm_read_120{warp_memory: DictAccess*}(loc: felt) -> (val: u120) { + let (res) = dict_read{dict_ptr=warp_memory}(loc); + return (u120_from_felt(res),); +} + +func wm_read_128{warp_memory: DictAccess*}(loc: felt) -> (val: u128) { + let (res) = dict_read{dict_ptr=warp_memory}(loc); + return (u128_from_felt(res),); +} + +func wm_read_136{warp_memory: DictAccess*}(loc: felt) -> (val: u136) { + let (res) = dict_read{dict_ptr=warp_memory}(loc); + return (u136_from_felt(res),); +} + +func wm_read_144{warp_memory: DictAccess*}(loc: felt) -> (val: u144) { + let (res) = dict_read{dict_ptr=warp_memory}(loc); + return (u144_from_felt(res),); +} + +func wm_read_152{warp_memory: DictAccess*}(loc: felt) -> (val: u152) { + let (res) = dict_read{dict_ptr=warp_memory}(loc); + return (u152_from_felt(res),); +} + +func wm_read_160{warp_memory: DictAccess*}(loc: felt) -> (val: u160) { + let (res) = dict_read{dict_ptr=warp_memory}(loc); + return (u160_from_felt(res),); +} + +func wm_read_168{warp_memory: DictAccess*}(loc: felt) -> (val: u168) { + let (res) = dict_read{dict_ptr=warp_memory}(loc); + return (u168_from_felt(res),); +} + +func wm_read_176{warp_memory: DictAccess*}(loc: felt) -> (val: u176) { + let (res) = dict_read{dict_ptr=warp_memory}(loc); + return (u176_from_felt(res),); +} + +func wm_read_184{warp_memory: DictAccess*}(loc: felt) -> (val: u184) { + let (res) = dict_read{dict_ptr=warp_memory}(loc); + return (u184_from_felt(res),); +} + +func wm_read_192{warp_memory: DictAccess*}(loc: felt) -> (val: u192) { + let (res) = dict_read{dict_ptr=warp_memory}(loc); + return (u192_from_felt(res),); +} + +func wm_read_200{warp_memory: DictAccess*}(loc: felt) -> (val: u200) { + let (res) = dict_read{dict_ptr=warp_memory}(loc); + return (u200_from_felt(res),); +} + +func wm_read_208{warp_memory: DictAccess*}(loc: felt) -> (val: u208) { + let (res) = dict_read{dict_ptr=warp_memory}(loc); + return (u208_from_felt(res),); +} + +func wm_read_216{warp_memory: DictAccess*}(loc: felt) -> (val: u216) { + let (res) = dict_read{dict_ptr=warp_memory}(loc); + return (u216_from_felt(res),); +} + +func wm_read_224{warp_memory: DictAccess*}(loc: felt) -> (val: u224) { + let (res) = dict_read{dict_ptr=warp_memory}(loc); + return (u224_from_felt(res),); +} + +func wm_read_232{warp_memory: DictAccess*}(loc: felt) -> (val: u232) { + let (res) = dict_read{dict_ptr=warp_memory}(loc); + return (u232_from_felt(res),); +} + +func wm_read_240{warp_memory: DictAccess*}(loc: felt) -> (val: u240) { + let (res) = dict_read{dict_ptr=warp_memory}(loc); + return (u240_from_felt(res),); +} + +func wm_read_248{warp_memory: DictAccess*}(loc: felt) -> (val: u248) { + let (res) = dict_read{dict_ptr=warp_memory}(loc); + return (u248_from_felt(res),); +} + +func wm_read_256{warp_memory: DictAccess*}(loc: felt) -> (val: u256) { let (low) = dict_read{dict_ptr=warp_memory}(loc); let (high) = dict_read{dict_ptr=warp_memory}(loc + 1); return (Uint256(low, high),); @@ -51,6 +206,163 @@ func wm_write_felt{warp_memory: DictAccess*}(loc: felt, value: felt) -> (res: fe return (value,); } + +func wm_write_8{warp_memory: DictAccess*}(loc: felt, value: u8) -> (res: u8) { + let (fvalue) = u8_to_felt(value); + dict_write{dict_ptr=warp_memory}(loc, fvalue); + return (value,); +} +func wm_write_16{warp_memory: DictAccess*}(loc: felt, value: u16) -> (res: u16) { + let (fvalue) = u16_to_felt(value); + dict_write{dict_ptr=warp_memory}(loc, fvalue); + return (value,); +} +func wm_write_24{warp_memory: DictAccess*}(loc: felt, value: u24) -> (res: u24) { + let (fvalue) = u24_to_felt(value); + dict_write{dict_ptr=warp_memory}(loc, fvalue); + return (value,); +} +func wm_write_32{warp_memory: DictAccess*}(loc: felt, value: u32) -> (res: u32) { + let (fvalue) = u32_to_felt(value); + dict_write{dict_ptr=warp_memory}(loc, fvalue); + return (value,); +} +func wm_write_40{warp_memory: DictAccess*}(loc: felt, value: u40) -> (res: u40) { + let (fvalue) = u40_to_felt(value); + dict_write{dict_ptr=warp_memory}(loc, fvalue); + return (value,); +} +func wm_write_48{warp_memory: DictAccess*}(loc: felt, value: u48) -> (res: u48) { + let (fvalue) = u48_to_felt(value); + dict_write{dict_ptr=warp_memory}(loc, fvalue); + return (value,); +} +func wm_write_56{warp_memory: DictAccess*}(loc: felt, value: u56) -> (res: u56) { + let (fvalue) = u56_to_felt(value); + dict_write{dict_ptr=warp_memory}(loc, fvalue); + return (value,); +} +func wm_write_64{warp_memory: DictAccess*}(loc: felt, value: u64) -> (res: u64) { + let (fvalue) = u64_to_felt(value); + dict_write{dict_ptr=warp_memory}(loc, fvalue); + return (value,); +} +func wm_write_72{warp_memory: DictAccess*}(loc: felt, value: u72) -> (res: u72) { + let (fvalue) = u72_to_felt(value); + dict_write{dict_ptr=warp_memory}(loc, fvalue); + return (value,); +} +func wm_write_80{warp_memory: DictAccess*}(loc: felt, value: u80) -> (res: u80) { + let (fvalue) = u80_to_felt(value); + dict_write{dict_ptr=warp_memory}(loc, fvalue); + return (value,); +} +func wm_write_88{warp_memory: DictAccess*}(loc: felt, value: u88) -> (res: u88) { + let (fvalue) = u88_to_felt(value); + dict_write{dict_ptr=warp_memory}(loc, fvalue); + return (value,); +} +func wm_write_96{warp_memory: DictAccess*}(loc: felt, value: u96) -> (res: u96) { + let (fvalue) = u96_to_felt(value); + dict_write{dict_ptr=warp_memory}(loc, fvalue); + return (value,); +} +func wm_write_104{warp_memory: DictAccess*}(loc: felt, value: u104) -> (res: u104) { + let (fvalue) = u104_to_felt(value); + dict_write{dict_ptr=warp_memory}(loc, fvalue); + return (value,); +} +func wm_write_112{warp_memory: DictAccess*}(loc: felt, value: u112) -> (res: u112) { + let (fvalue) = u112_to_felt(value); + dict_write{dict_ptr=warp_memory}(loc, fvalue); + return (value,); +} +func wm_write_120{warp_memory: DictAccess*}(loc: felt, value: u120) -> (res: u120) { + let (fvalue) = u120_to_felt(value); + dict_write{dict_ptr=warp_memory}(loc, fvalue); + return (value,); +} +func wm_write_128{warp_memory: DictAccess*}(loc: felt, value: u128) -> (res: u128) { + let (fvalue) = u128_to_felt(value); + dict_write{dict_ptr=warp_memory}(loc, fvalue); + return (value,); +} +func wm_write_136{warp_memory: DictAccess*}(loc: felt, value: u136) -> (res: u136) { + let (fvalue) = u136_to_felt(value); + dict_write{dict_ptr=warp_memory}(loc, fvalue); + return (value,); +} +func wm_write_144{warp_memory: DictAccess*}(loc: felt, value: u144) -> (res: u144) { + let (fvalue) = u144_to_felt(value); + dict_write{dict_ptr=warp_memory}(loc, fvalue); + return (value,); +} +func wm_write_152{warp_memory: DictAccess*}(loc: felt, value: u152) -> (res: u152) { + let (fvalue) = u152_to_felt(value); + dict_write{dict_ptr=warp_memory}(loc, fvalue); + return (value,); +} +func wm_write_160{warp_memory: DictAccess*}(loc: felt, value: u160) -> (res: u160) { + let (fvalue) = u160_to_felt(value); + dict_write{dict_ptr=warp_memory}(loc, fvalue); + return (value,); +} +func wm_write_168{warp_memory: DictAccess*}(loc: felt, value: u168) -> (res: u168) { + let (fvalue) = u168_to_felt(value); + dict_write{dict_ptr=warp_memory}(loc, fvalue); + return (value,); +} +func wm_write_176{warp_memory: DictAccess*}(loc: felt, value: u176) -> (res: u176) { + let (fvalue) = u176_to_felt(value); + dict_write{dict_ptr=warp_memory}(loc, fvalue); + return (value,); +} +func wm_write_184{warp_memory: DictAccess*}(loc: felt, value: u184) -> (res: u184) { + let (fvalue) = u184_to_felt(value); + dict_write{dict_ptr=warp_memory}(loc, fvalue); + return (value,); +} +func wm_write_192{warp_memory: DictAccess*}(loc: felt, value: u192) -> (res: u192) { + let (fvalue) = u192_to_felt(value); + dict_write{dict_ptr=warp_memory}(loc, fvalue); + return (value,); +} +func wm_write_200{warp_memory: DictAccess*}(loc: felt, value: u200) -> (res: u200) { + let (fvalue) = u200_to_felt(value); + dict_write{dict_ptr=warp_memory}(loc, fvalue); + return (value,); +} +func wm_write_208{warp_memory: DictAccess*}(loc: felt, value: u208) -> (res: u208) { + let (fvalue) = u208_to_felt(value); + dict_write{dict_ptr=warp_memory}(loc, fvalue); + return (value,); +} +func wm_write_216{warp_memory: DictAccess*}(loc: felt, value: u216) -> (res: u216) { + let (fvalue) = u216_to_felt(value); + dict_write{dict_ptr=warp_memory}(loc, fvalue); + return (value,); +} +func wm_write_224{warp_memory: DictAccess*}(loc: felt, value: u224) -> (res: u224) { + let (fvalue) = u224_to_felt(value); + dict_write{dict_ptr=warp_memory}(loc, fvalue); + return (value,); +} +func wm_write_232{warp_memory: DictAccess*}(loc: felt, value: u232) -> (res: u232) { + let (fvalue) = u232_to_felt(value); + dict_write{dict_ptr=warp_memory}(loc, fvalue); + return (value,); +} +func wm_write_240{warp_memory: DictAccess*}(loc: felt, value: u240) -> (res: u240) { + let (fvalue) = u240_to_felt(value); + dict_write{dict_ptr=warp_memory}(loc, fvalue); + return (value,); +} +func wm_write_248{warp_memory: DictAccess*}(loc: felt, value: u248) -> (res: u248) { + let (fvalue) = u248_to_felt(value); + dict_write{dict_ptr=warp_memory}(loc, fvalue); + return (value,); +} + func wm_write_256{warp_memory: DictAccess*}(loc: felt, value: Uint256) -> (res: Uint256) { dict_write{dict_ptr=warp_memory}(loc, value.low); dict_write{dict_ptr=warp_memory}(loc + 1, value.high);